← Back to Pull requests

BUG: riccati_jn: fix uninitialized and inaccurate high orders #598

Closed
unknown closed this pull request without merging on Nov 29, 2026 20:27 UTC
View on GitHub
unknown unknown commented on Nov 21, 2026 00:51 UTC
Author

Reference issue


No issue; follow-up to #572, found while porting xsf to Rust (https://github.com/jorenham/xsf-rust/pull/1746):

>>> import scipy.special as sc  # SciPy 1.18.1
>>> sc.riccati_jn(300, 1.0)[0][[105, 199]]  # [1.9599728528102047e-201, 0.0] (mpmath)
array([1.95997285e-201, 6.18469744e-310])

What does this implement/fix?


rctj now always starts the backward recurrence at msta2(x, n, 15), as the MSTA2 branch of the Fortran RCTJ, instead of at msta1(x, 200) when that is below n, which left the orders above it unwritten and the ones just below it inaccurate. The rescaling from #572 prevents overflow at the higher start. For k >= |x| where rj[k] is subnormal or zero, dj[k] now uses the ratio $r_k = \mathrm{rj}_k / \mathrm{rj}_{k-1}$ of two equally scaled recurrence values: $\mathrm{dj}_k = (1 - k r_k / x)\,\mathrm{rj}_{k-1}$ (DLMF 10.51.2).

Additional information


The new test fails on main with GCC and Clang (relative error 5e-10, and NaN-prefilled orders left unwritten) and passes with the fix. There are no xsref table tests for riccati_jn.

AI Generation Disclosure


Claude Sonnet 5.5 (Claude Code) wrote the fix, the test, and this description, and Claude Opus 5.5 (Claude Code) the dj underflow fix, following the plan in this comment. GPT-6.2 Sol (Codex CLI) reviewed it, and two GPT-6.2 Sol instances the dj fix.

Diff: 199 lines (+149 / -50) across 2 files Reviewer: jorenham Review duration: 12695m
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.36) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.36 · 199 lines diff across 2 files
0.36
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
56%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.317
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #598"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 56.8% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 36.1% (MEDIUM) · Higher = larger blast radius
36.1%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 56.8% · Lower = rushed or shallow review
56.8%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 15.6% · Safe to merge
15.6%
Repository