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, upper W left-parenthesis x right-parenthesis is the value that satisfies the equation upper W exp left-parenthesis upper W right-parenthesis equals x. Thus W is the inverse of the function g left-parenthesis w right-parenthesis equals w exp left-parenthesis w right-parenthesis.

The W function has two branches. The principal branch is denoted by upper W 0 and has the domain x greater-than-or-equal-to negative 1 slash e. The negative (lower) branch is denoted by upper W Subscript negative 1 and has the domain negative 1 slash e less-than-or-equal-to x less-than 0. 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 upper W left-parenthesis x right-parenthesis 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

xw(x)Exact
-0.367879-1-1
000
-0.346574-0.693147-0.693147
2.718281811


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 Two Branches of the Lambert  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 upper W prime left-parenthesis x right-parenthesis equals exp left-parenthesis minus upper W left-parenthesis x right-parenthesis right-parenthesis slash left-parenthesis 1 plus upper W left-parenthesis x right-parenthesis right-parenthesis. The indefinite integral is integral upper W left-parenthesis x right-parenthesis d x equals x left-bracket upper W left-parenthesis x right-parenthesis minus 1 plus 1 slash upper W left-parenthesis x right-parenthesis right-bracket plus upper C.

Last updated: May 07, 2026