Skip to content

physical-quantities: apply the unit factor to each value of a list - #16

Merged
m-messer merged 1 commit into
mainfrom
fix/quantity-value-list
Oct 28, 2026
Merged

m-messer merged 1 commit into
mainfrom
fix/quantity-value-list

Conversation

@m-messer

Copy link
Copy Markdown
Member

Summary

A quantity whose value stands for several values had the unit factor applied to the list as a whole. sympy_forms built ({value})*({factor}), so {1, 2} km became ((1, 2))*(1000), and parse_quantity raised QuantityParseError ("A bracketed list such as (a, b) can't be used in arithmetic"). This contradicted the documented standard_values ("several for a value such as {1, 2}").

Affected inputs, each with a unit:

  • {1, 2} km
  • 1,2~\mathrm{km} (a LaTeX comma list)
  • plus_minus 2 km
  • \pm 2~\mathrm{km}

When create_expression_set finds more than one value, the factor is now applied to each value. A single value is converted exactly as before.

Found while porting compareExpressions' main #295 onto the refactor (test_latex_response_parsed_as_list on compareExpressions #280).

Testing

  • New test_unit_factor_applies_to_each_value_of_a_list in physical_quantities/tests/test_regressions.py with four cases. All four fail without the fix.
  • scripts/test.sh: slr_parsing 116, criteria 105, expression_parsing 519 and physical_quantities 542, all passing.
  • ruff check, ruff format --check and mypy are clean.
  • tools/parity/check.py shows 0 unexpected changes and 0 mismatched. A first attempt multiplied the parsed values for single values too, which changed forms such as 3*micro*1 to 3*micro. Single values therefore keep the text route.

Follow-up (compareExpressions)

The app's LaTeX quantity preview (app/preview/physical_quantity.py) reads the value with parse_expression, so it still raises for a list. It needs to show either both values or the last one (main #295 kept the last one, giving 2 metre). That change goes with the pin bump that picks this up.

🤖 Generated with Claude Code

A value that stands for several values ({1, 2}, a LaTeX comma list such as
1,2~\mathrm{m}, or ±) with a unit was multiplied by the unit factor as a
whole, "((1, 2))*(1)", which raised QuantityParseError. The factor is now
applied to each value. A single value is converted as before (the parity
check is unchanged).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@m-messer
m-messer merged commit 0ac8fdd into main Oct 28, 2026
8 checks passed
@m-messer
m-messer deleted the fix/quantity-value-list branch October 28, 2026 16:39
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