Skip to content

Add significant figures and decimal places parameters - #300

Draft
m-messer wants to merge 1 commit into
feat/big-operator-symbolsfrom
feat/sig-figs-decimal-places
Draft

m-messer wants to merge 1 commit into
feat/big-operator-symbolsfrom
feat/sig-figs-decimal-places

Conversation

@m-messer

Copy link
Copy Markdown
Member

Stacked on #299, which is stacked on the rc4 pin in #298. Hold until #298 merges. Replaces #273 and #277.

The number-string helpers (read_written_number, round_to_significant_figures, round_to_decimal_places) are in lambda-feedback/lambda-feedback-packages#12. Grading and docs stay here.

Parameters

Parameter Alias Effect
significant_figures sig_figs The response must equal the answer to n sig figs, written to exactly n sig figs (92.00 ≠ 92 at 4 sf)
significant_figures_tolerance sig_figs_tol Sets rtol = 5*10**(-n); the written precision isn't checked
decimal_places dp Same as sig_figs, but counts decimal places; may be 0
decimal_places_tolerance dp_tol Sets atol = 0.5*10**(-n)

At most one of these, or of atol/rtol, can be set. A conflict or an out-of-range count raises a ValueError. A count that isn't an int (a bool isn't one) raises a TypeError. #277 raised a bare Exception; the messages are the same.

Where it goes

  • app/evaluation.py: _apply_precision_aliases and _apply_precision_parameters, applied in _build_parameters before the parsing parameters are made. sig_figs and dp go into new EvaluationParameters fields.
  • app/context/tolerance.py: relative_tolerance_from_sig_figs and absolute_tolerance_from_decimal_places.
  • app/context/symbolic/numerical.py:
    • sig_figs_match, decimal_places_match and matches_written_precision.
    • replace_pi moved out of compare_numerically so both can use it.
  • For a plain response/answer criterion, sig_figs/dp replace the comparison, not just act as a fallback:
    • in symbolic check_equality;
    • in physical quantity _quantity_match, where they replace the value comparison and units are still compared as usual. _tolerances skips the implicit tolerance from the answer when either is set.
  • Docs in app/docs/user.md and app/docs/dev.md. sig_figs_tol is documented as ≤, because the tolerance check here counts the boundary as within tolerance. Add decimal_places grading parameters #277's docs said <.

Tests

  • Ported Add decimal_places grading parameters #277's evaluation tests into symbolic_evaluation_test.py and physical_quantity_evaluation_test.py. The error tests check for the specific exception type.
  • Ported the matcher and tolerance helper tests into the new app/tests/precision_test.py. Dropped the cases that pass a float as the response string: the package helper only accepts str, and the app always passes a string.
  • 1476 passed. The 3 failures are the ones expected on Pin the packages to the rc5 preview #298: test_radians_to_frequency, and the two a!=b factorial cases that the Support inequalities in the answer and response #276 port fixes.
  • mypy is clean. The blocking flake8 selection reports 0. The warning-only run has one new warning: check_equality complexity is 11, one over the limit of 10.

🤖 Generated with Claude Code

Ports #273 and #277 onto the refactor. `sig_figs`/`significant_figures` and
`dp`/`decimal_places` check the precision the response is written to, and
`sig_figs_tol`/`significant_figures_tolerance` and
`dp_tol`/`decimal_places_tolerance` set `rtol`/`atol`. A conflicting or
out-of-range parameter raises a ValueError, and a non-integer count a
TypeError. The number-string helpers come from expression_parsing
(lambda-feedback-packages#12).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@m-messer
m-messer force-pushed the feat/big-operator-symbols branch from 4c58351 to 86a1678 Compare October 28, 2026 17:48
@m-messer
m-messer force-pushed the feat/sig-figs-decimal-places branch from 8fd9210 to 6079134 Compare October 28, 2026 17:48

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