Lambert W function

The Lambert W function is used in mathematics to solve equations in which the unknown appears both outside and inside an exponential function or a logarithm, such as $$3x+2=e^x$$ or $$x=\ln(4x)$$. Such equations cannot otherwise, except in special cases, be solved explicitly in terms of algebraic operations, exponentials and logarithms.

Definition
The Lambert W function is defined as the multivalued function $$W$$ that satisfies


 * $$z = W(z)e^{W(z)}\;$$

for any complex number $$\scriptstyle z$$. Equivalently, it may be defined as the inverse function of $$f(w) = we^w$$. Thus, the equation $$C = we^w$$ is by definition solved by $$\scriptstyle w = W(C)$$. The multivaluedness of the Lambert W function means that there is generally more than one solution. The graph of the Lambert W function in the real numbers looks as follows:

The function has two real branches in the interval $$-1/e < x < 0$$ which join at $$x = -1/e$$. Concretely, this means that the equation $$x = w e^w$$ has two real solutions if $$-1/e < x < 0$$. For example, if $$x = -0.15$$ (which is about half way between $$-1/e$$ and 0), there is one solution $$\scriptstyle w_0 \approx -0.17$$ that lies on the blue graph and another solution $$\scriptstyle w_{-1} \approx -3.0$$ that lies on the dashed red graph.

The single-valued function corresponding to the blue graph for $$\scriptstyle -1/e\, \le \, x \,< \,\infty$$ is called the principal branch of the Lambert W function and is denoted by $$W_0$$. The single-valued function corresponding to the dashed red graph for $$\scriptstyle -1/e \, \le \, x \, < \, 0$$ is called the negative branch, denoted by $$W_{-1}$$. The negative branch goes to $$\scriptstyle -\infty$$ as $$\scriptstyle x \to 0$$ while the principal branch grows slowly but unboundedly as $$\scriptstyle x \to \infty$$.

The behavior of the Lambert W function can be understood by comparing it to the natural logarithm, the inverse of $$e^w$$. For large negative or positive $$w$$, $$e^w$$ and $$we^w$$ grow similarly, so their respective inverse functions have similar asymptotes as well (except for the sign when $$w$$ is negative). Multiplying the exponential by $$w$$ deforms its graph around zero so that it is no longer monotone, and that is why the Lambert W function has two real branches: one for values on each side of the stationary point. The following pair of graphs shows the relation between the two exponential functions (left graph) and their inverse functions (right graph):

Like the complex logarithm, the Lambert W function has infinitely many complex branches; they are conventionally labeled $$W_k$$ where $$k$$ runs over all the integers. The details are discussed for instance in Corless et al.

Besides $$W(-1/e) = -1$$, the Lambert W function has the special values $$W_0(0) = 0$$ and $$W_0(e) = 1$$. The value $$\scriptstyle W_0(1) = 0.567143\ldots$$ is called the omega constant.

Examples of use
The Lambert W function solves any equation of the form $$C = x e^x$$ &mdash; we may call this the canonical form. Many other types of equations can be solved in terms of the Lambert W function as well, by using the rules of exponentials and logarithms to rewrite them in the canonical form. For example, the equation $$xb^x=a$$ is solved by $$\scriptstyle x=W(a\ln b)/\ln b$$ and $$a^x=x+b$$ is solved by


 * $$x = \frac{-b-W(-a^{-b} \ln a)}{\ln a}.$$

Valluri et al. give the following example of an equation from physics that can be solved with the Lambert W function. Planck's law states that the radiation intensity $$I$$ at wavelength $$\lambda$$ from a black body at temperature $$T$$ is given by


 * $$I(\lambda, T) = \frac{8\pi h c/\lambda^5}{\exp(hc/\lambda k T)-1},$$

where $$h$$ is Planck's constant, $$k$$ is Boltzmann's constant and $$c$$ is the speed of light. Note that $$\lambda$$ appears both inside and outside an exponential. Next, Wien's displacement law states that the maximum intensity is attained at the wavelength $$\lambda_{max} = b/T$$ where $$b$$ is a quantity called Wien's displacement constant. Using the Lambert W function, we can give an explicit formula for $$b$$.

To derive Wien's displacement law, we wish to solve $$\scriptstyle \partial I / \partial \lambda = 0$$. If we calculate the partial derivative, simplify, and perform the substitution $$x=hc/\lambda k T$$, we obtain the equation $$(x-5)e^x = -5$$. To write this in canonical form for application of the Lambert W function, we substitute $$w = x-5$$ and multiply both sides of the resulting equation by $$e^{-5}$$. This leaves $$w e^w = -5e^{-5}$$, with the nonzero solution $$w = W_0(-5e^{-5})$$. Substituting back the expression for $$x$$, we obtain Wien's displacement law with the value for Wien's constant given explicitly by


 * $$b = \frac{hc/k}{5+W_0(-5e^{-5})} = 2.893 \times 10^{-3} \, \mathrm{m} \, \mathrm{K}.$$

Calculus
It is possible to do calculus with the Lambert W function much like with other elementary functions. Its properties can be derived from the familiar properties of exponentials and logarithms, although we have to use the theory of implicit functions since the Lambert W function is defined implicitly rather than by a direct formula.

Let us first consider limiting behavior. When discussing the graph of the Lambert W function, we said that its asymptotes are "similar" to those of the natural logarithm, since the exponential in $$we^w$$ dominates when $$w$$ is large. A more precise statement is that


 * $$\lim_{x\to\infty} \frac{W_0(x)}{\ln x} = 1.$$

By similar reasoning, the negative branch approaches the singularity at $$x=0$$ logarithmically:


 * $$\lim_{x\to 0^-} \frac{W_{-1}(x)}{\ln(-x)} = 1.$$

However, the absolute difference between the Lambert W function and the natural logarithm, $$|\scriptstyle W(x)-\ln x|$$, diverges to infinity as $$x \to \infty$$. It is possible to give a more complicated asymptotic formula for the Lambert W function that eliminates this difference, in the form of an infinite series


 * $$W(x) = \ln(x) - \ln \ln(x) + \sum_{n=1}^\infty \frac{(-1)^n}{(\ln x)^n} c_n(x)$$

where


 * $$c_n(x) = \sum_{m=1}^n (-1)^m \;s(n, \,n-m+1)\; \frac{(\ln \ln x)^m}{m!}$$

and $$s(n, k)$$ denotes a Stirling number of the first kind. The series is absolutely convergent for sufficiently large $$x$$.

The Taylor series of the Lambert W function can be found by using the Lagrange inversion theorem to invert the series of $$w e^w$$. This way, we find that the principal branch of the Lambert W function has the Taylor series expansion


 * $$W_0(x) = \sum_{n=1}^\infty \frac{(-n)^{n-1}}{n!}x^n = x - x^2 + \begin{matrix}\frac{3}{2}\end{matrix}x^3 - \begin{matrix}\frac{8}{3}\end{matrix}x^4 + \begin{matrix}\frac{125}{24}\end{matrix}x^5 - \cdots$$

around $$x=0$$. Due to the singularity at $$x=-1/e$$, and as can be proved with the ratio test, the series converges for $$|x|<1/e$$. The Lambert W function further has the derivative


 * $$W'(x) = \frac{1}{(1+W(x))\exp(W(x))}$$

which is infinite at the branch point $$x = -1/e$$. The indefinite integral is given by


 * $$\int W(x) \,dx = x\left(W(x)-1+\frac{1}{W(x)}\right)+C.$$

It is also possible to find integrals of more complicated expressions containing the Lambert W function. See Corless et al. for an overview.

Numerical calculation
The value of $$W(z)$$ can be calculated by using a regular root-finding algorithm to solve the equation $$we^w-z=0$$ for $$w$$. Since the left-hand side has simple derivatives, Newton's method and Halley's method are both good choices. Halley's method amounts to iterating


 * $$w_{k+1} = w_k - \frac{w_k e^{w_k}-z}{e^{w_k} (w_k+1) - \frac{(w_k+2)(w_k e^{w_k}-z)}{2w_k+2}}$$

for $$k = 1, 2, \ldots$$. The initial value $$w_0$$ must be chosen carefully in order to end up on the correct branch. To calculate real values on the principal branch, any real number above $$-1$$ will work, but faster convergence is obtained by taking the initial value from an interpolating function around 0 for small arguments and a few terms of the asymptotic series for large arguments. With a sufficiently accurate initial value, a few iterations of Halley's method will give a value that is correct to full precision in ordinary floating-point arithmetic.

Of course, we could use standard root-finding techniques to solve equations without going through the trouble of rewriting them in terms of the Lambert W function. From the numerical point of view, the advantage of using the Lambert W function is that highly optimized implementations that have been tested for correctness are available; further, those implementations allow the user to select a complex branch of choice.

History and application
Equations of the kind that can be solved analytically with the Lambert W function are common in mathematics and science, yet the utility of such a function was not realized until recently. The Lambert W function was introduced in the 1980's as a function in the Maple computer algebra system, whose interface required an explicit notation for solutions of equations. The function's history highlights the importance of good mathematical notation: due to previously not being recognized as a function in its own right, it had not been studied systematically, despite its most important properties requiring only elementary complex analysis. An account of the function and its history that helped popularize it is given in a 1996 paper by R. M. Corless et al. (with Donald Knuth a notable co-author).

The basic theory behind the Lambert W function was investigated in 1779 by Leonhard Euler. The Maple developers chose the name of Johann Heinrich Lambert instead of Euler's since Euler had referenced work by Lambert in his paper, and possibly because "naming yet another function after Euler would not be useful".

Since its introduction, the Lambert W function has been applied to problems ranging from quantum physics to population dynamics to the complexity of algorithms. Cranmer discusses the application of the Lambert W function in solar wind physics and writes in the conclusion: "The Lambert W function used in these solutions was defined and publicized only about a decade ago, but it has rapidly become a convenient tool for mathematical physicists. The elegance of explicit solutions to equations thought previously to be expressible only implicitly is clear, but there also are many practical benefits to having explicit solutions as well."