Skip to content

Invert dimensions after / in parsed and composed expressions - #102

Merged
suleman-uzair merged 1 commit into
mainfrom
fix/parser-dimension-division
Nov 6, 2026
Merged

suleman-uzair merged 1 commit into
mainfrom
fix/parser-dimension-division

Conversation

@suleman-uzair

@suleman-uzair suleman-uzair commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

This PR makes the parser invert a dimension after /, as it already does for a unit. dim_L/dim_T serialized as D_LT (Time power 1) instead of D_LT-1. This restores the behaviour of asciimath2unitsml, whose postprocess1 inverts every term after /, dimensions included.

Changes

  • Parser#update_units_exponents applies the same sqrt/inverse rule to Unit and Dimension; inverse_power_numerator moves to the shared PowerNumerator module.
  • Compose::Builder drops the invert_dimensions: false path, so Quantity division of dimension quantities gives dim_L*dim_T^(-1).
  • The two specs that pinned the un-inverted output now expect the inverted form, with new specs for parsed dimension division.

Output change

dim_X/dim_Y now serializes with the inverted power. The old output was wrong.

The parser inverted a unit after "/" but skipped a dimension, so
dim_L/dim_T serialized as D_LT instead of D_LT-1. Dimensions now follow
the same rule as units: inverse_power_numerator moves to the shared
PowerNumerator storage and the parser applies it to both.

Quantity arithmetic no longer keeps dimension leaves un-inverted on
division, so Quantity(dim_L) / Quantity(dim_T) gives dim_L*dim_T^(-1).
The two specs that pinned the old output now expect the inverted form.
@suleman-uzair suleman-uzair changed the title Invert dimensions after / in parsed expressions Invert dimensions after / in parsed and composed expressions Nov 6, 2026
@suleman-uzair
suleman-uzair marked this pull request as ready for review November 6, 2026 13:14
@suleman-uzair
suleman-uzair merged commit d42601d into main Nov 6, 2026
19 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.

1 participant