On the Haskell Discourse [0], someone posted about another Haskell library, units [1], which allows to define unit systems NOT limited to the 7 physical dimensions. For example, adding a base dimension for currency would be nice to model electricity prices in currency per energy.
Dimension analysis is a super power in applied math. I was first taught it in chemistry, but was able to use it to avoid tripping myself up on just about every real world math problem I did...
(And I too changed an implementation to add units of measure to a system. It took a few days, and caused some grief with downstream system developers. But we also avoided the Mars Climate Orbiter experience in production )
The modeling of unit systems with types is fraught with all sorts of inconsistencies and design tradeoffs. There are quantities that have the same dimensions, but shouldn't be compared or allow arithmetic between them. Many issues with Temperature scales and how to interpret differences in these spaces.
I think a pretty well thought out approach to this is the mp-units library in c++ that uses the ISQ(International System of Quantities) [1].
There are some great blog posts on their site about modeling units systems and dimensions.
Fingers crossed it may even be added to the standard library in C++29.
Many quantities that in the current official version of SI appear to have the same dimensions, in fact do not have the same dimensions.
The illusion of having the same dimensions has been caused by a vote of the General Conference on Weights and Measures, which has been exactly as stupid as deciding by vote that 2 + 2 = 5. It is really a shame that something like this has happened.
According to that vote, some quantities have been declared as adimensional, even if arbitrary units of measurements must be chosen for them, exactly like for any other physical quantity and their units enter in the definitions of many other units, so changing any such choice of a unit changes the values of many other SI units, which implies that any version of SI that does not explicitly include the fundamental units chosen for "adimensional" quantities is incomplete.
The system of units of measurement required for the physical quantities includes fundamental units a.k.a. base units, which are chosen arbitrarily, without any constraints, and also derived units, whose values are determined in such a way as to eliminate all constants from the formulae that relate the physical quantity for which the derived unit is determined to other physical quantities for which units have already been determined.
The fundamental units are of 3 kinds, which I shall call arithmetic units, geometric units and dynamic units.
The arithmetic units are for discrete quantities, i.e. quantities that are expressed in integer numbers, so they have natural units.
There are a huge number of such fundamental units for quantities that can be obtained by counting, e.g. the number of atoms of a certain kind, the number of ions of certain kind, the number of molecules of a certain kind, the number of objects of a certain kind, the number of apples, the number of oranges, the number of humans and so on.
While "1" is the natural unit for all such quantities, in physics and chemistry there are many such quantities for which the conventional SI unit is not "1", but the number of Avogadro, a.k.a. one mole of substance.
Besides numbers of various entities, if we neglect nuclear/"elementary" particle physics, there is one more discrete physical quantity, which is the electric charge a.k.a. the quantity of electricity. The natural unit for the electric charge is the elementary electric charge and the conventional SI unit, the coulomb, is defined as an exact multiple of the elementary electric charge.
Besides the units for discrete quantities, there are 6 fundamental units for continuous quantities, 3 geometric units & 3 dynamic units. The 3 geometric units are the units of logarithmic ratio, plane angle and solid angle (which are respectively associated with 1-dimensional, 2-dimensional and 3-dimensional spaces).
The 3 fundamental geometric units are chosen by a mathematical convention, but they are exactly as arbitrary as the fundamental dynamic units. This is proven by the fact that in practice many different choices are used for these 3 fundamental units. Like length can be measured in meters or in feet, logarithmic ratios can be measured in nepers or in decibels, plane angles can be measured in degrees or in right angles or in cycles or in radians, while solid angles can be measured in orthogonal trihedral angles, in whole spheres or in steradians. Changing the choice for any of these fundamental units requires value conversions for all physical quantities that have units derived from them, in the same way like when replacing Imperial units with metric units.
There are many physical quantities in SI that appear to have the same dimensional formulae, but this happens only because the units of logarithmic ratio or plane angle or solid angle are omitted from the formulae. This omission is especially frequent for the unit of plane angle, which enters in a much greater number of dimensional formulae than it is obvious. For instance, the magnetic flux also includes in its dimensional formula the unit of plane angle, though you will almost never see this taken into account.
The SI includes a greater number of conventional fundamental dynamic units than necessary, for historical reasons, which results in a greater number of "universal constants" than for an optimal system of units, which requires only 3 fundamental dynamic units.
While at the end of the 18th century, when the metric system has been designed, it was convenient to choose as fundamental dynamic units the units of length, time and mass, for which distinct physical devices were chosen to materialize the units, the current SI system is equivalent with choosing a single physical device to materialize all 3 fundamental dynamic units, which are the units of length, time and electric voltage (yes, now the unit of mass is derived from the unit of electric voltage, not vice-versa, despite confusing definitions that can be encountered in many texts).
The single physical device that can materialize all 3 fundamental dynamic units is an atomic clock. The electromagnetic wave corresponding to its output signal provides the unit of length in its wavelength, the unit of time in its wave period, while the Josephson voltage corresponding to its frequency provides the unit of electric voltage. The conventional units of SI are obtained from the 3 units provided by an atomic clock by multiplication with conventional exact constants, in order to ensure continuity with the older units of measurement.
A few of the so-called base units of SI are no longer true base units, but they are derived from the true base units by inserting exact conventional constants in the formulae relating physical quantities, e.g. the units of temperature and luminous intensity.
Thanks for the explanation. When I taught physics, I was always annoyed by not being able to teach this correctly. Right from PHY101: Mechanics, as soon as you get to rotational motion, you run into these problems because of the units of plane angle issue. Common introductory texts get the units for rotational quantities wrong.
Do you have a reference for any undergrad text that does this correctly?
One thing I would stress is that there is not one "true" system of units that is correct in some absolute sense. Unit systems are to arithmetic as type systems are to code. It's OK to have different systems of units that are good at preventing different kinds of error. This means that when talking about
That being said, you can absolutely criticize any given unit system, just as you can criticize any given type system. And some of your criticisms* of SI are indeed valid. (*Out of those that I even understand at all.) It just means that when we compare unit systems, we should be focusing on factors like: what kinds of errors do they catch/prevent? How understandable are they? How reliable? You do that in some places, such as your excellent point about torque vs. energy. But it's less clear why we should be splitting out the 3 kinds of units or only ever specifying number of apples as integers (I can certainly have half an apple) -- how does this actually help us? I would also argue that if you're trying to say something like "1 Apple + 1 Orange != 2", then I'd argue for the same reason that "1 Apple + 1 Apple != 2", because different apples are different sizes, shapes, value, etc. Really I'm just not clear on almost any of your points about "discrete units".
And for the geometric units, why stop at 3? We obviously could have 4-dimensional angles as well (possibly not physically useful, but maybe for spacetime calculations ... and why should our system of units only apply to our particular universe?). You could have n^2 and n^3 units similar to logarithmic units (e.g. 1 squart = 1 foot, 2 squart = 4 feet, 3 squart = 9 feet). I'm not claiming any of those are useful, but I am claiming it shows that your examples are not "fundamental".
> The electromagnetic wave corresponding to its output signal provides the unit of length in its wavelength, the unit of time in its wave period.
But aren't the wavelength and period of an electromagnetic wave linearly correlated by the speed of light? Doesn't this make your 3 fundamental dynamic units only 2?
I am using Unitful.jl for some complex electromagnetics code I am developing. Although it makes the definition of types and constructors more complicated, it has helped me find several subtle bugs in the equations. Forcing the type system to keep track of measurement units has pros and cons, but so far, the advantages are more significant than the cons.
Doing it within an existing type system is more trouble than it’s worth: the algebra of units is simple, but it doesn’t apply to other types without stretching the compiler. It is far easier to have a distinct subsystem with measure types specifically identified.
I will say that the OpenFOAM C++ library supports dimensions in a more user friendly way than this, with support for both vectors/matrices and for checking units when you take partial derivatives of your quantities.
There is even native support for reading dimensioned values from input files, so your user can specify "speed 12.7 [ft/s]" irrespective of what units you use internally in the code processing that input file. It just gets converted (or throws an error).
I misread this title (the word "confidence" threw me) and was initially very confused when it turned out to be about dimensional analysis instead of uncertainty.
But why not both? A number system with dimensions and which automatically propagates measurement uncertainty through calculations (a la Taylor's train wreck book) doesn't seem totally infeasible?
I would particularly like this for expressing cad models as code instead of brep.
There are Haskell packages for uncertainty (e.g. [0], based on automatic differentiation [1]). However, these packages don't support typed dimensions, because multiplication/division becomes more complex.
It is my goal to provide quantities with uncertainty AND typed dimensions one day.
Very cool. Thanks for the links, I'm not very familiar with the Haskell ecosystem, I mostly work in Rust and Go these days. I'll definitely check them out.
This is the kind of thing that would be pretty straight-forward in Julia, I imagine. Independent libraries for uncertainties and units could easily be remixed together if the unitful quantity accepts any number type, and the uncertainties just define a new number type. Multiple dispatch should generate consistent downstream behavior "for free".
I haven't had the opportunity to use this in research yet, but i liked numbat [0], as it comes with relevant common units and lets you define your own. It appeared on HN before [1].
There is a good dimensional analysis package `ezunits` in Maxima. Very useful for working through equations and then sometimes generating the c/fortran code directly from Maxima is fine.
On the Haskell Discourse [0], someone posted about another Haskell library, units [1], which allows to define unit systems NOT limited to the 7 physical dimensions. For example, adding a base dimension for currency would be nice to model electricity prices in currency per energy.
[0]: https://discourse.haskell.org/t/blog-post-scientific-computi...
[1]: https://hackage.haskell.org/package/units
(And I too changed an implementation to add units of measure to a system. It took a few days, and caused some grief with downstream system developers. But we also avoided the Mars Climate Orbiter experience in production )
I think a pretty well thought out approach to this is the mp-units library in c++ that uses the ISQ(International System of Quantities) [1].
There are some great blog posts on their site about modeling units systems and dimensions. Fingers crossed it may even be added to the standard library in C++29.
[1]: https://mpusz.github.io/mp-units/latest/
The illusion of having the same dimensions has been caused by a vote of the General Conference on Weights and Measures, which has been exactly as stupid as deciding by vote that 2 + 2 = 5. It is really a shame that something like this has happened.
According to that vote, some quantities have been declared as adimensional, even if arbitrary units of measurements must be chosen for them, exactly like for any other physical quantity and their units enter in the definitions of many other units, so changing any such choice of a unit changes the values of many other SI units, which implies that any version of SI that does not explicitly include the fundamental units chosen for "adimensional" quantities is incomplete.
The system of units of measurement required for the physical quantities includes fundamental units a.k.a. base units, which are chosen arbitrarily, without any constraints, and also derived units, whose values are determined in such a way as to eliminate all constants from the formulae that relate the physical quantity for which the derived unit is determined to other physical quantities for which units have already been determined.
The fundamental units are of 3 kinds, which I shall call arithmetic units, geometric units and dynamic units.
The arithmetic units are for discrete quantities, i.e. quantities that are expressed in integer numbers, so they have natural units.
There are a huge number of such fundamental units for quantities that can be obtained by counting, e.g. the number of atoms of a certain kind, the number of ions of certain kind, the number of molecules of a certain kind, the number of objects of a certain kind, the number of apples, the number of oranges, the number of humans and so on.
While "1" is the natural unit for all such quantities, in physics and chemistry there are many such quantities for which the conventional SI unit is not "1", but the number of Avogadro, a.k.a. one mole of substance.
Besides numbers of various entities, if we neglect nuclear/"elementary" particle physics, there is one more discrete physical quantity, which is the electric charge a.k.a. the quantity of electricity. The natural unit for the electric charge is the elementary electric charge and the conventional SI unit, the coulomb, is defined as an exact multiple of the elementary electric charge.
Besides the units for discrete quantities, there are 6 fundamental units for continuous quantities, 3 geometric units & 3 dynamic units. The 3 geometric units are the units of logarithmic ratio, plane angle and solid angle (which are respectively associated with 1-dimensional, 2-dimensional and 3-dimensional spaces).
The 3 fundamental geometric units are chosen by a mathematical convention, but they are exactly as arbitrary as the fundamental dynamic units. This is proven by the fact that in practice many different choices are used for these 3 fundamental units. Like length can be measured in meters or in feet, logarithmic ratios can be measured in nepers or in decibels, plane angles can be measured in degrees or in right angles or in cycles or in radians, while solid angles can be measured in orthogonal trihedral angles, in whole spheres or in steradians. Changing the choice for any of these fundamental units requires value conversions for all physical quantities that have units derived from them, in the same way like when replacing Imperial units with metric units.
There are many physical quantities in SI that appear to have the same dimensional formulae, but this happens only because the units of logarithmic ratio or plane angle or solid angle are omitted from the formulae. This omission is especially frequent for the unit of plane angle, which enters in a much greater number of dimensional formulae than it is obvious. For instance, the magnetic flux also includes in its dimensional formula the unit of plane angle, though you will almost never see this taken into account.
The SI includes a greater number of conventional fundamental dynamic units than necessary, for historical reasons, which results in a greater number of "universal constants" than for an optimal system of units, which requires only 3 fundamental dynamic units.
While at the end of the 18th century, when the metric system has been designed, it was convenient to choose as fundamental dynamic units the units of length, time and mass, for which distinct physical devices were chosen to materialize the units, the current SI system is equivalent with choosing a single physical device to materialize all 3 fundamental dynamic units, which are the units of length, time and electric voltage (yes, now the unit of mass is derived from the unit of electric voltage, not vice-versa, despite confusing definitions that can be encountered in many texts).
The single physical device that can materialize all 3 fundamental dynamic units is an atomic clock. The electromagnetic wave corresponding to its output signal provides the unit of length in its wavelength, the unit of time in its wave period, while the Josephson voltage corresponding to its frequency provides the unit of electric voltage. The conventional units of SI are obtained from the 3 units provided by an atomic clock by multiplication with conventional exact constants, in order to ensure continuity with the older units of measurement.
A few of the so-called base units of SI are no longer true base units, but they are derived from the true base units by inserting exact conventional constants in the formulae relating physical quantities, e.g. the units of temperature and luminous intensity.
Do you have a reference for any undergrad text that does this correctly?
That being said, you can absolutely criticize any given unit system, just as you can criticize any given type system. And some of your criticisms* of SI are indeed valid. (*Out of those that I even understand at all.) It just means that when we compare unit systems, we should be focusing on factors like: what kinds of errors do they catch/prevent? How understandable are they? How reliable? You do that in some places, such as your excellent point about torque vs. energy. But it's less clear why we should be splitting out the 3 kinds of units or only ever specifying number of apples as integers (I can certainly have half an apple) -- how does this actually help us? I would also argue that if you're trying to say something like "1 Apple + 1 Orange != 2", then I'd argue for the same reason that "1 Apple + 1 Apple != 2", because different apples are different sizes, shapes, value, etc. Really I'm just not clear on almost any of your points about "discrete units".
And for the geometric units, why stop at 3? We obviously could have 4-dimensional angles as well (possibly not physically useful, but maybe for spacetime calculations ... and why should our system of units only apply to our particular universe?). You could have n^2 and n^3 units similar to logarithmic units (e.g. 1 squart = 1 foot, 2 squart = 4 feet, 3 squart = 9 feet). I'm not claiming any of those are useful, but I am claiming it shows that your examples are not "fundamental".
> The electromagnetic wave corresponding to its output signal provides the unit of length in its wavelength, the unit of time in its wave period.
But aren't the wavelength and period of an electromagnetic wave linearly correlated by the speed of light? Doesn't this make your 3 fundamental dynamic units only 2?
Doing it within an existing type system is more trouble than it’s worth: the algebra of units is simple, but it doesn’t apply to other types without stretching the compiler. It is far easier to have a distinct subsystem with measure types specifically identified.
There is even native support for reading dimensioned values from input files, so your user can specify "speed 12.7 [ft/s]" irrespective of what units you use internally in the code processing that input file. It just gets converted (or throws an error).
See e.g. this, from 4.2.6 onwards: https://doc.cfd.direct/openfoam/user-guide-v12/basic-file-fo...
But why not both? A number system with dimensions and which automatically propagates measurement uncertainty through calculations (a la Taylor's train wreck book) doesn't seem totally infeasible?
I would particularly like this for expressing cad models as code instead of brep.
It is my goal to provide quantities with uncertainty AND typed dimensions one day.
[0]: https://hackage.haskell.org/package/uncertain
[1]: https://hackage.haskell.org/package/ad
[0]: https://github.com/sharkdp/numbat
[1]: https://news.ycombinator.com/item?id=38276430