Skip to main content

Units and Quantities

The Compute Engine provides a unit system for representing and computing with physical quantities. Units are organized around SI base dimensions with support for derived, prefixed, and non-SI units.

Quantity​

Quantity(magnitude, unit)

A value paired with a physical unit.

The magnitude is any numeric expression. The unit is a unit symbol (string) or a compound unit expression built from Multiply, Divide, and Power.

9.8\,\mathrm{m/s^{2}}
$$$9.8\,\mathrm{m/s^{2}}$$
["Quantity", 3.5, "m"]
// A simple quantity: 3.5 meters

["Quantity", 9.8, ["Divide", "m", ["Power", "s", 2]]]
// A compound unit: 9.8 m/s^2

["Quantity", 100, "km"]
// Prefixed unit: 100 kilometers

A DSL string shorthand is accepted for compound units and canonicalized to the structured form:

["Quantity", 9.8, "m/s^2"]
// → ["Quantity", 9.8, ["Divide", "m", ["Power", "s", 2]]]

["Quantity", 1, "kg/(m*s^2)"]
// → ["Quantity", 1, ["Divide", "kg", ["Multiply", "m", ["Power", "s", 2]]]]

Arithmetic on quantities:

Add and Subtract require compatible dimensions and express the result in the unit with the largest scale factor:

["Add", ["Quantity", 12, "cm"], ["Quantity", 1, "m"]]
// → ["Quantity", 1.12, "m"]

Multiply and Divide combine units, cancelling common unit symbols structurally (a repeated unit cancels exactly, with no conversion factor):

["Multiply", ["Quantity", 5, "m"], ["Quantity", 3, "s"]]
// → ["Quantity", 15, ["Multiply", "m", "s"]]

["Divide", ["Quantity", 18, "in"], ["Quantity", 12, ["Divide", "in", "ft"]]]
// → ["Quantity", 1.5, "ft"]

Power raises the unit to the exponent:

["Power", ["Quantity", 3, "m"], 2]
// → ["Quantity", 9, ["Power", "m", 2]]

QuantityMagnitude​

QuantityMagnitude(quantity)

Extract the numeric magnitude from a Quantity expression.

["QuantityMagnitude", ["Quantity", 3.5, "m"]]
// → 3.5

QuantityUnit​

QuantityUnit(quantity)

Extract the unit expression from a Quantity.

["QuantityUnit", ["Quantity", 3.5, "m"]]
// → "m"

["QuantityUnit", ["Quantity", 9.8, ["Divide", "m", ["Power", "s", 2]]]]
// → ["Divide", "m", ["Power", "s", 2]]

UnitConvert​

UnitConvert(quantity, target-unit)

Convert a quantity to a different compatible unit. The target can be a simple unit symbol or a compound unit expression.

Returns the converted Quantity, or an Error if the units are incompatible.

Supports affine temperature conversions (degC, degF, K).

["UnitConvert", ["Quantity", 1500, "m"], "km"]
// → ["Quantity", 1.5, "km"]

["UnitConvert", ["Quantity", 180, "deg"], "rad"]
// → ["Quantity", 3.14159..., "rad"]

["UnitConvert",
["Quantity", 36, ["Divide", "km", "h"]],
["Divide", "m", "s"]]
// → ["Quantity", 10, ["Divide", "m", "s"]]

["UnitConvert", ["Quantity", 100, "degC"], "degF"]
// → ["Quantity", 212, "degF"]

["UnitConvert", ["Quantity", 5, "m"], "s"]
// → Error (incompatible dimensions)

UnitSimplify​

UnitSimplify(quantity)

Reduce a compound unit to a named derived SI unit if one matches the dimension and has scale factor 1.

["UnitSimplify",
["Quantity", 100, ["Multiply", "kg", "m", ["Power", "s", -2]]]]
// → ["Quantity", 100, "N"]

If no simpler named form exists, the quantity is returned unchanged.

IsCompatibleUnit​

IsCompatibleUnit(unit-a, unit-b)

Test whether two units have the same dimension vector. Returns True or False. Both simple unit symbols and compound unit expressions are accepted.

["IsCompatibleUnit", "m", "km"]
// → True

["IsCompatibleUnit", "m", "s"]
// → False

["IsCompatibleUnit", "J", "eV"]
// → True

["IsCompatibleUnit", ["Divide", "m", "s"], ["Divide", "km", "h"]]
// → True

UnitDimension​

UnitDimension(unit)

Return the 7-element dimension vector of a unit. The vector encodes the exponents of the SI base dimensions: [length, mass, time, current, temperature, amount, luminosity].

Both simple unit symbols and compound unit expressions are accepted.

["UnitDimension", "m"]
// → [1, 0, 0, 0, 0, 0, 0]

["UnitDimension", "N"]
// → [1, 1, -2, 0, 0, 0, 0]

["UnitDimension", "V"]
// → [2, 1, -3, -1, 0, 0, 0]

["UnitDimension", ["Divide", "m", ["Power", "s", 2]]]
// → [1, 0, -2, 0, 0, 0, 0]

Physics Constants​

The physics library provides physical constants as Quantity expressions. These constants use the 2018 CODATA recommended values.

SymbolValueUnitDescription
SpeedOfLight299792458m/sSpeed of light in vacuum
PlanckConstant6.62607015e-34J sPlanck constant
Mu01.25663706212e-6N/A^2Vacuum permeability
StandardGravity9.80665m/s^2Standard acceleration due to gravity
ElementaryCharge1.602176634e-19CElementary charge
BoltzmannConstant1.380649e-23J/KBoltzmann constant
AvogadroConstant6.02214076e23mol^-1Avogadro constant
VacuumPermittivity8.8541878128e-12F/mVacuum permittivity
GravitationalConstant6.67430e-11m^3/(kg s^2)Gravitational constant
StefanBoltzmannConstant5.670374419e-8W/(m^2 K^4)Stefan-Boltzmann constant
GasConstant8.314462618J/(mol K)Molar gas constant
\mu_0
$$$\mu_0$$

The vacuum permeability constant Mu0 can be entered in LaTeX as \mu_0.

\varepsilon_0
$$$\varepsilon_0$$

The vacuum permittivity constant VacuumPermittivity can be entered in LaTeX as \varepsilon_0.

Supported Units​

SI Base Units​

SymbolQuantityName
mLengthmeter
kgMasskilogram
sTimesecond
AElectric currentampere
KTemperaturekelvin
molAmount of substancemole
cdLuminous intensitycandela

Named Derived SI Units​

SymbolQuantityNameIn base units
HzFrequencyhertzs^-1
NForcenewtonkg m s^-2
PaPressurepascalkg m^-1 s^-2
JEnergyjoulekg m^2 s^-2
WPowerwattkg m^2 s^-3
CElectric chargecoulombA s
VVoltagevoltkg m^2 s^-3 A^-1
FCapacitancefaradkg^-1 m^-2 s^4 A^2
ohmResistanceohmkg m^2 s^-3 A^-2
SConductancesiemenskg^-1 m^-2 s^3 A^2
WbMagnetic fluxweberkg m^2 s^-2 A^-1
TMagnetic flux densityteslakg s^-2 A^-1
HInductancehenrykg m^2 s^-2 A^-2
lmLuminous fluxlumencd
lxIlluminanceluxcd m^-2
BqRadioactivitybecquerels^-1
GyAbsorbed dosegraym^2 s^-2
SvEquivalent dosesievertm^2 s^-2
katCatalytic activitykatalmol s^-1

SI Prefixes​

All SI prefixes are supported on base and named derived units:

PrefixSymbolFactor
quettaQ10^30
ronnaR10^27
yottaY10^24
zettaZ10^21
exaE10^18
petaP10^15
teraT10^12
gigaG10^9
megaM10^6
kilok10^3
hectoh10^2
decada10^1
PrefixSymbolFactor
decid10^-1
centic10^-2
millim10^-3
microu10^-6
nanon10^-9
picop10^-12
femtof10^-15
attoa10^-18
zeptoz10^-21
yoctoy10^-24
rontor10^-27
quectoq10^-30
Note

Prefixes are applicable to all base and derived units except kg. Use g as the base for mass prefixing: mg, ug, etc.

Non-SI Units​

SymbolQuantitySI Equivalent
minTime60 s
hTime3600 s
dTime86400 s
haArea10^4 m^2
LVolume10^-3 m^3
tMass10^3 kg
eVEnergy1.602176634e-19 J
DaMass1.66053906660e-27 kg
auLength1.495978707e11 m
inLength0.0254 m
ftLength0.3048 m
miLength1609.344 m
lbMass0.45359237 kg
ozMass0.028349523125 kg
galVolume3.785411784e-3 m^3
atmPressure101325 Pa
barPressure10^5 Pa
calEnergy4.184 J
kWhEnergy3.6e6 J
degCTemperatureK - 273.15
degFTemperature(K - 459.67) x 5/9
Note

degC and degF use affine conversions (offset + scale), not just linear scaling. UnitConvert handles these correctly.

Angular Units​

SymbolNameIn radians
radradian1
degdegreepi/180
gradgradianpi/200
turnturn2 pi
arcminarcminutepi/10800
arcsecarcsecondpi/648000

Angular units are dimensionless. Trigonometric functions (Sin, Cos, Tan, etc.) automatically convert Quantity arguments with angular units to radians.

Dimensionless Units​

SymbolScale factor
percent0.01
ppm10^-6
dB1 (nominal)
Np1 (nominal)
Note

Logarithmic units (dB, Np) are parsed and stored but conversion between logarithmic and linear scales is not supported in v1.

LaTeX Parsing​

Supported Input Forms​

LaTeXMathJSON
5\,\mathrm{m}["Quantity", 5, "m"]
3\,\text{kg}["Quantity", 3, "kg"]
9.8\,\mathrm{m/s^{2}}["Quantity", 9.8, ["Divide", "m", ["Power", "s", 2]]]
\qty{12}{cm}["Quantity", 12, "cm"]
\SI{5}{kg}["Quantity", 5, "kg"]
\unit{m/s}["Divide", "m", "s"]
\si{MHz}"MHz"
9°30'15"["Add", ["Quantity", 9, "deg"], ["Quantity", 30, "arcmin"], ["Quantity", 15, "arcsec"]]
9°30'["Add", ["Quantity", 9, "deg"], ["Quantity", 30, "arcmin"]]

Unit Parsing Rules​

Within \mathrm{...} or \text{...}, the parser interprets:

  • / as division
  • ^ and ^{...} as exponents
  • \cdot as multiplication
  • Juxtaposed symbols as individual units or prefixed units