Skip to content

Share one numpy.isclose tolerance check between the symbolic and physical quantity contexts - #289

Draft
m-messer wants to merge 1 commit into
fix/criteria-correctnessfrom
fix/tolerance-alignment
Draft

m-messer wants to merge 1 commit into
fix/criteria-correctnessfrom
fix/tolerance-alignment

Conversation

@m-messer

Copy link
Copy Markdown
Member

Problem

The symbolic and physical-quantity contexts each had their own rtol/atol check, and they disagreed (bug report, bug 9). This PR is stacked on #286 and replaces #262 (fix/atol-rtol-alignment), which made the same change on the code from before the refactor.

Symbolic (compare_numerically) Physical quantity (_within_tolerance)
Both rtol and atol set both had to pass only rtol was checked, unless the answer was 0
Boundary < <
Values that can't be converted to float not within tolerance raised

Changes

The agreed rules are the same as numpy.isclose, and they are what #262 proposed: |ans - res| <= atol + rtol*|ans|.

  • values_within_tolerance (new app/context/tolerance.py):
    • applies that rule;
    • if symbols cancel only in (ans - res)/ans (e.g. both sides are multiples of rho*L**3), it checks rtol alone, because atol needs a numerical value of the answer;
    • returns False when the values can't be compared numerically.
  • compare_numerically (app/context/symbolic/numerical.py) and _within_tolerance (app/context/physical_quantity/graphs/match.py) both call it.
    • For physical quantities, atol is still multiplied by the answer's unit factor, so it stays in the answer's units.
  • app/docs/user.md: the tolerance descriptions now say ≤ and explain how rtol and atol combine. Also fixes some broken LaTeX in the absolute_tolerance entry.

Behaviour changes (answer 1 unless noted):

Case Before Now
rtol 0.1, atol 0.5, response 1.55 rejected (both contexts) accepted
atol 0.5, response 1.5 (exactly at the tolerance) rejected accepted
answer rho*L**3, response 1.05*rho*L**3, rtol 0.1, atol 0.01 rejected accepted

A physical quantity whose tolerance comes from the answer's significant figures also accepts a value exactly at the boundary now (1 m accepts 1.5 m).

Checklist

  • Tests added/updated
  • Docs updated (app/docs.md) if user-facing behaviour changed

Testing

  • New tests:
    • test_numerical_tolerances in symbolic_evaluation_test.py and in physical_quantity_evaluation_test.py. The five cases that change behaviour failed before the fix.
    • test_values_within_tolerance calls the helper directly, including zero, complex and symbolic values.
  • pytest app: 1290 passed, 2 skipped, 1 failed. The failure is test_radians_to_frequency, which already failed before this PR.
  • mypy app: no issues.

With #284, #286, #288 and this PR, every bug in the report has a fix.

🤖 Generated with Claude Code

@m-messer m-messer mentioned this pull request Oct 19, 2026
@m-messer
m-messer added this pull request to stack #291 October 20, 2026 13:09
@m-messer
m-messer force-pushed the fix/tolerance-alignment branch from 2b9c77d to 729dd96 Compare October 20, 2026 14:14
@m-messer
m-messer removed this pull request from stack #291 October 20, 2026 14:19
@m-messer
m-messer force-pushed the fix/criteria-correctness branch from b9fb345 to c39aeb3 Compare October 23, 2026 09:43
@m-messer
m-messer force-pushed the fix/tolerance-alignment branch from 729dd96 to 1bf6443 Compare October 23, 2026 09:43
…ute tolerance checks; refactor evaluation logic and expand test coverage
@m-messer
m-messer force-pushed the fix/criteria-correctness branch from c39aeb3 to 64872a9 Compare October 23, 2026 12:44
@m-messer
m-messer force-pushed the fix/tolerance-alignment branch from 1bf6443 to 0ad04ad Compare October 23, 2026 12:44

This branch has not been deployed

No deployments
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.

1 participant