Architecture for software-assisted quantity calculus☆
Introduction
In the scientific conventions of the early 19th century, mathematical operations applied only to numbers, and units of measure were just information that described what the numbers represented. This belief gave way to the practice of including units of measure within the scope of the mathematical operations, thereby formalizing the method of working with combinations of units. The resulting quantity calculus methodically determines the units of derived quantities and protects us from the error of computing nonsensical combinations of quantities that have different dimensions [2]. For example, if a property line is moved by 3 m, we are allowed to add 3 m to the width of the lot, but we cannot add 3 m to the lot size that is measured in m2. We must multiply 3 m by the depth of the lot (x m) to obtain the change to the lot size (3x m2).
Many software libraries and packages that implement “quantities and units” (Q&U) functions are available; for example:1
- •
Mathematica, quantities and units in the Wolfram language [3];
- •
Maxima package ezunits [4];
- •
Modelica, physical variables and SIunits library [5];
- •
LabVIEW unit labels [6];
- •
MathCad units [7];
- •
GNU Units [8];
- •
UDUNITS [9];
- •
R packages for units of measure (e.g., units and udunits2 [10]);
- •
Ruby gems for units of measure (e.g., ruby-units [11], phys-units [12], and unitwise [13]; there are at least 10);
- •
C++ libraries for units of measure (e.g., Boost.Units [14]);
- •
F# units of measure (a built-in language feature) [15];
- •
Python package numericalunits [16]; and
- •
Julia packages SIUnit [17] and Unitful [18].
A comparable number of formal models and ontologies related to quantities and units exist; for example:
- •
Conceptual model of the International Vocabulary of Metrology (VIM) [19, Annex A];
- •
Dybkaer’s Ontology on Property [20];
- •
Unified Code for Units of Measure (UCUM) [21];
- •
Quantities and Units of Measure Ontology Standard (QUOMOS) [22];
- •
Units Markup Language (UnitsML) [23];
- •
Quantities, Units, Dimensions, and Data Types Ontologies (QUDT) [24];
- •
Quantities, Units, Dimensions, Values (QUDV) in Systems Modeling Language (SysML) [25]; and
- •
Ontology of units of Measure and related concepts (OM) [26].
Although all of the above libraries, packages, models, and ontologies begin with the International System of Units (SI) [27] and associated practices, they differ in how they address issues such as ad hoc counting units, ratios of two quantities of the same kind, and uncertainty. These issues and others that have undermined the functionality and consistency of software for metrology have been discussed in related work [7], [28].
This article describes an architecture that addresses the complete set of functions for Q&U software in a simple and consistent fashion. The goal is not to produce yet another implementation or framework to compete in an already overcrowded arena, but to identify the major architectural features that have proven to be important or sorely needed in this author’s experience, and thereby encourage more convergent thinking and improved compatibility among different implementations in the future.
The building blocks of the architecture are:
- •
A catalog of recognized units and numerical prefixes;
- •
Values (in the measurement sense), including derived values and compound values;
- •
Probability distributions to characterize uncertain values, with automated propagation of distributions to derived values; and
- •
An extensible type system for specializations of the SI unit 1.
Section 2 through Section 5 address each of these in turn. Additional recommendations concerning numeric data types are given in Section 6. Section 7 summarizes.
Section snippets
Units
Quite simply, one cannot begin to implement quantity calculus without first having a catalog of units that the software will recognize and refer to. We need not belabor the point, but all Q&U software must at least recognize the standard base units, derived units, and numerical prefixes (k, M, etc.) that are identified in the SI brochure [27] and be capable of converting “non-coherent” units to their standard equivalents.
Values
The following terms are defined by the 3rd edition of the VIM [19].
quantity: property of a phenomenon, body, or substance, where the property has a magnitude that can be expressed as a number and a reference.
[The “reference” is typically an expression in terms of SI units.]
quantity value: number and reference together expressing magnitude of a quantity.
measurement result: set of quantity values being attributed to a measurand together with any other available relevant information.
[The “set of
Characterizing and propagating uncertainty
Uncertainty too often is completely ignored or is handled in a limited way in available Q&U software.
Expressing uncertainty using standard deviations and multiples thereof involves simplifying assumptions that are unnecessary when quantity calculus is automated. The more general approach is to propagate probability distributions (see Figure 2) [29], [30]. Probability distributions replace both a point estimate and its standard uncertainty. They may be continuous (for dimensional quantities and
Subtyping unit 1
A quantity in SI can be stated as the product of a numerical value and a unit of measurement. The unit is derived from the seven SI base quantities, which measure seven different physical dimensions. However, many kinds of quantities have no extent in any of those dimensions. For example, a counted quantity is a number of some distinguishable kind of thing, such as 32 bits. Ratios of two quantities of the same kind, such as mass fractions (kg/kg), are in another major category of dimensionless
Numeric data types
It is unfortunately common in scientific applications for all numeric values to be represented using floating-point numbers as the catch-all data type. While additional numeric types and arbitrary-precision arithmetic are widely implemented, their integration with scientific applications in general and quantity calculus in particular is inconsistent.
In addition to the basic types of floating point, signed integer, and unsigned integer, the following constructed types are frequently useful:
- •
Conclusion
This short article described an architecture that addresses the complete set of functions for quantities and units in a simple and consistent fashion. Hopefully, this will encourage more convergent thinking about the functions and the underlying concepts so that the many disparate software implementations, present and future, will become more consistent with one another.
Acknowledgments
Thanks to Raghu Kacker, Paul Black, Barbara Guttman, Antonio Possolo, and CS&I reviewers for helpful review comments and suggestions.
Funding for the preparation of this article was provided by NIST.
References (37)
Computing numerically with functions instead of numbers
Communications of the ACM
(2015)- J. Kogan, An alternative path to a new SI, Part 1: On quantities with dimension one, 2014....
Architecture for Software-Assisted Quantity Calculus
NIST Technical Note 1943
(2016)On the history of quantity calculus and the international system
Metrologia
(1995)- Units—Wolfram language documentation, 2017....
- Ezunits, in Maxima 5.40.0 manual, 2017,...
- Modelica SIunits library, 2009,...
- Available units in LabVIEW—LabVIEW 2016 help, 2016....
- et al.
Physical quantities, dimensions and units in mathematical packages
Mathematical Machines and Systems
(2009) - GNU Units, 2017,...