Skip to content

The Lambert W function - #2202

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
the-lambert-w-function
Oct 29, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
the-lambert-w-function

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

lambertw(z) and lambertw(k, z) (also productlog, Mathematica's name) were reserved in #2184. They are now the Lambert W function: the solution w of w e^w = z on branch k, or on the principal branch when k is omitted. Part of #2182.

  • Branches follow Corless et al. (1996), as in Mathematica's ProductLog and mpmath's lambertw. W_0 is real on [-1/e, +oo) and W_(-1) on [-1/e, 0). On a cut, the value is the one approached from above.
  • Exact values: at 0, and wherever z is c e^c for a real c on the branch. So lambertw(e) is 1 and lambertw(-1/e) is -1.
  • Numerically (Number.LambertW), the branch is found in double precision, starting from the series about -1/e, from ln(1 + z), or from the asymptotic form, then Halley's iteration. The root is then refined by Halley's iteration at the working precision, which does not move it to another branch. Near -1/e, the series itself is evaluated at the working precision.
  • Checked against mpmath to 1e-25: 45 points on branches −2…2 in the tests, plus a one-off sweep of 700 random points on branches −3…3, on and around the cuts.
  • Derivative: e^(-W)/(1 + W), which is 1 at 0. LaTeX output is \operatorname{W}_{k} and SymPy output is LambertW.
Input Was (2.6.0) Now
"lambertw(e)".ToEntity().Simplify() e * lambertw 1
"productlog(e)".ToEntity().Simplify() e * productlog 1
"lambertw(-1, x)".ToEntity() throws UnhandledParseException lambertw(-1, x)

The solver does not use it yet. Solving x e^x = c is a follow-up.

🤖 Generated with Claude Code

https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

lambertw(z) and lambertw(k, z), also productlog, Mathematica's name, were reserved by name in #2184
and are now Entity.LambertWf, built by MathS.LambertW: the solution w of w e^w = z on the branch k,
a whole number, and the principal branch without one.

The branches are those of Corless, Gonnet, Hare, Jeffrey and Knuth (1996), as Mathematica's
ProductLog and mpmath's lambertw have them: W_0 is real on [-1/e, +oo) and W_(-1) on [-1/e, 0), both
are -1 at -1/e, and a value on a cut is the one approached from above. It is exact at 0, which is 0 on
the principal branch and -oo off it as ln 0 is, and where z is c e^c for a real number c the branch
takes: lambertw(e) is 1, lambertw(-1/e) is -1 and lambertw(-1, -2 e^(-2)) is -2.

Elsewhere it is evaluated at the working precision, in Number.LambertW. The branch is found in double
precision: from the series in p = sqrt(2 (e z + 1)) about the branch point, from ln(1 + z) on the
principal branch short of |z| = 3, and from ln z + 2 pi i k - ln(ln z + 2 pi i k) otherwise, each
taken to a root by Halley's iteration. That root is refined by the same iteration on decimal pairs
at the working precision, which triples the digits with each step and does not leave the branch.
Near the branch point, where double precision cannot resolve z + 1/e, the series is evaluated at the
working precision instead. Forty-five points on branches -2 to 2, and 700 random ones on -3 to 3 on
and about the cuts, agree with mpmath to 1e-25.

Its derivative is e^(-W(z)) / (1 + W(z)), which is 1 at 0 where W(z) / (z (1 + W(z))) is 0/0. It prints
as lambertw(z) and lambertw(k, z), draws as \operatorname{W}_{k}, and exports to SymPy's LambertW.

Part of #2182.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.32836% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.54%. Comparing base (76d334c) to head (05c077c).

Files with missing lines Patch % Lines
...ouriMath/Core/Entity/Continuous/Number/LambertW.cs 86.95% 4 Missing and 5 partials ⚠️
...nuous/Evaluation.Continuous.Arithmetics.Classes.cs 77.77% 1 Missing and 5 partials ⚠️
...y/Continuous/Entity.Continuous.LambertW.Classes.cs 66.66% 2 Missing ⚠️
...nuous/Solvers/EquationSolver/InvertNode.Classes.cs 0.00% 1 Missing ⚠️
...AngouriMath/Functions/TreeAnalyzer/Sort.Classes.cs 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2202      +/-   ##
==========================================
- Coverage   86.57%   86.54%   -0.03%     
==========================================
  Files         298      300       +2     
  Lines       66596    66717     +121     
  Branches    19320    19357      +37     
==========================================
+ Hits        57653    57742      +89     
- Misses       4865     4885      +20     
- Partials     4078     4090      +12     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.10% <94.32%> (-0.03%) ⬇️
fsharp 32.97% <ø> (ø)
interactive 40.72% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
Sources/AngouriMath/Convenience/MathS.cs 90.43% <100.00%> (+0.05%) ⬆️
Sources/AngouriMath/Core/Antlr/AngouriMathLexer.cs 99.21% <100.00%> (+<0.01%) ⬆️
...ources/AngouriMath/Core/Antlr/AngouriMathParser.cs 87.83% <100.00%> (+0.05%) ⬆️
Sources/AngouriMath/Core/Domains.Classes.cs 100.00% <100.00%> (ø)
...Math/Core/Transformations/Matching/MatchPattern.cs 86.36% <100.00%> (+0.02%) ⬆️
...ngouriMath/Functions/Continuous/Differentiation.cs 89.50% <100.00%> (+0.19%) ⬆️
...unctions/Output/Latex/Latex.Arithmetics.Classes.cs 97.74% <100.00%> (+0.05%) ⬆️
...ns/Output/ToString/ToString.Arithmetics.Classes.cs 100.00% <100.00%> (ø)
...ions/Output/ToSympy/ToSympy.Arithmetics.Classes.cs 76.92% <100.00%> (+0.36%) ⬆️
Sources/AngouriMath/Functions/Substitute.cs 84.49% <100.00%> (+0.08%) ⬆️
... and 5 more

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Rafael-SOWNet
Rafael-SOWNet merged commit 97843f4 into master Oct 29, 2026
36 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in AngouriMath Oct 29, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the the-lambert-w-function branch October 29, 2026 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant