How can I prove $\frac{\gamma}{2}=\int_{0}^{\infty}\frac{e^{-x^{2}}-e^{-x}}{x}\text{d}x$?

\begin{align} I=\int_0^\infty\frac{e^{-x^2}-e^{-x}}{x}\ dx\overset{IBP}{=}\int_0^\infty\ln x\left(2xe^{-x^2}-e^{-x}\right)\ dx \end{align} let $x^2\mapsto x$ for the first integral to get \begin{align} I=-\frac12\int_0^\infty\ln x\ e^{-x} dx=-\frac12(-\gamma) \end{align}


Proof for the last step: Using the fact that $$\int_0^\infty x^{a-1} \ e^{-bx} dx=\frac{\Gamma(a)}{b^{\ a}}\tag{1}$$

differentiate both sides of $(1)$ with respect to $a$ to get

$$\int_0^\infty \ln x\ x^{a-1} \ e^{-bx}\ dx=-\frac{\Gamma(a)(\ln b-\psi(a))}{b^{\ a}}\tag{2}$$ now set $a=1$ in $(2)$ $$\int_0^\infty \ln x\ e^{-bx}\ dx=-\frac{\ln b+\gamma}{b}$$

Finally set $b=1$ we get

$$\int_0^\infty \ln x\ e^{-x}\ dx=-\gamma$$


Starting from

$$\int_a^b \frac{e^{-x^2} - e^{-x}}{x}\, dx \quad (b > a > 0)$$

we have that

\begin{align}\int_a^b \frac{e^{-x^2} - e^{-x}}{x}\, dx &= \int_a^b \frac{e^{-x^2}}{x}\, dx - \int_a^b \frac{e^{-x}}{x}\, dx \\&= \frac{1}{2}\int_{a^2}^{b^2} \frac{e^{-u}}{u}\, du - \int_a^b \frac{e^{-x}}{x}\, dx\end{align}

by the substitution $u = x^2$. If we integrate by parts, we form

$$\int_a^b \frac{e^{-x}}{x}\, dx = e^{-b}\ln b - e^{-a}\ln a + \int_a^b e^{-x}\ln x\, dx$$

and

$$\frac{1}{2}\int_{a^2}^{b^2} \frac{e^{-u}}{u}\, du = e^{-b^2}\ln b - e^{-a^2}\ln a + \frac{1}{2}\int_{a^2}^{b^2} e^{-x}\ln x\, dx.$$

Thus,

\begin{align}\int_a^b \frac{e^{-x^2} - e^{-x}}{x}\, dx & = (e^{-b^2} - e^{-b})\ln b - (e^{-a^2} - e^{-a})\ln a\\& + \frac{1}{2}\int_{a^2}^{b^2} e^{-x}\ln x\, dx - \int_a^b e^{-x}\ln x\, dx.\\ \end{align}

Therefore, because $\big(e^{-x^2} - e^{-x}\big)\ln x$ tends to $0$ as $x\to 0^+$ and as $x\to \infty$, we can take the limit as $a \to 0^+$ and $b\to \infty$. This forms

$$\int_0^\infty \frac{e^{-x^2} - e^{-x}}{x}\, dx = -\frac{1}{2}\int_0^\infty e^{-x}\ln x\, dx$$

$\gamma$ is the Euler-Mascheroni Constant. It is defined by

$$\gamma = -\int_0^{\infty}e^{-x}\ln x ~dx \tag{*}$$

Thus, we have that

$$\int_0^{\infty}\frac{e^{-x^2}-e^{-x}}{x}dx=-\frac{1}{2}\int_0^{\infty}e^{-x}\ln x ~dx=\frac{\gamma}{2}$$


To show that $(*)$ holds, we can derive the above representation of the Euler-Mascheroni Constant. Let's start from

$$\int_0^{\infty}e^{-x}\ln x ~dx$$

and then write

$$e^{-x}=\lim_{n\to\infty}\Big(1-\frac{x}{n}\Big)^n=\lim_{n\to\infty}\Big(1-\frac{x}{n}\Big)^{n-1}$$

which means that

$$\int_0^{\infty}e^{-x}\ln x ~dx=\lim_{n\to\infty}\int_0^{n}\Big(1-\frac{x}{n}\Big)^{n-1}\ln x ~dx$$

Then, we can perform the $u$ substitution $$u=1-\frac{x}{n} ~~\Rightarrow~~ x=n(1-u)$$ $$du = -\frac{1}{n}dx$$ $$dx=-n~du$$

to form

\begin{align} \int_0^{n}\Big(1-\frac{x}{n}\Big)^{n-1}\ln x ~dx&=\int_1^{0}u^{n-1}\ln \big(n(1-u)\big) (-n~du) \\&=n\int_0^1u^{n-1}\ln \big(n(1-u)\big)du \end{align}

Hence,

\begin{align} \int_0^{n}\Big(1-\frac{x}{n}\Big)^{n-1}\ln x ~dx &= n\int_0^1u^{n-1}\ln \big(n(1-u)\big)du \\&= n\ln(n) \int_0^1u^{n-1}du ~+ ~n\int_0^1u^{n-1}\ln \big((1-u)\big)du \\ &= n\ln(n)\Big[\frac{u^n}{n}\Big]_0^1 ~-~ n\int_0^1u^{n-1} \sum_{k=1}^{\infty}\frac{u^k}{k}~du \\ &= n\ln(n)\frac{1}{n}~-~n\int_0^1 \sum_{k=1}^{\infty} \frac{u^{k+n-1}}{k}du \\ &= \ln(n) ~-~ n\sum_{k=1}^{\infty}\frac{1}{k(k+n)} \\ &= \ln(n)~-~\sum_{k=1}^{\infty}\Big(\frac{1}{k}-\frac{1}{n+k}\Big) \\ &= \ln(n)~-~\sum_{k=1}^{n}\frac{1}{k} \end{align}

So, if we let $n\to\infty$ we see that

\begin{align} \int_0^{\infty}e^{-x}\ln x ~dx &= \lim_{n\to\infty}\Big(\ln(n)~-~\sum_{k=1}^{n}\frac{1}{k}\Big) \\&= -\gamma \end{align}