Post AkQGN404wpkTC5uU52 by danderson@hachyderm.io
(DIR) More posts by danderson@hachyderm.io
(DIR) Post #AkQGMwcmN3x4JnxHI8 by danderson@hachyderm.io
2024-07-29T02:16:29Z
1 likes, 0 repeats
A thing I love about Common Lisp, is the history. Looking at a library that handles unit conversions and dimensional analysis. In its file comments, it notes:Ported from a 1982 Interlisp library. Ported in 1990 to GLISP, an AI research language.In 1993, its canonical internal representation of units switched from MKS to SI.Since then, it's had a couple small edits every few years, but not much change needed, really. Recognizably still the same as it was 30 years ago, still works fine.
(DIR) Post #AkQGN0LCYMGfqRlIRs by danderson@hachyderm.io
2024-07-29T02:20:42Z
1 likes, 0 repeats
CL is full of things like this, bits of code that sure, could be modernized a bit or adjusted a little for current day computers... But are pretty much Done and don't really need to change, because they solved the problem they set out to solve, and the solution is timeless, other than adjusting definitions to account for once in a lifetime events like the kilogram getting redefined in 2019.And it still seems to handle unit math better than current day contenders too, afaict
(DIR) Post #AkQGN404wpkTC5uU52 by danderson@hachyderm.io
2024-07-29T02:27:51Z
1 likes, 0 repeats
There was that whole kerfuffle in some OSS project that does unit conversions, about how one of the units was defined according to its colloquial usage, instead of the strictly correct derivation. This library gives the example of using "pounds" as a unit of force, which is commonly done even though strictly speaking the correct unit is pounds-force, or describing mass in electronvolts, which is not a unit of mass.There are fanatical supporters of either approach, it seems.
(DIR) Post #AkQGN7hnAlUugXNw8G by danderson@hachyderm.io
2024-07-29T02:32:20Z
1 likes, 0 repeats
This library not only acknowledges this, at least as early as 1993, but also offers a trivial solution: it observes that the imprecise language arises due to two factors: conflation of mass and weight in standard Earth gravity, and mass-energy equivalence off of the famous equation.So, it lets you pick! You can just tell it whether you want strict unit handling, or if it should scale things by 9.8m/s² or by c² as needed to make the dimensional analysis work.
(DIR) Post #AkQGNBUT6FDUQNBLv6 by danderson@hachyderm.io
2024-07-29T02:35:31Z
1 likes, 0 repeats
And if you tell it to be flexible, it only does that _when the dimensional analysis requires it_. It encodes dimensions such that if you tell it to convert between two units, it can quickly verify that they are cromulent with each other modulo a scale factor. If they are not, it knows exactly what dimensions are off, and both mass-weight and mass-energy mismatches have distinct, recognizable signatures. So the code can go "ah, you must be a physicist, sure, GeVs can be grams, here you go"
(DIR) Post #AkQGNFFj6znk5oJdUu by danderson@hachyderm.io
2024-07-29T02:38:45Z
1 likes, 0 repeats
To be clear none of this is groundbreaking math or anything, the paper associated with this library was published in 1993, and it appears to be a run-through of code that existed for at least a decade prior. Unit conversion and dimensional analysis are very solved things.... and yet software today still gets it wrong enough to have flamewars, or to go "I'm sorry, attoparsecs per microfortnight into inches per second is just complex enough that I won't bother, please ask simpler questions."
(DIR) Post #AkQGNIwNOshRWxIEtM by danderson@hachyderm.io
2024-07-29T02:41:38Z
1 likes, 0 repeats
I dunno, it's hard to explain, but reading code like this feels good. It won't win beauty awards, someone writing modern Common Lisp probably wouldn't do it this way... But does it matter? Thirty years ago, it comprehensively solved the problem it set out to solve, and still works the same today.It's a warm fuzzy feeling to encounter software that is Done, and doesn't immediately bitrot because the entire universe around it gets rewritten from scratch every two years.
(DIR) Post #AkQGNMB1MtCFZFATdQ by danderson@hachyderm.io
2024-07-29T02:52:50Z
1 likes, 0 repeats
Anyway, https://www.cs.utexas.edu/~novak/units.html is neat. It even has a companion paper that goes through its design, and how it handles some stuff like dimensional analysis and unit simplification that biases towards a chosen system of units. It's neat.If you were redoing it today, I think possibly the things you'd change would be maybe compute all the scaling factors as rational fractions when possible (it's become cheap to do), and maybe change the dimensional analysis encoding slightly? But also, eeeh.