Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify common unit if label has just one unit #338

Merged
merged 3 commits into from
Dec 2, 2024

Conversation

chiphogg
Copy link
Contributor

@chiphogg chiphogg commented Dec 2, 2024

If we don't do this, it's a weird situation: we end up with a
CommonUnit<A, B, ...> type, whose label is just the label for a
single simple unit X... which is quantity-equivalent to
CommonUnit<A, B, ...>. This means that when we print it, it will
look just like it is X, and people might get confused.

With this PR, when we're in this situation, we simply make
CommonUnitT<A, B, ...> (note the T, i.e., "compute the common unit")
return X itself!

To do this, we could try to piggyback on the label definition. I
found that way introduces some really confusing circular dependencies. I
find it is much simpler to simply count the distinct unscaled units in
the common unit, and do the simplification exactly when we get down to
only one.

Helps #105.

If we don't do this, it's a weird situation: we end up with a
`CommonUnit<A, B, ...>` type, whose _label_ is just the label for a
single _simple_ unit `X`... which is quantity-equivalent to
`CommonUnit<A, B, ...>`.  This means that when we print it, it will
_look just like it is_ `X`, and people might get confused.

With this PR, when we're in this situation, we simply make
`CommonUnitT<A, B, ...>` return `X` itself!

To do this, we _could_ try to piggyback on the label definition.  I
found that way introduces some really confusing circular dependencies.
I find it is much simpler to simply count the _distinct unscaled units_
in the common unit, and do the simplification exactly when we get down
to only one.

Helps #105.
This slipped through the cracks in the development.
@chiphogg chiphogg added the release notes: ✨ lib (enhancement) PR enhancing the library code label Dec 2, 2024
@chiphogg chiphogg merged commit 827edd8 into main Dec 2, 2024
13 checks passed
@chiphogg chiphogg deleted the chiphogg/reduce-to-single-equiv#105 branch December 2, 2024 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release notes: ✨ lib (enhancement) PR enhancing the library code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants