Replies: 7 comments 14 replies
-
What about the idea of not simplifying anything by default?
|
Beta Was this translation helpful? Give feedback.
-
Very interesting proposal. The idea of not simplifying hadn't even occurred to me. I have always been suspicious of constructs such as "m / m" (one ridiculous "definition" of the units for radians), both in code and on pen-and-paper. But I can see the motivation and the utility here, and I'm curious how it would work in practice. One negative consequence would be that the typenames printed in compiler errors would tend to become longer. I'm not sure how bad this would be in practice: many would be simplified by passing through an API, but many would not. I do feel very strongly that something like "m / km" should not be simplified. (This is already the case in mp-units and Au, and I'm confident we got it right.) The units "m" and "km" are separate units. From a practical point of view, I really don't think we want to be reasoning about whether unit X is a prefixed version of unit Y (let alone whether they are both prefixed versions of some other unit!). But then, if we take this for granted, and if we also continue gathering identical units to a single power, then "m / m" is treated differently than "m / km". This never bothered me before, but I do see the value in being consistent. Question: I notice that all of the examples involve division. To be consistent, should we also avoid simplifying multiplication? Should multiplying two quantities of "m" result in "m * m" rather than "squared(m)"? Question: Do we also now have order-dependence? Should "m *m / s" produce the same type as "m / s * m"? Will we also end up with things like "m / m * m / m * m"? |
Beta Was this translation helpful? Give feedback.
-
Hi,
My implementation does not simplify: you can cast to simplified units,
but "m/m" is not "1"
On 2024-06-24 15:45, Chip Hogg wrote:
Question: I notice that all of the examples involve division. To be
consistent, should we also avoid simplifying multiplication? Should
multiplying two quantities of "m" result in "m * m" rather than
"squared(m)"?
"m*m" is squared(m). m*m/m is squared(m)/m. In my implementation, that
is power_kind<m,2,1> (+2, -1 => +1 overall)
Question: Do we also now have order-dependence? Should "m *m / s"
produce the same type as "m / s * m"? Will we also end up with things
like "m / m * m / m * m"?
In my implementation that is simplified to power_kind<m,3,2>. "m*m/s" is
the same as "m/s*m".
I think order dependence would lead to madness.
Cheers,
Anthony
|
Beta Was this translation helpful? Give feedback.
-
On 24 June 2024 16:28:09 BST, Chip Hogg ***@***.***> wrote:
So, are you basically gathering together all of the positive and negative powers? That makes sense.
How do you deal with rational powers?
--
Reply to this email directly or view it on GitHub:
#582 (reply in thread)
You are receiving this because you were mentioned.
Message ID: ***@***.***>
At the moment I don't deal with rational powers, but making the positive and negative values rationals rather than integers isn't a big leap.
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
Beta Was this translation helpful? Give feedback.
-
We want the library to discriminate between I tried to implement this, but I have some problems on the way. Let's assume that we have a system of quantities with the following definitions: inline constexpr struct path_length : quantity_spec<length> {} path_length;
inline constexpr struct distance : quantity_spec<path_length> {} distance;
inline constexpr struct period_duration : quantity_spec<time> {} period_duration;
inline constexpr struct frequency : quantity_spec<inverse(period_duration)> {} frequency;
inline constexpr struct speed : quantity_spec<length / time> {} speed;
inline constexpr struct velocity : quantity_spec<speed, position_vector / time> {} velocity;
inline constexpr struct acceleration : quantity_spec<velocity / time> {} acceleration; Previously, the following resulted in the implicit conversions (we can call a function
The following resulted in the explicit conversion:
How the above should work with the lack of automatic simplifications? |
Beta Was this translation helpful? Give feedback.
-
Do you have a branch that disables simplification? I'd be curious to try some of my examples with that branch. |
Beta Was this translation helpful? Give feedback.
-
While fixing the remaining issues I got the following error:
This is much harder to understand than the previous simplified error:
Are we sure we want to go this path? |
Beta Was this translation helpful? Give feedback.
-
For the next mp-units release, I would like to revise the expression template simplification rules. This was initially proposed by @anthonywilliams in Tokyo, and I think it makes a lot of sense.
Current state
Currently, the same identifiers on the expression template list are always simplified. This provides a few interesting side effects:
This impacts the convertibility rules and decreases the safety of the library. I described this problem in detail in the P3045 "Dividing two quantities of the same kind" and "Arithmetic and compatibility of quantities of dimension one" chapters.
Proposed
Some entities should not be automatically simplified by default. We should be able to deal with units like
m/m
and expect them to appear if thekm/m
is supported as well. Also,isq::length / isq::length
should be allowed to happen with the following semantics:Open questions
Dimensions
As stated in https://en.wikipedia.org/wiki/International_System_of_Quantities#Dimensional_expression_of_derived_quantities, the dimension of derived quantities is a product of powers of base dimensions, and a result is provided by a specific equation. Does this mean that, by definition, dimensions should always be simplified? Even if we allow forming a type like
derived_dimension<isq::dim_length, per<isq::dim_length>>
orderived_dimension<isq::dim_length, isq::dim_time, per<isq::dim_time>>
in the framework, how would we print their symbols on the console?Beta Was this translation helpful? Give feedback.
All reactions