Skip to content

Fix HandyModRTransform.deriv3 for m > 2 - #348

Merged
marco-2023 merged 4 commits into
theochem:masterfrom
SajalDevX:fix-handymod-deriv3
Nov 5, 2026
Merged

marco-2023 merged 4 commits into
theochem:masterfrom
SajalDevX:fix-handymod-deriv3

Conversation

@SajalDevX

Copy link
Copy Markdown
Contributor

Fixes #347

HandyModRTransform.deriv3 had 2 * two_m in the first term of the numerator where the analytic third derivative has two_m**2. That term is multiplied by (m - 1)(m - 2), so it only goes wrong for m >= 3, and the existing tests all use m <= 2. The bad value also propagates to deriv3_inverse and to solve_ode_ivp / solve_ode_bvp on third-order ODEs with this transform (e.g. y''' = 6 with m = 3 was about 10% off the exact (x + 0.5)**3; it now matches).

Changes:

  • rtransform.py: 2 * two_m -> two_m**2 in HandyModRTransform.deriv3.
  • test_transform.py: test_handymod_deriv3_matches_finite_differences, checking deriv3 against the existing finite-difference helper for m = 1 to 5.

Testing:

  • The new test fails on master for m = 3, 4, 5 and passes with the fix.
  • I also checked deriv3 against the sympy third derivative of transform for m = 1 to 5 (relative error ~1e-15 after the fix), and reran the solve_ode_ivp example from the issue.
  • pytest src/grid/tests/test_transform.py src/grid/tests/test_rtransform.py src/grid/tests/test_ode.py passes (317 passed).
  • Black and ruff report nothing new in the touched files.

I used Claude to help find the bug and draft the test; I reviewed the change and ran the tests myself.

SajalDevX and others added 4 commits November 4, 2026 03:43
The first term of the numerator in deriv3 used 2 * 2**m where the
analytic third derivative has (2**m)**2. That term is multiplied by
(m - 1)(m - 2), so it vanishes for m = 1 and m = 2, which is why the
existing tests (all with m <= 2) did not catch it. For m >= 3 deriv3 is
wrong, and so are deriv3_inverse and solve_ode_ivp/solve_ode_bvp with
this transform on third-order ODEs.
@marco-2023

Copy link
Copy Markdown
Collaborator

Thanks, @SajalDevX, for your contribution. I added an analytical test and fixed the bounds of your test.

@marco-2023
marco-2023 self-requested a review November 5, 2026 12:59
@marco-2023
marco-2023 merged commit dd08d69 into theochem:master Nov 5, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HandyModRTransform.deriv3 is wrong for m > 2

2 participants