DesignerUnits

One goal in a public release is influence by example. I'd like future software to sport nice measurement units.

A review sequence by depth of interest: overview, worked examples, backgrounder, unit catalogs, QuickStart.nb, and finally DesignerUnits.nb which houses code. Core sections are "Unit Algebra - Productions - Main Algebra" and "Quantity Analysis."

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Same old same old

Though I haven't tried it out, this implementation seems to suffer from the same problem as must "syntactic" units packages since time immemorial. It assumes that because energy and torque have the same units (kg m^2 / s^2) that they are interchangeable. Alas, they are not, because energy is a scalar, torque a vector. Likewise, at a higher level of abstraction, length, width, and height are all measured in meters, but though multiplying them is sensible, adding them is not. Temperatures can be subtracted but not added. And so on.

Creating a units system that can be made to understand all these things is a huge effort, and one that as far as I know has never been done. Still, 0.5 loaf is much better than no bread.

Likewise, at a higher level

Likewise, at a higher level of abstraction, length, width, and height are all measured in meters, but though multiplying them is sensible, adding them is not.

Sure it is, if you're trying to measure a total distance traveled, for instance. The "sensibleness" of an operation is generally domain-specific. A units package should just check that the units are properly propagated and that any unit constraints are satisfied.

Absolute vs. Relative

Temperatures can be subtracted but not added.

Sure it is, if you're trying to measure a total distance traveled

These are actually the same issue, in that some units refer to "absolute" quantities while others refer to offsets from a (potentially implicit) origin. If it's 10C now and 15C later, adding those to get 25C is nonsense; if it was 5C warmer between measurements A and B, and 3C warmer between measurements B and C, adding those to get 8C is sensible. On the other hand, adding temperatures in K is generally reasonable, absolute values less than 0K are usually bogus, but offsets less than 0K are fine.

Distances are always offsets, but the implicit reference point varies, as does the meaning of addition. Adding distances traveled is simple; adding physical sizes of objects may be sensible depending on context; adding positions is likely to be nonsense. Sometimes distances should be seen as vectors, sometimes as scalars, and without context you can't always tell which is which. Yet all of these can be written in units of meters.

Beyond that, some units of measurement are nonlinear (e.g., decibels) or worse. What arithmetic operations make sense on values of the Mohs scale of mineral hardness?

Standard units of measure are, by themselves, massively underspecified, generally relying on human knowledge to supply the elided details. Arbitrary amounts of additional detail could of course be encoded, but at the expense of increasing complexity and burden on the user. An obvious analogy to general type systems for programming languages can be made, but I'll leave it be...

Torsors

Some, not all, of this discrimination can be helped by considering torsors. John Baez has an excellent introduction.

Arbitrary amounts of

Arbitrary amounts of additional detail could of course be encoded, but at the expense of increasing complexity and burden on the user. An obvious analogy to general type systems for programming languages can be made, but I'll leave it be...

Can't leave it be without at least one reference to F#'s support for units of measure.

Admin note

While Mark's past contributions to LtU are appreciated, for future reference, it's not appropriate for a contributing editor to post his own projects to the front page unless invited to do so, as in the case of guest bloggers. Instead, we encourage such entries to be posted as a forum topic, with a clear statement of the poster's own connection to the project.

Distracting

It's no crime even in theory. Story hijack and topic pollution are worse. Private channels exist. To reach editors plural, use a practical venue, not sea burial here.

Since I'm the more veteran editor, let Ehud admin me solo, not as "we" but himself. The tip needs vetting to become a guideline. If written, I never saw it. Repeat odds were nil anyway. A stray breach like that, let pass.

Mark, I am sure Anton was

Mark, I am sure Anton was thinking of items 7 & 8 in the policies document, especially as interpreted in the past. I am sure no offense was meant, and seeing as the topic seems to attract interest, no harm done.

Answers



johnwcowan

Units have subtle issues. Influence by example means handling some in shipping code. I'll check off your list to motivate interest.

There is no syntactic orientation. DsU separates presentation from semantics. A whole machinery serves the purpose. Maybe I miss your meaning.

DsU handles torque vs. energy. Read the backgrounder. The force catalog has a footnote. They differ by angle.

DsU has extension quantities. These carry identical dimensions as the generic, yet remain distinct. Example: volume_beverage extends volume. The notion permits discrimination, where useful, on a different footing than dimension.

Temperature sums work. The relevant catalog tweaks them. Behavior almost matches your spec. It can change to taste. The code is brief, exploiting hooks for custom algebra.

The length-width-height matter is vector analysis. Units live at a lower level, as you say. The upper level rules are plain old vector algebra, not a unit library's job. Interaction bugs would be implementation, not design boundary flaws. Please read my math comments to Casey McCann, too.


naasking

Is something in F# worth comparison or contrast?

Microsoft and Sun have seen my site. Microsoft visits with some regularity. I'm glad to help designers. I'd love to hear from them, even do work. Wolfram Research called with great interest.


Casey McCann

Our ideas seem close. Units as math aren't consistent.

Offset is fundamental. What are called "functional" quantities handle it. The label means they need functions more complicated than a multiply.

Decibels work. The validation suite shows corner cases and varying "meaning[s] of addition" for dB. It ships in the software. The backgrounder touches dB. Weighted flavors like audio need attention.

Interaction between scales and units has puzzles, perhaps. Units make enough work.

The word "underspecified" is mostly math lingo. What it suggests is better guidance outside math, not lost hope. Escape is everything. Guy Steele said units form a group. Only a subset can, if large. General units form a small language with odd rules. Smallness fuels hope. The language outlook drives units in Wolfram|Alpha. And they're a math company...

One veers off the rails conflating math ontologies with units. Points, vectors, scalars, torsors!, lines, origins, frames, distances, groups, and the rest form extensive families. Units aren't relations, just nice neighbors. Call them a language and you're finished with math metaphors.

User burden statements lost me. Encoding helps; that's the point. I want to write units as on paper. The computer should figure things out from its rule base.

Re: F#, I'm not sure what

Re: F#, I'm not sure what the connection to your work is. F#'s history with units of measure dates back to Andrew Kennedy's work on dimension types back in 1994, where he described a type inference extension to ML which can infer and check units.