Skip to content

LambertW ​

The Lambert WW function (Wolfram's ProductLog), the inverse of w eww\,e^w. compute-engine's native LambertW already covers the principal (k=0k=0) and lower-real (k=−1k=-1) branches numerically; extended here with exact values at algebraically nice points and every other integer branch.

✓ checked against that system · ! checked, with disagreements (hover a chip)WikipediaLambert W functionMathWorldLambertW-FunctionWikidataQ429331nLabLambert W-functionDLMF4.13.E1FungrimLambertW✓Fungrim entryWolfram LanguageProductLog✓
LambertW(z)the principal branch W0(z)W_0(z) — native, extended with exact values.
SageMathlambert_w(z)mpmathlambertw(z)
LambertW(z, k)the kk-th branch Wk(z)W_k(z), by Halley's iteration from the standard log-log seed (Corless et al. 1996). k=0k=0 and k=−1k=-1 stay on compute-engine's own native handler.
SageMathlambert_w(k, z)mpmathlambertw(z, k)
Typed signatures
TypePackageApplies
(z: complex | infinity, branch: integer?) -> numberanalyticreplaces compute-enginealways
(z: complex | infinity, branch: integer?) -> numbercompute-enginealways

Domain: Special functions

Details
  • Differs from Wolfram: the branch is the second argument, LambertW(z,k)\mathrm{LambertW}(z, k), in compute-engine's order. Wolfram's ProductLog[k, z] and Sage's lambert_w(k, z) take (k,z)(k, z); mpmath's lambertw(z, k) takes (z,k)(z, k), like ours. Keep this order in mind when pasting a call across systems: the same branch W−1(−0.2)≈−2.5426W_{-1}(-0.2) \approx -2.5426 is LambertW(-0.2, -1) here, ProductLog[-1, -0.2] in Wolfram, lambert_w(-1, -0.2) in Sage and lambertw(-0.2, -1) in mpmath. Swapped, ProductLog[-0.2, -1] is an error in Wolfram (the branch must be an integer), and LambertW(-1, -0.2) declines here. The Wolfram transpiler reverses the arguments at the boundary.
  • Checked directly: LambertW(-0.14, -1) is the k=−1k=-1 branch. The Sage form is documented prior art, not run here.
  • Exact values are recognized structurally at z=0z=0, z=ez=e (giving w=1w=1), z=−1/ez=-1/e (giving w=−1w=-1), z=n enz = n\,e^n for small integer nn, and z=−ln⁡(k)/kz=-\ln(k)/k for small integer k≥2k \ge 2 (giving w=−ln⁡kw=-\ln k, since e−ln⁡k=1/ke^{-\ln k}=1/k) — even under plain evaluate(), not just N().
  • Every other branch is solved by Halley's method in the complex plane; checked against wolframscript's N[ProductLog[k, z], 16] at several points (real and complex zz, several kk) to full double precision.

Plot

ComplexPlot
real slice

Examples

4 more kept as data, checked against the oracles
Basic #
live ↗
InW⁡(0)\operatorname{W}(0)Out00

1⋅e1=e1 \cdot e^1 = e

live ↗
InW⁡(e)\operatorname{W}(e)Out11
Scope #

The branch point −1/e-1/e

live ↗
InW⁡(−1e)\operatorname{W}(-\frac{1}{e})Out−1-1

2e2=wew2e^2 = w e^w at w=2w = 2

live ↗
InW⁡(2e2)\operatorname{W}(2e^2)Out22

−ln⁡2⋅e−ln⁡2=−ln⁡22-\ln 2 \cdot e^{-\ln 2} = -\tfrac{\ln 2}{2}

live ↗
InW⁡(−ln⁡(2)2)\operatorname{W}(-\frac{\ln(2)}{2})Out−ln⁡(2)-\ln(2)

A branch other than 0 or -1, checked against N[ProductLog[-3, -0.14], 16]

live ↗
InN(W⁡−3(−0.14))N(\operatorname{W}_{-3}(-0.14))Out−4.645 279 174 278 859−13.812 745 325 218 817i-4.645\,279\,174\,278\,859-13.812\,745\,325\,218\,817i

Known value · Wolfram 15.0.0 ProductLog

The branch k=1k = 1, written in compute-engine's (z,k)(z, k) order — Wolfram's ProductLog[1, 1]

live ↗
InN(W⁡1(1))N(\operatorname{W}_{1}(1))Out−1.533 913 319 793 574 4+4.375 185 153 061 898i-1.533\,913\,319\,793\,574\,4+4.375\,185\,153\,061\,898i

The real branch k=−1k = -1 on −1/e<z<0-1/e < z < 0, written (z,k)(z, k) as here; Wolfram's ProductLog[-1, -0.2] and mpmath's lambertw(-0.2, -1) give the same value

live ↗
InN(W⁡−1(−0.2))N(\operatorname{W}_{-1}(-0.2))Out−2.542 641 357 773 526 424 29-2.542\,641\,357\,773\,526\,424\,29
About
Examples12
Checked againstWolfram Language 12 agreeSageMath 12 agreempmath 12 agree
CrosswalkWikipediaMathWorldWikidatanLabDLMFFungrimFungrim entry ×20Wolfram LanguageSageMath ×2mpmath ×2

Implementation

primitive · kernela kernel — an algorithm over mutable state that would not be readable as a tree

nativeenginetypescriptpackages/symbols/analysis/analytic/src/lambert-w.ts

Halley's iteration in the complex plane for k ∉ {0, -1}; structural pattern matching for the exact cases.

mappedmpmathpackages/oracle/src/mappings.ts
mappedmpmathpackages/oracle/src/mappings.ts

mpmath takes the branch second: lambertw(z, k).

mappedsagepackages/oracle/src/mappings.ts
mappedsagepackages/oracle/src/mappings.ts

See also: Exp, Ln