1. 27
  1. 15

    Oooh, dimensional analysis is a really deeply interesting problem. There’s lots of surprising challenges here. Just a few:

    • Two incompatible quantities can have the same units. Each vector component of torque has units kg*(m/s)², which are also the same units for energy. But you can’t meaningfully add the x component of a torque vector to the kinetic energy!
    • Two compatible quantities can have different units. This can happen if you need to convert between different systems. In SI, capacitance is measured in Farads, which has units s⁴/kg(A/m)². In CGS, though, capacitance is measured in… cm.
    • Two dimensional quantities can be incompatible. Can you add a molar ratio to radians?
    • There’s a difference between point and interval units. Kelvin and “degrees celsius” are identical interval units but different point units.

    Some more resources on this topic:

    • Frink is a programming language designed around doing unit conversions.
    • Before he died, Bill Kent drafted out a book on representing measurements. Even the first draft is extremely good.
    • The Frink unit file has tons of technical and historical information on units. Like how we actually have two different versions of “frequency” and Why Lumens Are Stupid.
    1. 3

      Some thoughts

      • I’m always dissatisfied with dimensionless quantities. That’s one of the bigger frustrations in use of unit systems in scientific programming.
      • Conversion between systems is handled at least some of the time by standardization and conversion on creation of a unit. This seems reasonable for an important subset of users.
      • The difference between temperature types is a big deal. “Dimensional quantities” end up taking the form of a kind of vector space, but then their differences are a different sort of algebraic object (a torsor) which supports a different set of operations. This, honestly, should also be the case with energies.

      The compatibility of torque and energy is a good example there. Despite them having the same unit signature, they’re not compatible for algebraic reasons (energy is a torsor again). This is partly alleviated by noting that torque could also be considered a joule-per-radian and realizing its dissatisfying, again, for dimensionless units to participate only as scalars.

      1. 2

        Two incompatible quantities can have the same units.

        Two compatible quantities can have different units.

        This suggests that you want dimensional analysis, rather than “units of measure” analysis.

        When I took physics in college, it always annoyed me that people said things like “voltage”, rather than “electric potential”, or “amperage”, rather than “current”, etc. It suggests insufficiently abstract thinking.

        Can you add a molar ratio to radians?

        Dimensions are a matter of what distinctions you choose to make. To make radians not dimensionless, you need to accept that “lengths of straight line segments” and “lengths of circle arcs” are fundamentally different things.

        If your physical problems are such that the geometric constructions in it can be carried the Ancient Greek way, the distinction between “constructible straight line distance” and “constructible angle” will be as clear as daylight.

      2. 2

        This was fascinating, thank you. I am a novice to Rust, but I could just about follow along the examples. It was interesting to see the edges of what you can achieve in this area with Rust. I would love to see someone demonstrate this in something like Haskell or Idris.

        1. 2

          There was a presentation on CppCon about A C++ Approach to Physical Units.

          That’s not rust, but at least I find it enlightening to take a peek at how other languages handle similar problems.