Math functions over quantities and intervals — the ones that carry dimensions.
(require '[commensura.math :as m]) (m/sqrt (c/pow (u/meter 1) 2)) ;=> 1 meter (exact when a perfect root) (m/abs (u/meter -5)) ;=> 5 meter (m/min (u/foot 1) (u/inch 6)) ;=> 6 inch (physical order, keeps the unit) (m/mod (u/hour 25) (u/hour 24));=> 1 hour
Only functions that touch dimensions live here — preserving them (abs/mod/min/max/
floor/ceil/round), scaling them (sqrt/root), or crossing the boundary (sign:
dimensioned → dimensionless). Raising to a power is a core verb (commensura.core/pow), which
sqrt/root are built on. Transcendentals (exp/ln/sin/…) are intentionally absent: they only
ever map dimensionless → dimensionless, so they belong to plain numeric code.
Over intervals, the monotone functions lift by mapping the endpoints — sign/floor/ceil/round
directly, abs with a special case when the interval spans zero — and sqrt/root scale through. mod/rem are the exception: scalar-only, and they reject an interval argument, because
modular reduction is discontinuous and cannot be soundly lifted ([23,25] mod 24 is {23} ∪ [0,1],
not a single interval). Names shadow clojure.core, so use this namespace qualified (m/abs), never
:refer. Comparisons come from commensura.core.
Math functions over quantities and intervals — the ones that *carry dimensions*.
(require '[commensura.math :as m])
(m/sqrt (c/pow (u/meter 1) 2)) ;=> 1 meter (exact when a perfect root)
(m/abs (u/meter -5)) ;=> 5 meter
(m/min (u/foot 1) (u/inch 6)) ;=> 6 inch (physical order, keeps the unit)
(m/mod (u/hour 25) (u/hour 24));=> 1 hour
Only functions that touch dimensions live here — preserving them (`abs`/`mod`/`min`/`max`/
`floor`/`ceil`/`round`), scaling them (`sqrt`/`root`), or crossing the boundary (`sign`:
dimensioned → dimensionless). Raising to a power is a core verb (`commensura.core/pow`), which
`sqrt`/`root` are built on. Transcendentals (`exp`/`ln`/`sin`/…) are intentionally absent: they only
ever map dimensionless → dimensionless, so they belong to plain numeric code.
Over intervals, the monotone functions lift by mapping the endpoints — `sign`/`floor`/`ceil`/`round`
directly, `abs` with a special case when the interval spans zero — and `sqrt`/`root` scale through. `mod`/`rem` are the exception: **scalar-only, and they reject an interval argument**, because
modular reduction is discontinuous and cannot be soundly lifted (`[23,25] mod 24` is `{23} ∪ [0,1]`,
not a single interval). Names shadow `clojure.core`, so use this namespace qualified (`m/abs`), never
`:refer`. Comparisons come from `commensura.core`.(abs x)Absolute value; dimension-preserving. Over a zero-spanning interval the lower bound is 0; on an Uncertain, |value| carries the spread unchanged.
Absolute value; dimension-preserving. Over a zero-spanning interval the lower bound is 0; on an Uncertain, |value| carries the spread unchanged.
(ceil x)Smallest integer ≥ x, in x's unit. On an Uncertain, rounds the central value and keeps the spread.
Smallest integer ≥ x, in x's unit. On an Uncertain, rounds the central value and keeps the spread.
(floor x)Largest integer ≤ x, in x's unit. On an Uncertain, rounds the central value and keeps the spread.
Largest integer ≤ x, in x's unit. On an Uncertain, rounds the central value and keeps the spread.
(max x)(max x y)(max x y & more)The physically larger value (variadic); keeps the winner's unit (and, for an Uncertain, its σ). Conforming.
The physically larger value (variadic); keeps the winner's unit (and, for an Uncertain, its σ). Conforming.
(min x)(min x y)(min x y & more)The physically smaller value (variadic); keeps the winner's unit (and, for an Uncertain, its σ). Conforming.
The physically smaller value (variadic); keeps the winner's unit (and, for an Uncertain, its σ). Conforming.
(mod x y)x modulo y — conforming, dimension-preserving (keeps x's unit). Scalar-only: an interval or uncertain argument is rejected (modular reduction is discontinuous, so it cannot be soundly lifted).
x modulo y — conforming, dimension-preserving (keeps x's unit). Scalar-only: an interval or uncertain argument is rejected (modular reduction is discontinuous, so it cannot be soundly lifted).
(rem x y)Remainder of x by y — conforming, dimension-preserving. Scalar-only: an interval or uncertain
argument is rejected (see mod).
Remainder of x by y — conforming, dimension-preserving. Scalar-only: an interval or uncertain argument is rejected (see `mod`).
(round x)Nearest integer (half → +∞), in x's unit. On an Uncertain, rounds the central value, keeping σ.
Nearest integer (half → +∞), in x's unit. On an Uncertain, rounds the central value, keeping σ.
(sign x)Sign of a value: a plain -1, 0, or 1, for a value of any dimension. On an Uncertain, the sign of the central value (the spread does not carry — this is a classification, not a measurement).
Sign of a value: a plain -1, 0, or 1, for a value of any dimension. On an Uncertain, the sign of the central value (the spread does not carry — this is a classification, not a measurement).
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |