Units and Quantities
The Compute Engine supports physical units and quantities. You can parse LaTeX expressions with units, perform arithmetic on quantities, convert between units, and check dimensional compatibility.
Quick Start
Creating Quantities
A quantity pairs a numeric value with a unit. Use the Quantity function in
MathJSON:
["Quantity", 3.5, "m"]
["Quantity", 100, "km"]
["Quantity", 9.8, ["Divide", "m", ["Power", "s", 2]]]
Simple Units
Simple units use standard SI abbreviations as strings:
"m", "kg", "s", "A", "K", "mol", "cd"
Prefixed units are also single strings:
"km", "mg", "ns", "GHz", "kN"
Compound Units
Compound units are built with Multiply, Divide, and Power:
["Divide", "m", "s"] // velocity (m/s)
["Divide", "m", ["Power", "s", 2]] // acceleration (m/s^2)
["Multiply", "kg", "m", ["Power", "s", -2]] // force (N)
DSL String Shorthand
For convenience, compound units can also be written as strings using a simple DSL syntax. The string is automatically parsed into the structured form during canonicalization:
["Quantity", 9.8, "m/s^2"]
// canonicalizes to:
["Quantity", 9.8, ["Divide", "m", ["Power", "s", 2]]]
The DSL supports:
/for division:m/s^for exponents:s^-2*for multiplication:kg*m(...)for grouping:kg/(m*s^2)- SI prefixes:
km/h
"ms" is always parsed as the prefixed unit millisecond, not meter times
second. Use "m*s" for the product.
Parsing LaTeX with Units
The engine recognizes units inside \mathrm{...} and \text{...} when they
appear next to a number:
siunitx Commands
The siunitx LaTeX package commands are also supported:
Serialization
Quantities serialize back to LaTeX with a thin space and upright unit:
Arithmetic on Quantities
Addition and Subtraction
Operands must have compatible dimensions. The result is expressed in the unit with the largest scale factor:
Adding quantities with incompatible dimensions (e.g., meters + seconds) returns the expression unevaluated.
Multiplication and Division
Units combine when multiplying or dividing quantities:
Scalar multiplication works naturally:
Exponentiation
The unit is raised to the power:
Unit Conversion
Use UnitConvert to convert a quantity to a different compatible unit:
Compound unit conversion is also supported:
Temperature Conversion
Temperature units (degC, degF, K) use affine conversions that correctly
handle the offset between scales:
Converting incompatible units returns an Error expression:
Unit Simplification
UnitSimplify reduces a compound unit to a named derived unit when one exists:
If no simpler named form exists, the quantity is returned unchanged.
Dimensional Analysis
Checking Compatibility
Use IsCompatibleUnit to test whether two units have the same dimension.
Both simple and compound unit expressions are supported:
Dimension Vectors
Every unit maps to a 7-element dimension vector over the SI base dimensions:
[length, mass, time, current, temperature, amount, luminosity].
Use UnitDimension to retrieve it. Both simple symbols and compound
expressions are supported:
Angular Units and Trigonometry
Trigonometric functions accept Quantity arguments with angular units. The
angle is automatically converted to radians before evaluation:
Supported angular units: deg, rad, grad, turn, arcmin, arcsec.
Degrees-Minutes-Seconds (DMS) Notation
Geographic coordinates and angular measurements are often written in
degrees-minutes-seconds notation. The engine parses DMS notation when
arc-minute (') and arc-second (") symbols appear after a degree symbol:
The ' and " symbols are only interpreted as arc-minutes and arc-seconds
when they immediately follow a degree value. In other contexts, they retain
their usual meaning (e.g., prime/derivative notation).
DMS expressions canonicalize to a single angle value, so arithmetic works naturally:
Physics Constants
The physics library (loaded by default) provides physical constants as
Quantity expressions:
| Symbol | Value | Unit |
|---|---|---|
SpeedOfLight | 299792458 | m/s |
PlanckConstant | 6.62607015e-34 | J s |
Mu0 (Vacuum permeability) | 1.25663706212e-6 | N/A^2 |
StandardGravity | 9.80665 | m/s^2 |
ElementaryCharge | 1.602176634e-19 | C |
BoltzmannConstant | 1.380649e-23 | J/K |
AvogadroConstant | 6.02214076e23 | mol^-1 |
VacuumPermittivity | 8.8541878128e-12 | F/m |
GravitationalConstant | 6.67430e-11 | m^3/(kg s^2) |
StefanBoltzmannConstant | 5.670374419e-8 | W/(m^2 K^4) |
GasConstant | 8.314462618 | J/(mol K) |
Supported Units
SI Base Units
m, kg, s, A, K, mol, cd
Named Derived SI Units
Hz, N, Pa, J, W, C, V, F, ohm, S, Wb, T, H, lm,
lx, Bq, Gy, Sv, kat
SI Prefixes
All SI prefixes from quetta (10^30) to quecto (10^-30) are supported on base
and named derived units. For example: km, mg, GHz, kN, nA.
Non-SI Units
Time: min, h, d | Length: in, ft, mi, au |
Mass: t, lb, oz, Da | Volume: L, gal |
Energy: eV, cal, kWh | Pressure: atm, bar |
Area: ha | Temperature: degC, degF |
Angle: deg, rad, grad, turn, arcmin, arcsec |
Other: percent, ppm, dB, Np