How this integral $ \int_0^z\frac{1-e^x}{x} dx$ is connected to the Gamma function and Euler constant?

I believe that this works for both positive and negative $z$.

By definition and change of variables $$ \Gamma(0,-z)=\int_{-z}^\infty e^{-x}\frac{\mathrm{d}x}{x}=-\int_{-\infty}^z e^x\frac{\mathrm{d}x}{x}\tag{1} $$ where the principal value is taken where needed. Applying $(1)$ to the integral from $w$ to $z$: $$ \int_w^z\frac{1-e^x}{x}\mathrm{d}x=\log|z|-\log|w|+\Gamma(0,-z)-\Gamma(0,-w)\tag{2} $$ According to $(2)$, $$ \int_0^z\frac{1-e^x}{x}\mathrm{d}x=\log|z|+\Gamma(0,-z)-C\tag{3} $$ where $$ C=\lim_{w\to0}(\log|w|+\Gamma(0,|w|))\tag{4} $$ We can use $\Gamma(0,|w|)$ in $(4)$ since either $\Gamma(0,w)$ or $\Gamma(0,-w)$ is defined by a principal value integral, so we have $$ \lim_{w\to0}(\Gamma(0,-w)-\Gamma(0,w))=0 $$ Therefore, $$ \begin{align} C &=\lim_{w\to0}(\log|w|+\Gamma(0,|w|))\\ &=\lim_{w\to0}\left(\log|w|+\int_{|w|}^\infty e^{-x}\frac{\mathrm{d}x}{x}\right)\\ &=\lim_{w\to0}\left(\log|w|-\log|w|\;e^{-|w|}+\int_{|w|}^\infty\log(x)e^{-x}\mathrm{d}x\right)\\ &=\int_0^\infty\log(x)e^{-x}\mathrm{d}x\\ &=-\gamma\tag{6} \end{align} $$ where $\gamma$ is the Euler-Mascheroni Constant. Combining $(3)$ and $(6)$, we get $$ \int_0^z\frac{1-e^x}{x}\mathrm{d}x=\log|z|+\Gamma(0,-z)+\gamma\tag{7} $$ If there is interest, I can append a proof that $\int_0^\infty\log(x)e^{-x}\mathrm{d}x=-\gamma$.


First of all, you misquote WolframAlpha. It give $\int_0^z \left( 1- \mathrm{e}^x \right) \frac{\mathrm{d} x}{x} = \gamma + \log(-z) + \Gamma(0, -z)$. Notice $\Gamma(0, -z)$ instead of $\Gamma(0, z)$.

This is done using the fundamental theorem of calculus:

Let $$ F(x) = \int \left( 1- \mathrm{e}^x \right) \frac{\mathrm{d} x}{x} = \log(x) - \operatorname{Ei}(x) $$ Then, $\int_0^z \left( 1- \mathrm{e}^x \right) \frac{\mathrm{d} x}{x} = F(z) - \lim_{x\to 0^+} F(x) = F(z) + \gamma$. The latter limit follows from the Taylor series for the exponential integral.

The connection between $\Gamma(0,-z) = \int_{-z}^\infty \mathrm{e}^{-x} \frac{\mathrm{d} x}{x}$ and $\operatorname{Ei}(z) = \int_{-\infty}^z \mathrm{e}^{x} \frac{\mathrm{d} x}{x}$ is well known.