Comments (5)
issue #380 has the explanation for why it is like that.
I trust that we agree that this is a restriction imposed by an unfortunate shortcoming of the current implementation details of uom
rather than something fundamental. Put another way ThermodynamicTemperature - ThermodynamicTemperature
should give TemperatureInterval
.
I do wonder if
TemperatureKind
is the correct way to go for affine quantities, instead of something else more generic on top ofuom
. Position and distance are also different, yet I don't see aLengthKind
for it or aLengthInterval
and the same goes for time and energy.
... and for any Quantity
, which is what the aforementioned #289 is all about.
And then how would you account for the fact that
Velocity * Time = LengthInterval
and notLength
?
-
All
Quantities
need an affine (Q<A>
) and a vector (Q<V>
) version. -
The affine versions cannot be added or multiplied, only subtracted (note the
V
s in some of the< >
):Q<A> - Q<A> = Q<V>
Q<A> + Q<V> = Q<A>
Q<A> + Q<A>
- meaninglessQ<A> * <anything>
- meaningless
-
The vector versions support many more operations:
Q<V> - Q<V> = Q<V>
Q<V> + Q<V> = Q<V>
Q<V> + Q<A> = Q<A>
Q1<V> * Q2<V> = Q3<V>
- etc.
When you say that
Velocity * Time = LengthInterval
You mean
Velocity<V> * Time<V> = Length<V>
They cannot possibly be <A>
s because multiplication is not implemented for <A>
s.
Your Length
is really Length<A>
and that cannot be the result of a multiplication: only Q<V>
can be the result of a multiplication; your LengthInterval
is really Length<V>
which is just as well, because Q<V>
s are the only things that can result from multiplying Q
s.
In fact, I believe a similar problem already exists:
ThermalConductance
andThermalConductivity
should only be multipliable withTemperatureInterval
, that's what makes physical sense.
In general, it only makes sense to multiply vector, not affine, quantities.
When it comes to quantities like ThermalConductance
or Mass
there is a stronger tendency to conclude that their affine varieties do not exist, than it is for quantities like Velocity
: any 21st century physicist knows that absolute velocities are expressed in some arbitrary frame of reference. Mass
has an obvious, objective, non-arbitrary frame of reference on which everyone agrees, so it's more difficult to appreciate that said obvious choice of zero for affine mass is not the only possible choice. When you make the obvious choice, you can get away with confounding affine and vector mass, which makes it easy to overlook that Mass
also comes in affine and vector varieties, and that it is important to distinguish between the two:
- Place a bowl on top of some kitchen scales.
- Do NOT press the TARE button.
- Put some rice in the bowl.
- How would you double the amount of rice in the bowl?
If your solution is to keep pouring in rice until the number shown by the display doubles, then you'll get the wrong answer precisely because you performed an operation that is only permitted on vector quantities on an affine quantity: you multiplied an affine mass by 2, and multiplying affine quantities doesn't make sense.
from uom.
Not a great answer, but I would convert to temperature interval and then back again: 0 K ThermodynamicTemperature + SUM(ThermodynamicTemperature - 0 K TemperatureInterval)
from uom.
I hit a similar issue, but subtracting TemperatureInterval
to a ThermodynamicTemperature
yields a ThermodynamicTemperature
, so SUM(ThermodynamicTemperature - 0 K TemperatureInterval)
is not really possible and the only way to do this is by getting the underlying value and creating a new TemperatureInterval with it, right?
from uom.
More generally speaking, while summing affine quantities makes no sense, computing their mean does. So affine quantities, not just ThermodynamicTemperature
but also anything that might eventually emerge from #289, should support computing means, without forcing the user to hack around the type system in order to achieve something perfectly reasonable.
I've not had the need to use uom
's temperatures yet, so I was expecting to be able to subtract one ThermodynamicTemperature
from another and get a TemperatureInterval
, but that appears not to work:
use uom::si::f32::{TemperatureInterval as dT, ThermodynamicTemperature as T};
fn temp_difference(t1: T, t2: T) -> dT { t2 - t1 }
gives a compilation error or the subtraction `t2 - t1', which prevents these sorts of implementations
fn mean_t(t1: T, t2: T) -> T {
let dt: dT = t2 - t1;
t1 + dt / 2.0
}
fn mean_temp(ts: &[T]) -> Option<T> {
if ts.is_empty() { return None }
let n = ts.len() as f32;
let t0: T = ts[0]; // An arbitrary reference value, any `T` will do
let mean_deviation_from_t0: dT = ts.iter().map(|t| t - t0).sum::<dT>() / n;
Some(t0 + mean_deviation_from_t0)
}
from uom.
@jacg issue #380 has the explanation for why it is like that. I do wonder if TemperatureKind
is the correct way to go for affine quantities, instead of something else more generic on top of uom
. Position and distance are also different, yet I don't see a LengthKind
for it or a LengthInterval
and the same goes for time and energy. And then how would you account for the fact that Velocity * Time = LengthInterval
and not Length
?
In fact, I believe a similar problem already exists: ThermalConductance
and ThermalConductivity
should only be multipliable with TemperatureInterval
, that's what makes physical sense.
from uom.
Related Issues (20)
- Unable to `clamp` quantity to a range. HOT 2
- Unexpected inequality with large conversion factor HOT 6
- Allow subtracting two thermodynamic temperatures HOT 3
- Deserialize references to quantities HOT 2
- New unit `ElectricalSusceptance` HOT 1
- Change of base_unit of Ratio quantity HOT 1
- Conversion to/from complex storage types is wrong
- Quantity-Aware access parts of quantity with complex storage type HOT 2
- Consider rust-specific cache action HOT 1
- Built-In SI system has no alias for Angular Momentum
- Unit conversion problem using BigRational
- Unclear about how to create arbitrary quantities with arbitrary units HOT 6
- Conversion to Watts HOT 1
- Newbie Feedback HOT 1
- New release HOT 1
- NIST Special Publication link
- Add a feature for bytemuck and/or zerocopy to `Quantity`
- Support fixed-point storage type(s)
- Better precision and abbreviation change for `astronomical_unit` HOT 6
- Implement clamp for f64 Quantities
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uom.