Repository navigation
The Lambert W function compiles, and W_0 left of -2/e is on its branch - #2214
Merged
Merged
Conversation
lambertw compiles in both compilers, through LambertWFunction, a double-precision kernel on the interpreter's branches: a start, then Halley's iteration, with the imaginary part held at 0 where the branch is real, -1 within rounding of the branch point, and NaN on a branch that is not whole. The evaluator takes its double-precision start from the same kernel, which replaces InDoublePrecision. Comparing it with mpmath found the start wrong for W_0 on the axis from -1 to -2/e and about -1: ln(1 + z) is real there, where W_0 is not, so the iteration never left the axis (W_0(-0.975) was -6.61), and near -1 it reached another branch (W_0(-1.02) was its conjugate). The starts are now SciPy's regions on the principal branch: the branch-point series within 0.3 of -1/e, ln(1 + z) in a box right of -1 about the axis, and the asymptotic start elsewhere. Evaluation and the compiled form agree with mpmath at 11,501 points: the real axis from -5 to 0 on three branches, and 10,000 random points on seven. Part of #2195 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 #2214 +/- ##
==========================================
- Coverage 86.59% 86.58% -0.01%
==========================================
Files 303 304 +1
Lines 67168 67207 +39
Branches 19495 19509 +14
==========================================
+ Hits 58162 58194 +32
- Misses 4903 4907 +4
- Partials 4103 4106 +3
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.
Part of #2195, item 3:
lambertwcompiles. The PR also fixes a defect in #2202's evaluation that compiling it brought to light.Compiling.
Numerics/LambertWFunctionis a double-precision kernel on the interpreter's branches, Corless et al.'s, as #2202 has them:0where the branch is real;-1within rounding of the branch point, andNaNon a branch that is not whole.FastExpression has an instruction for it, and LINQ has
Complexanddoubledefinitions; overdoublea complex value isNaN. Evaluation now takes its double-precision start from the same kernel, which replacesInDoublePrecision.The defect. Comparing the kernel with mpmath found evaluation wrong as well, because the two shared one start:
W_0on the real axis from-1to-2/ewas real. The start there wasln(1 + z), which is real whereW_0is not, so the iteration never left the axis:W_0(-0.975)was-6.61, where mpmath gives-0.3358 + 1.3221i.-1, the same start is nearln 0, and the iteration reached another branch:W_0(-1.02)andW_0(-1.349 - 0.358i)came back as conjugates.#2202's 700-point check against mpmath missed it, because random complex points almost never lie on the axis.
The starts now follow SciPy's
lambertwregions on the principal branch:0.3of-1/e;ln(1 + z)in a box right of-1about the axis;The other branches are unchanged.
lambertwis new since 2.6.0, so there is no 2.6.0 row; its entry says it compiles.Checked against mpmath (dps 30) at 11,501 points, evaluated and compiled alike: the real axis from
-5to0in steps of0.01on branches-1,0and1, and 10,000 random points on branches-3to3, a third of them near-1and a tenth far out. All agree to1e-9.Tests:
LambertWCompilationTestcompares both compilers with evaluation on branches-2,-1,0,1,3and1/2, at 19 points: the branch point, either side of it, the negative axis, far out, and off the axis.LambertWTestgains five mpmath rows at-0.8,-0.975,-1,-1.02and-1.349 - 0.358i.🤖 Generated with Claude Code
https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura