Wikifunctions:Type proposals/Unit of measurement
Summary
This proposal introduces two new types in order to represent units of measurements (the definition of unitful values is left for a future proposal).
This proposal is meant to compete with Wikifunctions:Type_proposals/SI_units, while still being heavily inspired by it. The main difference between these two models is that this proposal wants to handle all the units at the same time.
While Wikidata quantity (Z6010) is already able to encode quantities, it is not able to encode for all the possible derived units and it is not practical to use for mathematical calculations (mainly due to the fact that the unit is encoded just by a Wikidata reference). This proposal wants to overcome all these difficulties.
Uses
These types should make possible to handle operations with units, like unit conversions and multiplications.
Structure
Unit dimensions
This type encodes for the physical dimensions of a unit. It contains 7 values, all of type Rational number (Z19677), corresponding to the SI fundamental dimensions. Those values represent the exponents of said fundamental dimentions.
Unit of measurement
This type represent a Unit. Assuming it has the ZID "Znnnn", its keys should be:
- ZnnnnK1: "dimension" of type Unit dimensions: encodes for the physical dimension of the physical value represented by the unit
- ZnnnnK2: "conversion to SI" of type Rational number (Z19677): represents the factor to use to convert this unit to the corresponding SI unit with the same dimensions
- ZnnnnK3: "offset with SI" of type Rational number (Z19677): represents the offset (in SI units) between this unit 0 and the SI unit 0. This value is included mainly to properly handle temperature units.
- ZnnnnK4: "Wikidata representation" of type list of pairs of Wikidata item reference (Z6091) and Rational number (Z19677): contains the units that compose this unit, with the first element of the pair being the reference to the Wikidata item representing the unit, and the second element representing the exponent said unit must be raised to. All the units of the list should be multiplied to obtain the unit represented by the entire type. This is to remember the symbol that should be used to display the unit.
Calling the value in SI unit and the value in the represented unit, the following relation should be valid:
Example values
Unit dimensions
Example: speed
- ZmmmmK1 (time): -1/1
- ZmmmmK2 (length): 1/1
- ZmmmmK3 (mass): 0/1
- ZmmmmK4 (current): 0/1
- ZmmmmK5 (temperature): 0/1
- ZmmmmK6 (luminous intensity): 0/1
- ZmmmmK7 (amount of substance): 0/1
Unit of measurement
Example: miles/minute
- ZnnnnK1 (dimension): Unit dimensions(-1,1,0,0,0,0,0)
- ZnnnnK2 (conversion to SI): 16764/625
- ZnnnnK3 (offset with SI): 0/1
- ZnnnnK4 (Wikidata representation): list:
- pair(mile (Q253276), 1/1)
- pair(minute (Q7727), -1/1)
In alternative:
- pair(mile per minute (Q106611642), 1/1)
Note: in general, multiple values for ZnnnnK4 are possible.
Validator
Unit dimensions
The validator ensures that:
- All the keys are valid
Measurement unit
The validator ensures that:
- All the keys are valid
- The conversion factor with SI is different from 0/1
- All the Wikidata representation exponents are different from 0/1
- The Wikidata representation is made of references to measurement units
- The Wikidata representation is coherent with all the other values
Identity
Unit dimensions
Two unit dimensions are the same if all the values are the same
Measurement unit
Two units are the same if:
- the unit dimensions are the same
- the conversion factors to SI are the same
- the offsets with SI are the same
Considering that the same unit could have different Wikidata representations, the last key shouldn't be considered in the standard comparing function; it is stil possible to implement a stricter equality function (similar to how Rational number (Z19677) has same Rational number (Z19686) as the standard comparing function but same Rational number object (Z19892) still exists).
Converting to code
Python
Unit dimensions
As a dictionary, with the values in keys from K1 to K7.
Measurement unit
As a dictionary, with keys from K1 to K4. The K4 key should be a list of tuples with two values, the first being a string (representing the QID) and the second being a Fraction.
JavaScript
Similar to Python, with Objects instead of dictionaries and with Arrays instead of tuples.
Display function
Measurement unit
Just the symbol (according to the Wikidata representation).
Read function
Measurement unit
Should read the symbol (supporting also exponents, multiplications and divisions of units). It should also accept the QID of the Wikidata item representing the unit.
Alternatives
Support for logarithmic units
To support a logarithmic unit, it would be necessary to only add a key (ZnnnnK5, type of unit) indicating whether it's a logaritmic or a linear unit (possibly a lightweight Wikidata enumeration of linear scale (Q1914828) and logarithmic unit (Q17342348) or logarithmic scale (Q937378)).
In fact, given a logarithmic unit derived from a linear unit , if it's derived from an expression like , it can also be expressed in the form of , with and . For consistency, we should instead express in terms of :
with and .
and could be stored in the fields ZnnnnK3 and ZnnnnK2 respectively, with the convention that is in SI units. ZnnnnK1 would represent the dimentions of the original linear unit , considering that the logaritmic unit itself whould always be adimensional. We should also choose the conventional basis for the logarithm; my proposal would be to choose basis 10, since the most used logarithmic units use basis 10.
For example, the decibel used for sound intensity, given by the formula , with should be represented as:
- ZnnnnK1 (dimensions): Unit dimensions (-3,0,1,0,0,0,0)
- ZnnnnK2 (conversion to SI): 1/10
- ZnnnnK3 (offset with SI): -12/1
- ZnnnnK4 (Wikidata representation): list:
- pair(decibel (Q5329), 1/1)
- ZnnnnK5 (type of unit): logarithmic scale (Q937378)
In alternative, logarithmic units could be a separated type (considering that common operations with linear units, like multiplication and additions of unitful values, are not uniquely defined with logarithmic units).
Comments
For general comments, please reply to the proposer.
Support as proposer. Dv103 (talk) 16:42, 22 June 2025 (UTC)
Uncertain for the logarithmic units, as the proposer. Probably it's better to create a separate type for them, considering that they would be a useless bloat for functions dealing with linear units. Units like decibels would still be able to be represented in the Unit of measurement type as dimensionless units (so that we can also create composite units, like decibel/second, or even decibel/decade). Dv103 (talk) 16:14, 29 July 2025 (UTC)
- Provisional
Support. Thanks for this proposal. I like it a lot. At this stage I even support the logarithmic version. I'll dwell on it for a while longer before removing the "provisional". --99of9 (talk) 07:49, 21 August 2025 (UTC)
Oppose on preference to SI units. I don't think more abstraction is helpful here. Feeglgeef (talk) 14:04, 7 April 2026 (UTC)
Support instead of Wikifunctions:Type_proposals/SI_units --Ameisenigel (talk) 08:15, 12 May 2026 (UTC)