## The Gamma and Lambert-W Functions

2017 June 21

Find the values of the following integrals, where $$W(x)$$ denotes the inverse function of $$y=xe^x$$ from $$0$$ to $$\infty$$:
$\int_0^1 W(x)dx$
$\int_0^{e} W(x)^2dx$
$\int_0^\infty W(e^{-x})dx$
$\int_0^\infty \frac{W(x)}{x\sqrt{x}}dx$
$\int_0^\infty W\bigg(\frac{1}{x^2}\bigg)dx$

I will be devoting this post to two very interesting and related functions: the Gamma Function $$\Gamma(z)$$ and the Lambert-W Function $$W(z)$$.

I will start off with the basics of the Lambert-W function. This function is taken to be the inverse function of $$y=xe^x$$. Here are two graphs, one of $$y=xe^x$$ (in red), and one of the Lambert-W function (in blue).

As you can see, $$y=xe^x$$ is not injective and should not have an inverse, but because only a small branch of it is non-injective, it can be useful to treat is as if it had an inverse anyways. This is what the Lambert-W function is for. That function cannot be inverted anyways using elementary functions, so the Lambert-W function is what we treat as its inverse. However, since it is not actually injective, the Lambert-W function has two branches: the lower branch $$W_{-1}$$ and the upper branch $$W_0$$. The point at which the function changes between these two branches is at the point corresponding to the minimum of $$y=xe^x$$, the point $$(-\frac{1}{e},-1)$$ on the Lambert-W function. Because it is defined as the inverse of $$y=xe^x$$, it has the properties
$W(xe^x)=x$
$W(x)e^{W(x)}=x$

The value $$W(1)$$, or the unique solution to the equation
$xe^x=1$
is called the omega constant $$\Omega$$ and is about $$0.5671$$. We will be using it in some of our later integral problems.

This function can be used to “solve” many new types of equations. For example, consider the equation
$e^x=3x$
This equation can be solved using the Lambert-W function in the following way:
$e^x=3x$
$1=3xe^{-x}$
$-\frac{1}{3}=-xe^{-x}$
$W\bigg(-\frac{1}{3}\bigg)=W(-xe^{-x})$
$W\bigg(-\frac{1}{3}\bigg)=-x$
$x=-W\bigg(-\frac{1}{3}\bigg)$
There are two possible values satisfying this, since both branches of the Lambert-W function exist at $$x=-\frac{1}{3}$$.

Here’s another example:
$6\cdot 2^{2x}=x$
This can be solved in the following way:
$6\cdot 2^{2x}=x$
$6\cdot e^{\ln(2^{2x})}=x$
$6\cdot e^{2x\ln(2)}=x$
$6=e^{-2x\ln(2)}x$
$-12\ln(2)=-2x\ln(2)e^{-2x\ln(2)}$
$W(-12\ln(2))=W(-2x\ln(2)e^{-2x\ln(2)})$
$W(-12\ln(2))=-2x\ln(2)$
$x=-\frac{W(-12\ln(2))}{2\ln(2)}$

The derivative of the Lambert-W function is given by
$W'(x)=\frac{1}{x}\frac{W(x)}{W(x)+1}$
I will not go into the details of the derivation of this formula, because it can be attained easily using the formula for the derivative of the inverse of a function, in this case the function $$f(x)=xe^x$$. Furthermore, its antiderivative is
$\int W(x) dx=\frac{x(W(x)^2-W(x)+1)}{W(x)}+C$
which can also be obtained with the use of a formula.

We will now derive two identities of the Lambert-W function that we will now prove that may become helpful later. The first is the sum identity
$W(a)+W(b)=W\bigg(\frac{ab}{W(a)}+\frac{ab}{W(b)}\bigg)$
and the second is the product identity
$aW(b)=W\bigg(\frac{ab^a}{W(b)^{a-1}}\bigg)$
Here is the derivation of the first identity:
$W(a)+W(b)$
$=W\bigg((W(a)+W(b))e^{W(a)+W(b)}\bigg)$
$=W\bigg(W(a)e^{W(a)}e^{W(b)}+W(b)e^{W(b)}e^{W(a)}\bigg)$
$=W\bigg(ae^{W(b)}+be^{W(a)}\bigg)$
$=W\bigg(\frac{ab}{W(b)}+\frac{ab}{W(a)}\bigg)$
$=W\bigg(\frac{ab}{W(a)}+\frac{ab}{W(b)}\bigg)$
And here is the derivation of the second:
$aW(b)$
$=W\bigg(aW(b)e^{aW(b)}\bigg)$
$=W\bigg(a\cdot W(b)e^{W(b)}\cdot e^{(a-1)W(b)}\bigg)$
$=W\bigg(abe^{(a-1)W(b)}\bigg)$
$=W\bigg(ab\big(e^{W(b)}\big)^{a-1}\bigg)$
$=W\bigg(ab\bigg(\frac{b}{W(b)}\bigg)^{a-1}\bigg)$
$=W\bigg(\frac{ab^a}{W(b)^{a-1}}\bigg)$

Before we move into the “good stuff”, it would be best to introduce the Gamma Function, as it can save a lot of time when evaluating some of the integrals that we will later evaluate.

Basically, the Gamma Function is an extension of the factorial function to non-natural numbers. It has the property
$\Gamma(n)=(n-1)!, \forall n\in\mathbb N$
So it is essentially the factorial function, translated one unit. It is defined as
$\Gamma(z)=\int_0^\infty x^{z-1}e^{-x}dx$
Its relation to the factorial function can be proven using induction. First we must show that $$\Gamma(1)=1$$:
$\Gamma(1)=\int_0^\infty x^{1-1}e^{-x}dx$
$\Gamma(1)=\int_0^\infty e^{-x}dx$
$\Gamma(1)=1$

Wonderful. Now we must begin the inductive part of the proof.
$\Gamma(z)=\int_0^\infty x^{z-1}e^{-x}dx$
If we use integration by parts, we can observe that
$\int x^{z-1}e^{-x}dx=-x^{z-1}e^{-x}+(z-1)\int x^{z-2}e^{-x}dx$
Which means that
$\Gamma(z)=(z-1)\int_0^\infty x^{z-2}e^{-x}dx$
$\Gamma(z)=(z-1)\Gamma(z-1)$
Which completes our inductive proof.

One thing that is helpful when working with the Gamma Function is knowledge of the Gaussian Integral; that is, the integral
$\int_{-\infty}^\infty e^{-x^2}dx=\sqrt{\pi}$
This integral comes up often when evaluating particular values of the Gamma Function. For example, look what happens when we try to evaluate $$\Gamma\bigg(\frac{1}{2}\bigg)$$:
$\Gamma\bigg(\frac{1}{2}\bigg)=\int_0^\infty x^{-\frac{1}{2}}e^{-x}dx$
If we make the substitution $$x \to y^2$$, this integral turns into
$\Gamma\bigg(\frac{1}{2}\bigg)=\int_0^\infty 2y(y^2)^{-\frac{1}{2}}e^{-y^2}dx$
$\Gamma\bigg(\frac{1}{2}\bigg)=2\int_0^\infty e^{-y^2}dx$
$\Gamma\bigg(\frac{1}{2}\bigg)=\int_{-\infty}^\infty e^{-y^2}dx$
Which is just the same as the Gaussian Integral, and so
$\Gamma\bigg(\frac{1}{2}\bigg)=\sqrt{\pi}$

I’ll spare you the derivations of the first couple values of this type of the Gamma Function, as they each involve a lot of integration by parts and are very repetitive. Here they are:
$\Gamma\bigg(\frac{1}{2}\bigg)=\sqrt{\pi}$
$\Gamma\bigg(\frac{3}{2}\bigg)=\frac{1}{2}\sqrt{\pi}$
$\Gamma\bigg(\frac{5}{2}\bigg)=\frac{3}{4}\sqrt{\pi}$
$\Gamma\bigg(\frac{7}{2}\bigg)=\frac{15}{8}\sqrt{\pi}$

Are you noticing a pattern?
$\Gamma\bigg(\frac{1}{2}\bigg)=\frac{1}{2^0}\sqrt{\pi}$
$\Gamma\bigg(\frac{3}{2}\bigg)=\frac{1}{2^1}\sqrt{\pi}$
$\Gamma\bigg(\frac{5}{2}\bigg)=\frac{1\cdot3}{2^2}\sqrt{\pi}$
$\Gamma\bigg(\frac{7}{2}\bigg)=\frac{1\cdot3\cdot5}{2^3}\sqrt{\pi}$

Do you see it? This can lead us to conjecture that
$\Gamma\bigg(\frac{2n+1}{2}\bigg)=\frac{(2n-1)!!}{2^n}, \forall n \in \mathbb N$

This can be proven easily using induction. This proof is also inductive and also uses integration by parts. The first step is recalling that $$\Gamma(\frac{1}{2})$$ is equal to $$\sqrt{\pi}$$. Then we can begin our inductive step. By definition,
$\Gamma\bigg(\frac{2n+1}{2}\bigg)=\int_0^\infty x^{\frac{2n-1}{2}}e^{-x}dx$
And if we use integration by parts, we notice that
$\int x^{\frac{2n-1}{2}}e^{-x}dx=-x^{\frac{2n-1}{2}}e^{-x} + \frac{2n-1}{2}\int x^{\frac{2n-3}{2}}e^{-x}dx$
Meaning that
$\Gamma\bigg(\frac{2n+1}{2}\bigg)=\frac{2n-1}{2}\int_0^\infty x^{\frac{2n-3}{2}}e^{-x}dx$
$\Gamma\bigg(\frac{2n+1}{2}\bigg)=\frac{2n-1}{2}\Gamma\bigg(\frac{2n-1}{2}\bigg)$
Which completes the induction step of our proof.

It can be proven similarly that
$\Gamma\bigg(\frac{kn+1}{k}\bigg)=\frac{(kn-k+1)!_k}{k^n}, \forall n,k \in \mathbb N$
where $$!_k$$ represents the kth factorial (that is, $$!_2$$ is $$!!$$, $$!_3$$ is $$!!!$$, and so on). This fact will be useful to us later on.

One final notable formula regarding the Gamma Function is its reflection formula, derived by Euler:
$\Gamma(z)\Gamma(1-z)=\frac{\pi}{\sin \pi z}$

However, we will not use it much, and so we will not derive it here. Perhaps in a later post that is focused solely on the Gamma Function.

Before we start the integrals, let me remind you of the definite integral property
$\int_a^b f(x)dx=\int_{g^{-1}(a)}^{g^{-1}(b)} g'(x)(f \circ g)(x) dx$
Because we will be using it a lot in the upcoming problems.

First off, we will tackle the least intimidating of the integrals:
$\int_0^1 W(x)dx$
It seems impossible at first to integrate over a function that cannot even be expressed using other elementary functions. However, we can use the trick that I just mentioned, along with the fact that $$W(x)$$ is defined as the inverse of $$xe^x$$. Let’s use the trick with $$g(x)=xe^x$$. Then we get
$\int_{W(0)}^{W(1)} W(xe^x)\cdot\frac{d}{dx}(xe^x)dx$
$$W(0)$$ is $$0$$ and $$W(1)$$ is the omega constant, so we can now simplify the integral and the rest of the bounds:
$\int_{0}^{\Omega} x(xe^x+e^x)dx$
$\int_{0}^{\Omega} x^2e^xdx+\int_0^{\Omega} xe^xdx$
Using integration by parts, we can reduce this to
$\Omega^2 e^{\Omega}-2\int_{0}^{\Omega} xe^xdx+\int_0^{\Omega} xe^xdx$
$\Omega^2 e^{\Omega}-\int_0^{\Omega} xe^xdx$
$\Omega^2 e^{\Omega}-(\Omega e^\Omega-e^\Omega+e^0)$
$\Omega^2 e^{\Omega}-\Omega e^\Omega+e^\Omega-e^0$
Remember, since $$\Omega=W(1)$$, we can simplify $$\Omega e^\Omega$$ to $$1$$:
$\Omega-1+e^\Omega-1$
$\Omega+e^\Omega-2$
Furthermore, since $$\Omega e^\Omega=1$$, then $$e^\Omega=\frac{1}{\Omega}$$, so our simplified answer is
$\Omega+\frac{1}{\Omega}-2$
and so
$\int_0^1 W(x)dx=\Omega+\frac{1}{\Omega}-2$

On to the next one:
$\int_0^{e} W(x)^2dx$
Let us again use our “trick” with $$g(x)=xe^x$$:
$\int_0^{1} x^2(xe^x+e^x)dx$
$\int_0^{1} x^3e^xdx+\int_0^1 xe^xdx$
Now the integral can be solved readily by using integration by parts over and over again. I’ll spare you the details:
$\int_0^{e} W(x)^2dx=4-e$

Now for the integral
$\int_0^\infty W(e^{-x})dx$
This time we can use $$g(x)=-\ln(xe^x)=-\ln(x)-x$$ to get the much easier integral
$\int_{\Omega}^0 x\cdot -(\frac{1}{x}+1)dx$
$\int_{0}^\Omega (x+1)dx$
$\frac{\Omega^2}{2}+\Omega$
and so
$\int_0^\infty W(e^{-x})dx=\frac{\Omega^2}{2}+\Omega$

Next up is
$\int_0^\infty \frac{W(x)}{x\sqrt{x}}dx$
Let us once again use $$g(x)=xe^x$$ to get
$\int_0^\infty \frac{x(xe^x+e^x)}{xe^x\sqrt{xe^x}}dx$
$\int_0^\infty \frac{xe^x(x+1)}{xe^x\sqrt{xe^x}}dx$
$\int_0^\infty \frac{x+1}{\sqrt{xe^x}}dx$
$\int_0^\infty (x+1)(x^{-\frac{1}{2}}e^{-\frac{1}{2}x})dx$
$\int_0^\infty x^{\frac{1}{2}}e^{-\frac{1}{2}x}dx+\int_0^\infty x^{-\frac{1}{2}}e^{-\frac{1}{2}x}dx$
Now we can recognize the relevance of the gamma function. If we use $$g(x)=2x$$ then we get
$2\sqrt{2}\int_0^\infty x^{\frac{1}{2}}e^{-x}dx+\sqrt{2}\int_0^\infty x^{-\frac{1}{2}}e^{-\frac{1}{2}x}dx$
$2\sqrt{2}\Gamma\bigg(\frac{3}{2}\bigg)+\sqrt{2}\Gamma\bigg(\frac{1}{2}\bigg)$
and, since we have already obtained these values for the Gamma Function, we have
$2\sqrt{2}\frac{\sqrt{\pi}}{2}+\sqrt{2}\sqrt{\pi}$
$2\sqrt{2\pi}$
and so
$\int_0^\infty \frac{W(x)}{x\sqrt{x}}dx=2\sqrt{2\pi}$

Now for the final integral:
$\int_0^\infty W\bigg(\frac{1}{x^2}\bigg)dx$
First we will use $$g(x)=\sqrt{\frac{1}{x}e^{-x}}$$, which gives us
$\frac{1}{2}\int_0^\infty x\cdot\bigg(x^{-\frac{1}{2}}e^{-\frac{1}{2}x}+x^{-\frac{3}{2}}e^{-\frac{1}{2}x}\bigg)dx$
$\frac{1}{2}\int_0^\infty x^{\frac{1}{2}}e^{-\frac{1}{2}x}dx+\frac{1}{2}\int_0^\infty x^{-\frac{1}{2}}e^{-\frac{1}{2}x}dx$
Now let us use $$g(x)=2x$$:
$\frac{1}{2}2\sqrt{2}\int_0^\infty x^{\frac{1}{2}}e^{-x}dx+\frac{1}{2}\sqrt{2}\int_0^\infty x^{-\frac{1}{2}}e^{-x}dx$
$\sqrt{2}\Gamma\bigg(\frac{3}{2}\bigg)+\frac{1}{\sqrt{2}}\Gamma\bigg(\frac{1}{2}\bigg)$
$\sqrt{2}\frac{\sqrt{\pi}}{2}+\frac{1}{\sqrt{2}}\sqrt{\pi}$
$\sqrt{2\pi}$
and so
$\int_0^\infty W\bigg(\frac{1}{x^2}\bigg)dx=\sqrt{2\pi}$

And that concludes this blog post!