Post date: Nov 26, 2019 1:44:19 AM
It is absurd for software to insist that human users translate the numerical values they must enter from the units in which they were originally measured to match the options set by the programmer. Doing so is unfriendly, and it is bad practice generally because it masks the inherent uncertainty in entered values that may be expressed in significant digits. Much more importantly—and much worse—forcing humans conform to the machine invites errors because the translations can be tricky and are hard to error-check.
Dimensional errors are profound errors, akin to adding apples and oranges, or meters to seconds, that typically render the calculation (and perhaps even the argument) gibberish. Unit errors not profound in the same way, but they can still be catastrophic. Famously, the Mars Climate Orbiter was lost because NASA's different contractors used different units and the conversion between them was not handled by the software interface. Even exclusively using SI cannot avoid such problems (e.g., mixing CGS vs. MKS units). Such errors are ubiquitous in quantitative work. For instance, casual review of an EPA document that had already undergone both peer review and public comment revealed fundamental dimensional errors in 2 of the 4 central equations.
Loehle (1991), Hart (1995), Kennedy (1996), and Ferson (2001), among many others, argued there is a clear need for automatic checking by computer. It seems also clear that automated correction could also be helpful. Surprisingly, with the exception of F# and Frink and some awkward libraries for Matlab and Python, almost no programming languages or software packages offer helpful features. Matlab’s are poor, although there are some useful libraries in Python, although the syntax they require can be a bit clumsy. We have software, already implemented in Risk Calc, RAMAS Ecotoxicology, and other commercial software, that can properly handle units and unit conversions across .
More interestingly, it is not terribly hard to define a computer language that understands and handles units. We did this with the Risk Calc scripting languages where it is a very natural extension of current common practice throughout the sciences and engineering disciplines. It is a wonder that programmers have not always insisted that their languages be aware of units and dimensions and automatically handle rote but critical unit checking and units conversion when necessary.
// Risk Calc can handle units too
3 ft + 2 m
2.9144 m
[2,3] meters + 11 feet
[ 17.561, 20.843] feet
2 m * 5.1 kg / 0.002 sec2 + 3.4 N
5103.4 N
1 widget + 2 widgets
3 widgets
2 pears + 3 apples
Units Problem: pear and apple don't conform
References
Eliasen, Alan (n.d.). "Frink". [blog] http://futureboy.us/frinkdocs/
Ferson, Scott (2001). Checking for errors in calculations and software: dimensional balance and conformance of units. Accountability in Research: Policies and Quality Assurance 8:261-279. [attached below]
George W. Hart (1995). Multidimensional Analysis: Algebras and Systems for Science and Engineering, Springer Verlag. [see https://www.georgehart.com/research/multanal.html]
Kennedy, A.J. (1996). Programming Languages and Dimensions. PhD thesis, Cambridge University.
Kitchin, John (2013). "Using units in [P]ython", The Kitchin Research Group: Chemical Engineering at Carnegie Mellon University [blog]. https://kitchingroup.cheme.cmu.edu/blog/2013/01/19/Using-units-in-python/
Madura, Jeffrey D. (1992). Software review: Dimensional Reasoner. Computational Biology and Chemistry 16.
Software Programs, Computer Languages, and Libraries
Dimensional Reasoner: Loehle, Craig (1991) Dimensional Reasoner (https://www.sciencedirect.com/science/article/abs/pii/0097848592800599?via%3Dihub)
F# (programming language syntax)
Frink programming language [http://futureboy.us/frinkdocs/]
Matlab library: http://matlab.cheme.cmu.edu/2011/08/05/using-cmu-units-in-matlab-for-basic-calculations/
Python libraries: SymPy, Pypi, Quantities, Unum, SimTK, SciMath
RAMAS Risk Calc: Ferson, Scott (2002). RAMAS Risk Calc 4.0: Risk Assessment with Uncertain Numbers. CRC Press. [RAMAS Risk Calc]
SCIMAX (software for writing scientific reports): https://engineering.cmu.edu/news-events/news/2019/11/21-scimax.html
"I think an essential feature in an engineering computational environment is properly handling units and unit conversions."
-John Kitchin