You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
HandyModRTransform.deriv3 returns the wrong third derivative whenever m >= 3. For m = 1 and m = 2 it is correct, which is the only range the current tests use.
The first term in the numerator is written as 2 * two_m * (m - 2) * (m - 1) * (1 - two_m + size_r) ** 2, but differentiating r(x) three times gives two_m**2 there, not 2 * two_m. The term is multiplied by (m - 1)(m - 2), so the mistake only shows up from m = 3 on.
Because deriv3 feeds deriv3_inverse and the transformed ODE solvers, those are off too. A small example with solve_ode_ivp on y''' = 6, y(-0.5) = y'(-0.5) = y''(-0.5) = 0, whose exact solution is (x + 0.5)**3:
Comparing deriv3 directly against the symbolic third derivative (sympy) of transform for rmin=0.1, rmax=10, the relative error is ~1e-15 for m = 1, 2 and 0.75, 0.87, 0.94 for m = 3, 4, 5.
The fix is a one-line change (2 * two_m to two_m**2) plus a test that checks deriv3 against finite differences for m = 1 to 5. I have a patch ready if that's fine.
Activity