Inferred division from defined multiplication relations
In #1329 this proposal came up:
Another idea: generate division operators based on multiplication. Right now we define:
ElectricPotential.Volt = ElectricCurrent.Ampere * ElectricResistance.Ohm (and generate the reverse) ElectricCurrent.Ampere = ElectricPotential.Volt / ElectricResistance.Ohm ElectricResistance.Ohm = ElectricPotential.Volt / ElectricCurrent.AmpereBut those last two could also be generated based on the first.
This PR is an experiment implementing this.
I rebased this on the latest changes in #1329 which makes it much cleaner.
Example of an interesting situation that occurs here, we previously defined:
MassFlow.GramPerSecond = Area.SquareMeter * MassFlux.GramPerSecondPerSquareMeter
MassFlux.KilogramPerSecondPerSquareMeter = MassFlow.KilogramPerSecond / Area.SquareMeter
If we infer division from multiplication, one of those has to add or lose a kilo ๐
Will review this next, hopefully in the next few days.
If we infer division from multiplication, one of those has to add or lose a kilo ๐
Haha ๐ But it will still work, right? The inferred division will just use grams instead?
Yes, it will work, except we're not sure why the original contributor chose a particular unit for an operator and if it matters, with precision for example.
Also, this PR is more of an experiment than a serious proposal. There's some questions about the "magic" of it, and I took some liberties with implicit/explicit conversion between Density and MassConcentration that I'm not quite sure about. Maybe @lipchev can chime in on this?
Yes, it will work, except we're not sure why the original contributor chose a particular unit for an operator and if it matters, with precision for example.
Also, this PR is more of an experiment than a serious proposal. There's some questions about the "magic" of it, and I took some liberties with implicit/explicit conversion between
DensityandMassConcentrationthat I'm not quite sure about. Maybe @lipchev can chime in on this?
Although the Density and Mass Concentration share the same units, they are not interchangeable- they describe different types of ratios. Casting between them (either implicitly or explicitly) makes no sense..
Thanks for the explanation! That makes the concept of inferred division a bit harder, given that we currently have:
Mass.Kilogram = Density.KilogramPerCubicMeter * Volume.CubicMeter
Mass.Kilogram = MassConcentration.KilogramPerCubicMeter * Volume.CubicMeter
which leads to these inferred ambiguous operators, which is what I tried to solve with my casting shenanigans:
Density.KilogramPerCubicMeter = Mass.Kilogram / Volume.CubicMeter
MassConcentration.KilogramPerCubicMeter = Mass.Kilogram / Volume.CubicMeter
The latter is currently not defined, so skipping it would not be a breaking change. I've reworked this PR to do that and removed the casting stuff.