Repository navigation
Fix catastrophic cancellation in ibeta_inv_imp for a == 1, b == 1 - #1676
Closed
3956418278-dotcom wants to merge 1 commit into
Closed
3956418278-dotcom wants to merge 1 commit into
3956418278-dotcom wants to merge 1 commit into
Conversation
Member
|
Superseded by: #1679. Thanks for bringing this to our attention |
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.
Problem
In
include/boost/math/special_functions/detail/ibeta_inverse.hpp, the triviala == 1 && b == 1fast path inibeta_inv_impcurrently sets*py = 1 - pinstead of*py = q:When invoked through
ibetac_inv(1, 1, q, &y)(wherep = 1 - qis already passed alongside exactq), computing1 - p = 1 - (1 - q)suffers catastrophic cancellation for smallqand underflows to0belowq ~ 1.11e-16.This directly affects
quantile(complement(fisher_f_distribution<double>(2, 2), q)), which evaluatesdf2 * x / (df1 * y) = x / y(exact closed form:(1 - q) / q):q(1 - q) / q1e-79999999.00526355779999999.000000001999999991e-109999999171.5963593999999999999999999991e-151000799917193442.5(rtol = 8.0e-4)999999999999998.889999999999999993.85e-163002399751580329.5(rtol = 15.6%)2597402597402596.52597402597402596.4...1e-20inf1e+201e+20 - 11e-300inf9.999999999999999e+2991e+300 - 1Fix
Assign
*py = qdirectly whena == 1 && b == 1, preserving full precision for bothibeta_invandibetac_inv.Testing
test_complement_quantile_df2_2intest/test_fisher_f.cppcovering bothquantile(complement(fisher_f_distribution<double>(2, 2), q))andibetac_inv(1, 1, q, &y)acrossqdown to1e-300.-DBOOST_MATH_STANDALONE=1) against bothibeta_invandibetac_inv.Discovered while auditing scipy/scipy#26692 / scipy/scipy#26696.
AI disclosure: An AI coding assistant (Antigravity) was used to run the numerical sweep that identified this edge case, verify the fix, and draft this PR description; I reviewed the patch and test results.