Repository navigation
The Lambert W function - #2202
Merged
Merged
Conversation
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 Report❌ Patch coverage is Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
lambertw(z)andlambertw(k, z)(alsoproductlog, Mathematica's name) were reserved in #2184. They are now the Lambert W function: the solutionwofw e^w = zon branchk, or on the principal branch whenkis omitted. Part of #2182.ProductLogand mpmath'slambertw.W_0is real on[-1/e, +oo)andW_(-1)on[-1/e, 0). On a cut, the value is the one approached from above.0, and whereverzisc e^cfor a realcon the branch. Solambertw(e)is1andlambertw(-1/e)is-1.Number.LambertW), the branch is found in double precision, starting from the series about-1/e, fromln(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.e^(-W)/(1 + W), which is1at0. LaTeX output is\operatorname{W}_{k}and SymPy output isLambertW."lambertw(e)".ToEntity().Simplify()e * lambertw1"productlog(e)".ToEntity().Simplify()e * productlog1"lambertw(-1, x)".ToEntity()UnhandledParseExceptionlambertw(-1, x)The solver does not use it yet. Solving
x e^x = cis a follow-up.🤖 Generated with Claude Code
https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura