Language Reference
LAMBERTW Function
LAMBERTW (matrix <, branch> ) ;
This function is supported by the IML procedure and the iml action.
The LAMBERTW function evaluates either branch of the real-valued Lambert W function (Corless et al. 1996). The Lambert W function is defined implicitly: for a real value x, is the value that satisfies the equation
. Thus W is the inverse of the function
.
The W function has two branches. The principal branch is denoted by and has the domain
. The negative (lower) branch is denoted by
and has the domain
. The Lambert W function is computed according to the method described by Barry, Culligan-Hensley, and Barry (1995).
The optional scalar argument branch determines the branch of the Lambert W function. If you omit the branch parameter or specify branch = 0, the principal branch is computed; otherwise the negative branch is computed. The following statements evaluate the principal branch of the Lambert W function at special values of x for which the exact value of is known. The output is shown in Figure 214.
x = -exp(-1) // 0 // -log(2)/2 // exp(1);
Exact = -1 // 0 // -log(2) // 1 ;
w = LambertW(x);
print x w[L="w(x)"] Exact;
Figure 214: Values of the Lambert W Function
| x | w(x) | Exact |
|---|---|---|
| -0.367879 | -1 | -1 |
| 0 | 0 | 0 |
| -0.346574 | -0.693147 | -0.693147 |
| 2.7182818 | 1 | 1 |
To graph the Lambert W function, you can evaluate each branch of the function at a sequence of points. For example, you might evaluate the principal branch as follows:
em = -exp(-1);
x = do( em, 0, 0.005 ) || do(0, 2.9, 0.1);
w0 = lambertW(x, 0); /* principal branch */
In a similar way, you can compute values of the negative branch:
Upper = -5*exp(-5); /* x value for which W(x) = -5 */
x = do(em, Upper, 0.005);
wm = lambertW(x, -1); /* negative branch */
Figure 215 displays a graph of both branches of the Lambert W function.
Figure 215: The Two Branches of the Lambert W Function

The Lambert W function is used to simulate and compute quantiles for a generalized Gaussian distribution, which is a heavy-tailed distribution that has finite moments.
The derivative and integral of the Lambert W function are defined in terms of W. The derivative is . The indefinite integral is
.