Repository navigation
Rewrite J1's (4, 8] rational exactly to avoid cancellation - #1627
Merged
Merged
Conversation
The same approximation, expanded in t = (x^2 - 40) / 24 with its root near j(1,1) divided out. Double error on (4, 8] drops from 85 ulps to under 4. Closes #1626 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NAThompson
force-pushed
the
bessel-j1-accuracy
branch
from
November 3, 2026 04:30
b52c2b6 to
dc3597b
Compare
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.
The same approximation, expanded in t = (x^2 - 40) / 24 with its root near j(1,1) divided out.
Double error on (4, 8] drops from 85 ulps to under 4.
Closes #1626
The (4, 8] branch evaluated P2(x²), whose alternating coefficients cancel by up to 62x. This rewrites the same rational function exactly (no refit): P2 is divided by (y − r₀), r₀ its root near j(1,1)², and both polynomials are re-expanded about y = 40. The remaining cancellation is at most 5.8x. Evaluated at 80 digits, the new form agrees with the old one to 9e-20 on [4, 8], so the long double approximation is unchanged.
cyl_bessel_j(1, x)on (4, 8]Integer orders computed by recurrence from J₁ get the fix too: J₇(7.695) went from −58 to 0.7 eps and J₁₀(7.902) from −82 ulps to 0.7 eps.
cyl_bessel_j(1, x) on [4, 8], develop (orange) vs this PR (blue)

This PR alone

Near the x = 4 and x = 8 branch points


cyl_bessel_j(7, x) on [5, 8], where its recurrence uses J₁ on (4, 8]

Apple M-series, clang -O2; benchmark in
reporting/performance/cyl_bessel_j_performance.cpp. Y₁'s (4, 8] branch has the same kind of cancellation; that is for a separate PR.🤖 Generated with Claude Code