Mirror of the Rel4tion website/wiki source, view at <http://rel4tion.org>
Clone
HTTPS:
git clone https://vervis.peers.community/repos/yEzqv
SSH:
git clone USERNAME@vervis.peers.community:yEzqv
Branches
Tags
measurement-units.mdwn
Purpose
Collect information and ideas, examine, explore, research and design the use of measurement units as parts of values.
Content
What are measurement units? Why are they important?
Example: Assume there’s a Vehicle class and an object my_boat which is a Vehicle. All Vehicles have a property speed, so we need to define it for my_boat. A reasonable way to define it is to use positive real numbers, and use kilometer-per-hour (KPH) or mile-per-hour (MPH) as a measurement unit.
Now assume we have a database describing turtles, and they have a speed too. But they’re so slow, the numbers in KPH and MPH units are tiny. They can be represented in a double, but we’d like to specify them in another unit, e.g. centimeter-per-hour.
Of course it’s possible to choose a single unit and define all speeds using the same unit, while the UI displays speed in the user’s local unit and converts automatically to and from the system speed unit. The problem is that not every number format necessarily can represent well any magnitude. And using a single unit requires the conversion to be done by software: If not supported, the user needs to work with ugly numbers. Also, conversions many cause accuracy loss or even drifts.
Another problem is that giving each property a unit means that each unit we want to use requires its own property. And that’s bad design because speed is speed, regardless of magnitude. So we want to have a single speed property, and be able to use different units attached to numeric values. Therefore a unit is like a coefficient.
Note however that the “whole range” of units in the world and conversions between them doesn’t have to be known to every database, so it is okay to mark a unit with a letter/name and not give universal relative numbers to units. The conversion software may use such numbers, or store them in the database, to make the conversions.
A measurement unit is something we can talk about and say various things, therefore it is worth having as a resource. What we want to say about measurement units:
- Full name (e.g. meter)
- Abbreviation (e.g. m)
- What it measures (e.g. hasSpeed)
- Conversion to other units
We’d also like to work with prefixes, and these can be resources too:
- Full name (e.g. kilo)
- Abbreviation (e.g. k)
- Power (e.g. 3, meaning it multiplies by 10^3)
Some units (e.g. bytes) use prefixes that are not powers of 10 but powers of 2, so also mentioning the base may be useful:
- Base (e.g. 10, because kilo is 10^3)
Now the value of speed for a given object has three components:
- Number
- Unit
- Prefix
If tuples get supported a single value can have all three, but I don’t think it’s good for semantic purposes, unless relations of arbitrary length tuples are introduced (i.e. not just sets of pairs like regular relations, but sets of tuples of other sizes). So let’s assume that tuples are not supported, and 3 triples are required: one to state the property value, and the others match the first triple with its unit and its prefix.
One thing we haven’t handled is conversions: The mathematical model for them if a function taking a number in one unit and applying some math to produce the conversion of it to another unit. The conversion doesn’t have to be a simple multiplication. For example, conversion between Celcius and Farenheit requires several arithmetic operations.
Assume a function would be stored as a string. It’s of course possible to also store a compiled machine-efficient code, but a binary form doesn’t allow to do queries, displaying to user, etc. So assume the function is a string. It can be a simple arithmetic expression or allow some more things, e.g. be a Python function. Then in the mathematical sense, we need a function which matches a pair of units to their conversion functions. Since we assume tuples are not used, these are some ideas:
- Define a conversion function resource and say things about it:
- the function string itself
- a compiled version of the function
- the domain unit
- the range unit
When looking for conversion functions, simply search for a function with the requested domain and range units.
Use a property isConvertibleTo to match a unit to a unit it is convertible to using a conversion function. The use isConvertibleBy to match the last statement with its conversion function.
Match each unit to the conversion functions which can be applied to it. Then, the set of units it is convertible to can be deduced by transitive closure of the functions’ domain and range units.