skoro v0.0.0

Implementation

A crate `skoro-spatial` declaring the unit quaternions, the rigid motions and the extended poses as embedded types with their volumes, and every map of the mathematics as a composite of the core's operations, typed by markers, reached through operators and extension traits, with host helpers for the values a model is given.

Updated 2026-11-14 · 26 min read

Overview#

When this is built, a crate skoro-spatial gives skoro its rotations and rigid motions as the mathematics settles them (The unit quaternions, The rigid motions). Three markers, Rotation, Pose and ExtendedPose, declare the types S3S^3, S3⋉R3S^3 \ltimes \R^3 and S3⋉(R3×R3)S^3 \ltimes (\R^3 \times \R^3), each with its chart (4), its projection and its declared volume, so that a quantity of any of them can be scored by the normal, observed and simulated like any other. Every map of Maps of the rotations and Maps of the rigid motions is a composite of the core’s primitives and selection, reached through operators (* composes, and acts on vectors) and through methods of extension traits on the handles. A model of an attitude integrated from a gyroscope and corrected by a measured direction reads:

use skoro::scope::{constant, quantity};
use skoro::{Real, Vector};
use skoro_normal::{Normal, Scale};
use skoro_spatial::{Rotation, RotationMaps, rotation};

writer.build(|| {
    // The attitude at the last tick, and the body rate integrated over the step.
    let q0 = quantity("q0", Rotation);
    let omega = constant(Vector::<3>, [0.01, -0.02, 0.005]);
    let predicted = q0 * rotation::exp(omega * 0.1);          // q₀ ⊗ Exp(ω Δt)

    // The new attitude, with its noise in its own frame.
    let q1 = quantity("q1", Rotation);
    Normal::on(Rotation, predicted, Scale::sd(0.01)).score(q1);

    // A measured direction of gravity in the body frame: the inverse action.
    let g = constant(Vector::<3>, [0.0, 0.0, -1.0]);
    let a = quantity("a", Vector::<3>);
    Normal::on(Vector::<3>, q1.unrotate(g), Scale::sd(0.05)).score(a);
});

and a pose graph, with odometry in the frame of the pose and a GPS position in a fixed one:

use skoro_spatial::{Pose, PoseMaps, pose};

writer.build(|| {
    let t0 = quantity("t0", Pose);
    let t1 = quantity("t1", Pose);
    let odometry = constant(Pose, ([1.0, 0.0, 0.0, 0.0], [1.0, 0.0, 0.0]));
    Normal::on(Pose, t0 * odometry, Scale::sds(&[0.01, 0.01, 0.01, 0.1, 0.1, 0.1])).score(t1);
    let gps = quantity("gps", Vector::<3>);
    Normal::on(Vector::<3>, t1.position(), Scale::sd(2.0)).score(gps);
});

The crate writes no kernel and no derivative. Each map’s derivatives of both orders are the core’s, by composition, and by Proposition 14 they are the Jacobians of the textbooks. A small host module does on the host, in double precision, what the mathematics leaves to the host: aligning an observed quaternion with its prediction (The double cover), and reading a quaternion off a matrix or Euler angles for a constant.

Constraints#

Read at commit 4239e5c. Each interface below is pasted from the file named, and followed by what the design must do because of it.

Embedded types and their volumes#

crates/skoro-core/src/embedded.rs:

impl Embedded {
    /// `retraction`, `Vector(n)` and `Vector(d)` to `Vector(n)`, is the `R` of the mathematics;
    /// `inverse`, two of `Vector(n)` to `Vector(d)`, its `Q`; `projection`, `Vector(n)` to
    /// `Vector(n)`, its `P`, when the type has one. Any other signature is refused
    /// (`InvalidDeclaration`).
    pub fn declare(
        name: &'static str,
        params: Vec<Param>,
        storage: usize,
        dimension: usize,
        retraction: Arc<Composite>,
        inverse: Arc<Composite>,
        projection: Option<Arc<Composite>>,
    ) -> Result<Arc<Embedded>, Error>;

    /// This declaration, with its chart's volume against the measure its retraction normalizes.
    pub fn with_volume(self: Arc<Self>, volume: Volume) -> Result<Arc<Embedded>, Error>;
}

impl Volume {
    /// `Λ`, `Vector(n)` and `Vector(d)` to `Real`, on a global chart.
    pub fn global(log_volume: Arc<Composite>) -> Volume;
}
  • A type is four composites over its storage: RR, QQ, PP and Λ\Lambda, written on Vector(n) and Vector(d), never on the type itself. The rotation’s arithmetic is therefore written once, as functions on storage handles, and used by the three declarations and by the maps alike.
  • Two declarations under one name and parameters are one type, so each type is declared once, in a static, and its marker hands out that declaration.
  • The measure is the one the retraction normalizes, ν\nu of Proposition 7 for the rotations and ν×\nu \times Lebesgue for the motions, so Λ\Lambda is the math’s log-volume as it stands, and every chart is global.

Markers and host values#

crates/skoro-core/src/q.rs and into_host.rs:

pub trait Typed: Copy + Send + Sync + 'static { fn admits(space: &Space) -> bool; }
pub trait Declares: Typed { fn space(&self) -> Space; }

/// A Rust value that a marker suggests, as a value on the host shared by every row; `None` when
/// it cannot be one.
pub trait IntoHostValue<T> { fn into_host_value(self) -> Option<HostValue>; }
impl<T, V: IntoHostValue<T>> IntoHostValue<T> for Rows<V> { /* one value per row */ }
  • Declares::space cannot fail, while declaring a type returns a Result. The declarations are deterministic, so the static that holds each one handles the error branch with unreachable!, as the core does where a branch is provably dead, and a test declares every type and defines every composite. The workspace lints deny unwrap, expect and panic!, not unreachable!.
  • IntoHostValue returns an Option, so a host value that cannot be a point (a zero quaternion, a non-finite entry) is refused there, and one that is only near the type is normalized there. Rows gives every implementation its batched form for free.

Operators and handles#

crates/skoro-core/src/ops.rs:

/// `lhs * rhs`.
pub trait QMul<Rhs: Typed = Self>: Typed {
    type Output: Typed;
    fn mul(lhs: Q<Self>, rhs: Q<Rhs>) -> Q<Self::Output>;
}

impl<T: Typed> Q<T> {
    pub fn retract(self, t: impl Into<QDyn>) -> Q<T>;
    pub fn local(self, from: Q<T>) -> Q<VectorDyn>;
    pub fn log_volume(self, t: impl Into<QDyn>) -> Q<Real>;
    pub fn include(self) -> Q<VectorDyn>;
}

pub fn concatenate(parts: &[QDyn], space: Space) -> QDyn;
pub fn project<T: Declares>(marker: T, w: impl Into<QDyn>) -> Q<T>;
pub fn select<T: Typed>(index: impl Into<QDyn>, values: &[Q<T>]) -> Q<T>;
pub fn product(parts: &[QDyn]) -> Q<ProductDyn>;

and the inherent methods of the Euclidean markers: exp, log, sin, cos, atan2, sum, slice, reshape, matmul, transpose, and on Q<Real>, is_nonnegative.

  • QMul is the core’s trait and the markers are this crate’s, so the orphan rule allows impl QMul for Rotation and impl QMul<Vector<3>> for Rotation: * composes and acts, as the mathematics writes them.
  • Q is the core’s type, so the crate cannot add inherent methods to Q<Rotation>. Its methods come through extension traits, which must not reuse the names of Q<T>’s generic inherent methods (retract, local, log_volume, include, narrow, untyped, id), since an inherent method wins and the trait’s would be unreachable by method syntax.
  • A value of an embedded type can be neither negated nor scaled, and concatenate builds Euclidean values and products only. Every map into a type therefore computes storage and ends in project, as (9) has it; a choice of sign (the rotation vector, alignment, the reading of a matrix) is a selection in storage, before the projection.
  • select takes a Categorical index whose value kk picks the kk-th value; a Boolean is Categorical(2), false picking the first. A choice among four is a tournament of Boolean selections.
  • A matrix is stored column by column: XijX_{ij} is at index i+3ji + 3j of a Matrix(3, 3).

The angle of a point#

crates/skoro-core/src/primitive/euclidean.rs, last changed at d47119d and read at fe6f57e:

plain!(
    /// `atan2(a, b)`, elementwise: the angle in `(-π, π]` of the point `(b, a)`, defined where
    /// `a² + b²` is positive and smooth off the half-line `a = 0, b < 0`.
    Atan2, "skoro.atan2", two_euclidean, Angle
);

with the derivatives (b,−a)/(a2+b2)(b, -a)/(a^2 + b^2) of (13), and their own, on both sides of the half-line.

  • An angle read off a rotation by atan2 is cut where it is π\pi: its value jumps by 2π2\pi there and its derivatives do not, which is the wrap of the Euler angles. The design takes the cut as it is and places it with atan2(sin θ, cos θ), whose derivatives in θ\theta are 11 and 00 everywhere.
  • atan2(0, 0) is undefined, and so are its derivatives: an argument that can vanish on some rows is replaced on them by a harmless one, as a norm’s is.

Composites#

crates/skoro-core/src/composite.rs:

impl Composite {
    /// Runs `body` with one handle per input; the operations inside build into the composite,
    /// and the handle `body` returns is its output.
    pub fn define(name: &'static str, params: Vec<Param>, inputs: &[Space],
                  body: impl FnOnce(&[QDyn]) -> QDyn) -> Result<Arc<Composite>, Failure>;
    /// Adds one node to the open scope: this composite applied to `inputs`.
    pub fn call(self: &Arc<Self>, inputs: &[QDyn]) -> QDyn;
}
  • A composite is defined once, over exact input spaces, and compiled for each target when a program is. Its body cannot see the target’s precision, so each cutoff and each truncation is one for both precisions. Lowering::target is public, so an Operation of the crate’s own could lower to a composite chosen per precision; see Series and cutoffs for why this design does not need it.
  • A call refuses inputs of other spaces with SpaceMismatch, at the caller’s line, which is how a map refuses a wrong input. VectorDyn(3) is Vector(3), so dynamic handles of the right size are accepted.
  • A composite may make constants, of any Declares marker, inside its body.

Testing#

crates/skoro-core/src/testing.rs:

pub fn check_operation(operation: &dyn Operation, inputs: &[(Space, HostValue)],
                       target: &Target) -> Result<(), String>;
pub fn check_agreement(a: impl Fn(&[QDyn]) -> QDyn, b: impl Fn(&[QDyn]) -> QDyn,
                       inputs: &[(Space, HostValue)], target: &Target) -> Result<(), String>;
pub fn check_embedded(declaration: &Arc<Embedded>, points: &HostValue,
                      target: &Target) -> Result<(), String>;
pub fn check_volume(declaration: &Arc<Embedded>, points: &HostValue,
                    target: &Target) -> Result<(), String>;

with Tolerance::of(Precision::Double) a relative 10−710^{-7} and a central difference of step 10−610^{-6}, and single-precision results held to double-precision ones within Tolerance::AGREEMENT, 10−410^{-4}, against the larger of the reference’s largest magnitude and one.

  • check_embedded and check_volume are the checks the mathematics asks of the types’ boundaries and volumes (What the tests check).
  • The single-precision agreement is absolute below magnitude one, which is what decides the cutoffs of Series and cutoffs.

The registry#

crates/skoro-core/src/registry.rs:

/// How a name finds its code again: constructors by name. A value, not global state; a feature
/// crate exports a function that adds its names to one.
impl Registry {
    pub fn register_embedded(&mut self, name: &'static str, make: MakeEmbedded) -> Result<(), Error>;
}
pub type MakeEmbedded = fn(&[Param]) -> Result<Arc<Embedded>, Error>;
  • The crate exports register, adding its three declarations. Composites are not registered: they are stored whole, as the normal’s are.

Design#

The crate#

crates/skoro-spatial, a member of the workspace, named for what it holds, the rotations and rigid motions of space, rather than for one of its types, depending on skoro-core and skoro-tensor and on nothing else, with skoro-normal as a development dependency for the tests that score these types. The umbrella does not re-export it, as it does not re-export the normal. It has no kernel, so the rule that a change to a kernel is pushed only after the wgpu tests pass does not apply.

crates/skoro-spatial/src/
    lib.rs          pub use of the items below; register()
    algebra.rs      the quaternion arithmetic on storage handles (private)
    series.rs       the coefficients of the removable singularities, guarded (private)
    types.rs        the three declarations, their markers, their host values
    rotation.rs     the maps of the rotations: operators, RotationMaps, free functions
    euler.rs        Sequence, Frame, Euler; the composites of eq:euler and the statement euler
    so3.rs          hat, vee, the Jacobians and their inverses
    pose.rs         the maps of the rigid motions: operators, PoseMaps, free functions
    extended.rs     the maps of the extended poses
    host.rs         alignment and conversions on the host, in double precision

One crate holds the three types. The archive branch had skoro-so3 and skoro-se3, the second built on the first’s arithmetic through a public module (skoro_so3::ops::body). Here every type is written on the same storage arithmetic, which would otherwise have to be a public interface of one crate for the other; and a pose is not useful without the rotations, nor the rotations, in practice, without the maps that carry vectors and positions. Kept from the archive: the body-frame chart of the motions, (r,p)⊕(a,b)=(r⊕a,p+rb)(r, p) \oplus (a, b) = (r \oplus a, p + r b), the group operations under their names (compose, invert, rotate and unrotate, transform and untransform), and methods on handles through extension traits. Not kept: the matrix storage, the exponential chart, and the fused kernels of the exponential and the logarithm for each backend, which Matrices or quaternions replaces with composites; and the archive’s cutoffs per precision, which Series and cutoffs replaces with one.

Storage arithmetic#

algebra.rs holds the arithmetic of (1) and (2) on handles of storage, QDyns of Vector(4) and Vector(3), built of the core’s primitives. Nothing in it is public; each function adds nodes to the open scope, inside a composite’s body.

/// `(w, u)` of a `Vector(4)`: `w` a `Real`, `u` a `Vector(3)`.
fn parts(q: QDyn) -> (QDyn, QDyn);
/// The `Vector(4)` of `w` and `u`.
fn quaternion(w: QDyn, u: QDyn) -> QDyn;
/// `a × b`, by slices, products and a concatenation.
fn cross(a: QDyn, b: QDyn) -> QDyn;
fn dot(a: QDyn, b: QDyn) -> QDyn;                       // (a * b).sum()
/// eq:product.
fn mul(a: QDyn, b: QDyn) -> QDyn;
fn conjugate(q: QDyn) -> QDyn;
/// `π(q) x = x + 2w (u × x) + 2 u × (u × x)`, and with `-u`, `π(q)ᵀ x`.
fn rotate(q: QDyn, x: QDyn) -> QDyn;
fn unrotate(q: QDyn, x: QDyn) -> QDyn;
/// eq:rotation, as a `Matrix(3, 3)` concatenated column by column.
fn matrix(q: QDyn) -> QDyn;
/// `[ω]×`, column by column.
fn hat(omega: QDyn) -> QDyn;
/// `1 / a = e^{-log a}`, for `a` positive on the domain.
fn reciprocal(a: QDyn) -> QDyn;
/// `√a = e^{½ log a}`, for `a > 0`.
fn sqrt(a: QDyn) -> QDyn;
/// `|x| = √(Σ xᵢ²)` and `x / |x|`, for `x ≠ 0`.
fn norm(x: QDyn) -> QDyn;
fn normalize(x: QDyn) -> QDyn;
/// `select` on two `QDyn`s by a `Boolean`: `if_true` where it is true.
fn choose(condition: QDyn, if_false: QDyn, if_true: QDyn) -> QDyn;
/// Both conditions: `1[a b - ½ ≥ 0]` of their embeddings as reals, since `select` takes
/// continuous values only and cannot choose between Booleans.
fn both(a: QDyn, b: QDyn) -> QDyn;
/// `δ(t) = ((1 - s), t/2) / (1 + s)`, `s = |t|²/16`: the chart at the identity.
fn delta(t: QDyn) -> QDyn;
/// The chart's inverse at the identity, `4 vec(d) / (1 + w(d))`.
fn delta_inverse(d: QDyn) -> QDyn;

rotate and matrix assume a unit quaternion, as the mathematics does. The maps that take a value of a type hand them its inclusion, which is unit up to rounding.

The three types#

types.rs declares each type once, in a LazyLock, with the composites of its boundary:

typenamestorage, dimensionR(x,t)R(x, t)Q(x,y)Q(x, y)P(x)P(x)Λ(x,t)\Lambda(x, t)
S3S^3skoro.spatial.rotation4, 3x^⊗δ(t)\hat x \otimes \delta(t)δ−1(xˉ⊗y)\delta^{-1}(\bar x \otimes y)x^\hat x−3log⁡(1+116∣t∣2)-3 \log(1 + \tfrac1{16} \lvert t \rvert^2)
S3⋉R3S^3 \ltimes \R^3skoro.spatial.pose7, 6(q^⊗δ(ϕ), p+π(q^)ρ)(\hat q \otimes \delta(\phi),\ p + \pi(\hat q) \rho)(δ−1(qˉ⊗q′), π(q)⊤(p′−p))(\delta^{-1}(\bar q \otimes q'),\ \pi(q)\transpose (p' - p))(q^,p)(\hat q, p)the same, of ϕ\phi
S3⋉(R3)2S^3 \ltimes (\R^3)^2skoro.spatial.extended_pose10, 9(q^⊗δ(ϕ), v+π(q^)η, p+π(q^)ρ)(\hat q \otimes \delta(\phi),\ v + \pi(\hat q) \eta,\ p + \pi(\hat q) \rho)likewise(q^,v,p)(\hat q, v, p)the same, of ϕ\phi

with x^=x/∣x∣\hat x = x / \lvert x \rvert. These are Proposition 5, Proposition 7 and Proposition 23, with one addition: the retraction normalizes its base point. On the type that changes nothing, and its derivatives at the type are the same; off it, it keeps a point that a long run of retractions has carried off the sphere by rounding from carrying that error into every later step, the way an estimator’s state is updated thousands of times in single precision. The mathematics leaves the behaviour off the type to this entry, as the core’s does. The alternative, leaving the drift to the maps that project, lost because an estimator that only retracts never projects. The inverse retraction does not normalize: its inputs are points of the type.

Each composite is written on storage with algebra.rs, so the motions’ declarations do not depend on the rotation’s statics. The denominators are positive on the domain: 1+s≥11 + s \ge 1, ∣x∣>0\lvert x \rvert > 0, and 1+w(xˉ⊗y)>01 + w(\bar x \otimes y) > 0 for y≠−xy \ne -x, where the inverse is undefined, as the chart’s cut: non-finite at a row exactly on it, and growing without bound near it, as Errors and domains says of every singular row.

pub static ROTATION: LazyLock<Arc<Embedded>> = LazyLock::new(|| {
    match declare_rotation() {
        Ok(declaration) => declaration,
        Err(_) => unreachable!("the rotation's declaration is checked by `types_are_declared`"),
    }
});

fn declare_rotation() -> Result<Arc<Embedded>, Error> {
    let (n, d) = (Space::Vector(4), Space::Vector(3));
    let define = |name, inputs: &[Space], body: fn(&[QDyn]) -> QDyn| {
        Composite::define(name, Vec::new(), inputs, body).map_err(|f| f.error)
    };
    let r = define("skoro.spatial.rotation.retract", &[n.clone(), d.clone()],
                   |q| mul(normalize(q[0]), delta(q[1])))?;
    let q = define("skoro.spatial.rotation.local", &[n.clone(), n.clone()],
                   |q| delta_inverse(mul(conjugate(q[0]), q[1])))?;
    let p = define("skoro.spatial.rotation.project", &[n.clone()], |q| normalize(q[0]))?;
    let lambda = define("skoro.spatial.rotation.log_volume", &[n.clone(), d],
                        |q| ((q[1] * q[1]).sum() * (1.0 / 16.0) + 1.0).log() * -3.0)?;
    Embedded::declare("skoro.spatial.rotation", Vec::new(), 4, 3, r, q, Some(p))?
        .with_volume(Volume::global(lambda))
}

The markers are unit structs, each admitting its declaration’s space and declaring it:

/// A unit quaternion `(w, x, y, z)`: a rotation, and its double cover. Tangent coordinates are the
/// rotation vector in the frame of the point, to first order.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default)]
pub struct Rotation;
/// `(q, p)`: a rigid motion, its tangent coordinates `(φ, ρ)` in the frame of the motion.
pub struct Pose;
/// `(q, v, p)`: an extended pose, its tangent coordinates `(φ, η, ρ)` in its own frame.
pub struct ExtendedPose;

impl Typed for Rotation {
    fn admits(space: &Space) -> bool { matches!(space, Space::Embedded(e) if **e == **ROTATION) }
}
impl Declares for Rotation {
    fn space(&self) -> Space { Space::Embedded(ROTATION.clone()) }
}
// likewise for Pose and ExtendedPose

/// The three declarations, by name, with no parameters.
pub fn register(registry: &mut Registry) -> Result<(), Error>;

Host values give a type’s storage in its order, the scalar part of a quaternion first:

/// `(w, x, y, z)`, normalized on the host; `None` for a zero or non-finite quaternion. A sensor that
/// gives `(x, y, z, w)` must be reordered.
impl IntoHostValue<Rotation> for [f64; 4];
/// The rotation and the position.
impl IntoHostValue<Pose> for ([f64; 4], [f64; 3]);
impl IntoHostValue<Pose> for [f64; 7];
/// The rotation, the velocity and the position.
impl IntoHostValue<ExtendedPose> for ([f64; 4], [f64; 3], [f64; 3]);
impl IntoHostValue<ExtendedPose> for [f64; 10];

Series and cutoffs#

series.rs computes the coefficients of Removable singularities and the motions’ DD and EE ((28)), each by the core’s guarded pattern: a discretization of the argument against a cutoff selects the series, the closed form’s argument is replaced by a harmless one on the rows where the series is chosen, and the series’ argument by one on the rows where the closed form is, wherever the series could be undefined.

/// Which coefficient, of `θ²`.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
enum Coefficient { A0, B0, A, B, C, D, E }      // a, b of eq:exp; A, B; C; D, E

/// The coefficient at `θ² = theta2`, a `Real`: the series below `CUTOFF`, the closed form above.
fn coefficient(c: Coefficient, theta2: QDyn) -> QDyn {
    let small = (-theta2 + CUTOFF).is_nonnegative();
    let safe = choose(small, theta2, one());               // the closed form's argument
    let theta = (safe.log() * 0.5).exp();
    choose(small, closed(c, theta), horner(series(c), theta2))
}

/// `L = 2 atan2(n, w) / n` of eq:log from `n²` and `w`: its series in `x = n²/w²` where
/// `n² < LOG_CUTOFF w²` and `w > 0`, the closed form elsewhere.
fn log_ratio(n2: QDyn, w: QDyn) -> QDyn {
    let small = both(w.is_nonnegative(), (w * w * LOG_CUTOFF - n2).is_nonnegative());
    let n = (choose(small, n2, one()).log() * 0.5).exp();
    let w_safe = choose(small, one(), w);                   // the series' 1/w where it is unused
    let x = n2 * reciprocal(w_safe * w_safe);
    choose(small, n.atan2(w) * reciprocal(n) * 2.0, horner(LOG_SERIES, x) * reciprocal(w_safe) * 2.0)
}

both multiplies the two Booleans’ embeddings as reals, to_real, which carries no derivative, and compares the product with 12\tfrac12: a selection cannot combine them, since Select refuses values that are not continuous. On a row with w=0w = 0 exactly, n2≥0=c w2n^2 \ge 0 = c\, w^2, so the series is never chosen there, and its guard keeps its 1/w1/w finite.

One cutoff serves both precisions. A composite cannot see its target’s precision, and the measurements below show that no second one is needed, so the alternative, an operation of the crate’s own lowering to a composite per precision through Lowering::target, with registry entries for each, lost. Two conditions decide each cutoff: in double precision, the series’ truncation at the cutoff is below rounding, against the series summed to convergence; in single precision, the closed form just above it, its value and its first and second derivatives, agrees with double precision within Tolerance::AGREEMENT. The second was measured on the closed forms and their derivatives in θ\theta (in nn for LL) written as the passes chain them, in numpy, not on the core’s passes themselves; series_meet_closed_forms and check_operation at 1.11.1 times each cutoff are the check on the code.

coefficientargumentcutoffseries keptf64 truncation at the cutofff32 closed form above it: value, first, second derivative
aaθ2\theta^20.10.1through θ10\theta^{10}below 2−532^{-53}3⋅10−83 \cdot 10^{-8}, 2⋅10−92 \cdot 10^{-9}, 6⋅10−96 \cdot 10^{-9}
bbθ2\theta^20.10.1through θ10\theta^{10}below 2−532^{-53}9⋅10−99 \cdot 10^{-9}, 2⋅10−72 \cdot 10^{-7}, 4⋅10−74 \cdot 10^{-7}
AAθ2\theta^20.10.1through θ10\theta^{10}below 2−532^{-53}3⋅10−73 \cdot 10^{-7}, 2⋅10−62 \cdot 10^{-6}, 2⋅10−52 \cdot 10^{-5}
BBθ2\theta^20.10.1through θ10\theta^{10}below 2−532^{-53}1⋅10−71 \cdot 10^{-7}, 3⋅10−73 \cdot 10^{-7}, 6⋅10−76 \cdot 10^{-7}
CCθ2\theta^20.10.1through θ12\theta^{12}below 2−532^{-53}1⋅10−61 \cdot 10^{-6}, 2⋅10−62 \cdot 10^{-6}, 4⋅10−54 \cdot 10^{-5}
DDθ2\theta^20.10.1through θ10\theta^{10}below 2−532^{-53}2⋅10−72 \cdot 10^{-7}, 3⋅10−63 \cdot 10^{-6}, 4⋅10−54 \cdot 10^{-5}
EEθ2\theta^20.10.1through θ10\theta^{10}below 2−532^{-53}2⋅10−72 \cdot 10^{-7}, 5⋅10−65 \cdot 10^{-6}, 2⋅10−42 \cdot 10^{-4}
LLx=n2/w2x = n^2/w^20.010.01through x7x^7below 2−532^{-53}2⋅10−82 \cdot 10^{-8}, 6⋅10−76 \cdot 10^{-7}, 3⋅10−53 \cdot 10^{-5}

The single-precision errors are absolute, as Tolerance::AGREEMENT holds them, and each coefficient reaches a map’s value multiplied by powers of θ\theta (EE by ΦΨΦ2\Phi \Psi \Phi^2, of order θ3∣ρ∣\theta^3 \lvert \rho \rvert), so the largest, EE’s second derivative, contributes about 10−510^{-5}. A cutoff of θ2=0.01\theta^2 = 0.01 would cost DD and EE errors of 10−110^{-1} and more in their second derivatives in single precision; one of 0.10.1 for LL would need its series through x14x^{14}. The series are evaluated by Horner’s rule, a product and a sum per term. The archive’s cutoffs per precision (θ2≈1.37\theta^2 \approx 1.37 and 0.0250.025, series through θ8\theta^8) are not kept.

The maps of the rotations#

rotation.rs. Each map with more than a few nodes is a composite named skoro.spatial.<map>, defined once in a LazyLock as the types are; the operators and methods call it.

/// `q₁ * q₂ = P(q₁ ⊗ q₂)`.
impl QMul for Rotation { type Output = Rotation; }
/// `q * x = π(q) x`, a vector, or each column of a `3 × N` matrix.
impl QMul<Vector<3>> for Rotation { type Output = Vector<3>; }
impl QMul<VectorDyn> for Rotation { type Output = VectorDyn; }
impl<const N: usize> QMul<Matrix<3, N>> for Rotation { type Output = Matrix<3, N>; }

/// The maps of a rotation, as methods of its handle.
pub trait RotationMaps: Sized {
    /// `P(q̄)`.
    fn inverse(self) -> Q<Rotation>;
    /// `P(q̄₁ ⊗ q₂)`: the rotation from `self` to `other`, in the frame of `self`.
    fn between(self, other: Q<Rotation>) -> Q<Rotation>;
    /// `π(q)ᵀ x`: a vector of the outer frame in the frame of `self`.
    fn unrotate(self, x: Q<Vector<3>>) -> Q<Vector<3>>;
    /// eq:rotation.
    fn matrix(self) -> Q<Matrix<3, 3>>;
    /// The adjoint, `π(q)`, carrying a perturbation in the frame of `self` to the outer frame.
    fn adjoint(self) -> Q<Matrix<3, 3>>;
    /// eq:log: the inverse of `exp`, of length in [0, 2π); non-finite at `-1`.
    fn log(self) -> Q<Vector<3>>;
    /// eq:rotation-vector: the rotation vector of the shorter turn, the same at `±q`.
    fn log_shorter(self) -> Q<Vector<3>>;
    /// eq:angle, in [0, π].
    fn angle_to(self, other: Q<Rotation>) -> Q<Real>;
    /// eq:slerp, and with `log_shorter` in place of `log`.
    fn slerp(self, other: Q<Rotation>, t: Q<Real>) -> Q<Rotation>;
    fn slerp_shorter(self, other: Q<Rotation>, t: Q<Real>) -> Q<Rotation>;
    /// The statement euler: the angles of `convention`, `α` and `γ` in (-π, π], cut at π, where
    /// their values jump by 2π and their derivatives do not; compare them by `angle_residual`.
    fn euler(self, convention: Euler) -> Q<Vector<3>>;
    /// The axis and the angle of `log`; the axis `(1, 0, 0)` at the identity.
    fn axis_angle(self) -> (Q<Vector<3>>, Q<Real>);
    /// `sign⟨q, r⟩ q`: the point over this rotation on the side of `reference`.
    fn aligned_with(self, reference: Q<Rotation>) -> Q<Rotation>;
}
impl RotationMaps for Q<Rotation> { /* each a call of its composite, narrowed */ }

pub mod rotation {
    pub fn identity() -> Q<Rotation>;
    /// eq:exp.
    pub fn exp(omega: Q<Vector<3>>) -> Q<Rotation>;
    /// The rotation by `angle` about `axis ≠ 0`.
    pub fn about(axis: Q<Vector<3>>, angle: Q<Real>) -> Q<Rotation>;
    /// `q_e(θ)` about a coordinate axis.
    pub fn elementary(axis: Axis, angle: Q<Real>) -> Q<Rotation>;
    /// eq:two-vectors; undefined where `b` is opposite to `a`, or either is zero: non-finite
    /// where the argument vanishes exactly, and ill-conditioned near it, its error the rounding
    /// over the angle by which `b` falls short of `-a`.
    pub fn from_two_vectors(a: Q<Vector<3>>, b: Q<Vector<3>>) -> Q<Rotation>;
    /// eq:euler.
    pub fn from_euler(angles: Q<Vector<3>>, convention: Euler) -> Q<Rotation>;
    /// eq:from-matrix.
    pub fn from_matrix(m: Q<Matrix<3, 3>>) -> Q<Rotation>;
}

The exponential is P(a , b ω)P(a\,,\ b\, \omega) with aa and bb from series.rs of θ2=ω⋅ω\theta^2 = \omega \cdot \omega; the logarithm is log_ratio(n², w) u, and log_shorter the same of the storage chosen between qq and −q-q by w≥0w \ge 0. The angle is 2atan2⁡(∣vec⁡r∣,∣w(r)∣)2 \operatorname{atan2}(\lvert \operatorname{vec} r \rvert, \lvert w(r) \rvert), the absolute value a selection; its norm is undefined at r=±1r = \pm 1, where the angle has no derivative and its rows are non-finite in the passes, as a norm’s are. The axis–angle guards the axis with a selection at n2=0n^2 = 0. Alignment selects between the storage of qq and its negation by ⟨q,r⟩≥0\langle q, r \rangle \ge 0 and projects.

from_matrix computes the four arguments cm(X)c_m(X) of (22) as linear maps of the stored matrix, chooses one by a tournament on their diagonal entries, and projects only the one chosen:

// x = the stored Matrix(3, 3) as a Vector(9); X_ij = x[i + 3j].
let c = [c0(x), c1(x), c2(x), c3(x)];                    // each a Vector(4)
let d = |m: usize| c[m].slice(m..m + 1).reshape(Space::Real);
let first = (d(1) - d(0)).is_nonnegative();               // 1 beats 0
let second = (d(3) - d(2)).is_nonnegative();              // 3 beats 2
let (a, da) = (choose(first, c[0], c[1]), choose(first, d(0), d(1)));
let (b, db) = (choose(second, c[2], c[3]), choose(second, d(2), d(3)));
normalize(choose((db - da).is_nonnegative(), a, b))

The chosen argument has norm at least 22, so the projection never meets a small one.

so3.rs holds the Euclidean maps of rotation vectors:

pub mod so3 {
    /// `[ω]×` and its inverse on skew matrices, the vector of the skew part of any other.
    pub fn hat(omega: Q<Vector<3>>) -> Q<Matrix<3, 3>>;
    pub fn vee(m: Q<Matrix<3, 3>>) -> Q<Vector<3>>;
    /// eq:jacobians and eq:jacobian-inverses; the inverses non-finite at `|ω| = 2π`.
    pub fn jl(omega: Q<Vector<3>>) -> Q<Matrix<3, 3>>;
    pub fn jr(omega: Q<Vector<3>>) -> Q<Matrix<3, 3>>;
    pub fn jl_inv(omega: Q<Vector<3>>) -> Q<Matrix<3, 3>>;
    pub fn jr_inv(omega: Q<Vector<3>>) -> Q<Matrix<3, 3>>;
}

each I+c1[ω]×+c2[ω]×2I + c_1 [\omega]_\times + c_2 [\omega]_\times^2 with the coefficients of series.rs.

Euler angles#

#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub enum Axis { X, Y, Z }

/// The twelve sequences: six of Tait–Bryan type and six proper.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub enum Sequence { Xyz, Xzy, Yxz, Yzx, Zxy, Zyx, Xyx, Xzx, Yxy, Yzy, Zxz, Zyz }

/// About the axes as the previous rotations left them, or about the fixed axes.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub enum Frame { Intrinsic, Extrinsic }

#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub struct Euler { pub sequence: Sequence, pub frame: Frame }

impl Euler {
    /// Yaw, pitch and roll `(ψ, ϑ, φ)`, intrinsic about `(z, y, x)`: the aerospace convention.
    pub const YAW_PITCH_ROLL: Euler = Euler { sequence: Sequence::Zyx, frame: Frame::Intrinsic };
    pub fn axes(self) -> [Axis; 3];
}

/// eq:angle-residual, elementwise: `a ⊖ b = atan2(sin(a - b), cos(a - b))`, in (-π, π], cut where
/// `a - b` is an odd multiple of π. `b + angle_residual(a, b)` is `a` brought within a half-turn of
/// `b`.
pub fn angle_residual<M: Angles>(a: Q<M>, b: Q<M>) -> Q<M>;

/// The markers whose values may be angles: `Real`, `Vector<N>` and `VectorDyn`. Sealed.
pub trait Angles: Typed + sealed::Sealed {}

The enum makes a sequence with two equal neighbouring axes unrepresentable. Frame shares its name with skoro::tensor::Frame; a crate that glob-imports both names one of them by its path. The angles’ vector holds them in the order of the sequence’s axes. Both directions are composites per intrinsic sequence, skoro.spatial.from_euler and skoro.spatial.euler with the parameter Text("zyx"), cached by sequence as the normal caches its composites; an extrinsic convention calls the composite of the reversed sequence with the angles reversed, by slices and a concatenation outside it.

from_euler is (18), three elementary quaternions multiplied and projected. euler is Proposition 19: for a Tait–Bryan sequence it first forms the linear rearrangement (w−uj, ui−ϵuk, uj+w, uk+ϵui)(w - u_j,\ u_i - \epsilon u_k,\ u_j + w,\ u_k + \epsilon u_i), then for both kinds

// (w, ui, uj, ul) read from the quaternion or its rearrangement, eps = ±1 for the sequence.
let (na, nb) = (w * w + ui * ui, uj * uj + ul * ul);
let total = na + nb;
let low = (total * LOCK - nb).is_nonnegative();          // β at 0 (proper) or -π/2 (Tait–Bryan)
let high = (total * LOCK - na).is_nonnegative();         // β at π or π/2
let beta = choose(low, choose(high, sqrt(nb).atan2(sqrt(na)) * 2.0, pi()), zero());
let sigma = ui.atan2(choose(high, w, one()));             // guarded where (w, ui) vanishes
let delta = (ul * eps).atan2(choose(low, uj, one()));     // guarded where (uj, ul) vanishes
let alpha = choose(low, choose(high, sigma + delta, delta * 2.0), sigma * 2.0);
let gamma = choose(low, choose(high, sigma - delta, zero()), zero());

with the arguments of the two square roots guarded as log_ratio’s are on the rows where they vanish, β\beta shifted by −π2-\tfrac\pi2 and γ\gamma multiplied by −ϵ-\epsilon for a Tait–Bryan sequence, and α\alpha and γ\gamma wrapped to (−π,π](-\pi, \pi] as atan2⁡(sin⁡⋅,cos⁡⋅)\operatorname{atan2}(\sin \cdot, \cos \cdot).

The lock. LOCK is the fraction cc of The lock, and is 10−3410^{-34}. On a selected row the convention’s rotation is within 2arcsin⁡c=2⋅10−172 \arcsin \sqrt c = 2 \cdot 10^{-17} of qq, below the rounding of a unit quaternion’s coordinates in double precision, 2−53≈1.1⋅10−162^{-53} \approx 1.1 \cdot 10^{-16}, which moves its rotation by angles of that order, and so below either precision’s, as the mathematics requires. The bound leaves c≲3⋅10−33c \lesssim 3 \cdot 10^{-33}; 10−3410^{-34} sits under it with room, and stays usable in single precision, where total * LOCK, with total at most 22 for the Tait–Bryan rearrangement, is a normal number, far above the smallest, 1.2⋅10−381.2 \cdot 10^{-38}, and a vanishing norm’s square of 10−3610^{-36} is still representable, so that the band selected is the same at both precisions. The earlier 10−3010^{-30}, chosen as “rounding of nothing”, gave 2⋅10−152 \cdot 10^{-15}, some twenty roundings, and is replaced. A larger threshold would replace the angles by the convention on a band of rotations that it reproduces only to the band’s β\beta; a smaller one would bring the band below single precision’s smallest normal numbers.

The threshold matters for finiteness, not for the round trip. A rotation at the lock only up to rounding, as (18) computes one at β=±π2\beta = \pm\tfrac\pi2, whose rearrangement leaves the vanishing norm at the size of rounding rather than zero, is not selected, and is read by the statement: its α\alpha and γ\gamma are individually ill-conditioned, with first derivatives of order 1/sin⁡β21 / \sin \tfrac\beta2, at most 101710^{17} on any row not selected, and second of its square, both finite in single precision, while α±γ\alpha \pm \gamma and β\beta are accurate, and the undetermined combination enters the rotation weighted by sin⁡β2\sin \tfrac\beta2, so the round trip reproduces the rotation within rounding. The selection is what keeps an exact zero, as at the identity of a proper sequence, from reaching atan2(0, 0) and a norm at zero.

The wrap. atan2⁡(sin⁡α,cos⁡α)\operatorname{atan2}(\sin \alpha, \cos \alpha) has derivative 11 in α\alpha on both sides of its cut, and second derivative 00, so the angles’ passes are continuous across the wrap and only their values jump, as the mathematics says. Nothing in the composite treats the wrap; the tests check it, and keep central differences away from it.

The residual. angle_residual is (21), inline rather than a composite, since it is four nodes, d=a−bd = a - b and atan2⁡(sin⁡d,cos⁡d)\operatorname{atan2}(\sin d, \cos d), on the untyped handles, narrowed back to M. It is generic over a sealed trait because the core gives sin, cos and atan2 as inherent methods of each Euclidean marker, with no trait to bound by, and an angle is a Real (a heading), a Vector<3> (the angles of euler), or a vector of any length. The alternative, leaving the expression to the caller, lost because a residual of angles written as a - b is the natural mistake, and the function names the right one where a user looks for it. It has no host twin: a host angle is compared by the same three lines of f64.

The maps of the rigid motions#

pose.rs and extended.rs, likewise, with the tangent coordinates rotation first:

impl QMul for Pose { type Output = Pose; }                     // composition
impl QMul<Vector<3>> for Pose { type Output = Vector<3>; }     // the action on a point, R x + p

pub trait PoseMaps: Sized {
    fn inverse(self) -> Q<Pose>;
    fn between(self, other: Q<Pose>) -> Q<Pose>;              // T₁⁻¹ T₂
    fn rotate(self, x: Q<Vector<3>>) -> Q<Vector<3>>;          // R x: a direction
    fn untransform(self, x: Q<Vector<3>>) -> Q<Vector<3>>;     // Rᵀ (x - p)
    fn rotation(self) -> Q<Rotation>;
    fn position(self) -> Q<Vector<3>>;
    fn matrix(self) -> Q<Matrix<4, 4>>;
    fn adjoint(self) -> Q<Matrix<6, 6>>;                       // eq:motion-adjoint
    fn log(self) -> Q<Vector<6>>;                              // eq:motion-log
    fn log_shorter(self) -> Q<Vector<6>>;
    fn interpolate(self, other: Q<Pose>, t: Q<Real>) -> Q<Pose>;          // eq:motion-slerp, first
    fn interpolate_shorter(self, other: Q<Pose>, t: Q<Real>) -> Q<Pose>;
    fn interpolate_parts(self, other: Q<Pose>, t: Q<Real>) -> Q<Pose>;    // eq:motion-slerp, second
    fn interpolate_parts_shorter(self, other: Q<Pose>, t: Q<Real>) -> Q<Pose>;
    /// The same storage as a value of the product S³ × ℝ³, whose chart moves the position in a
    /// fixed frame.
    fn as_product(self) -> Q<ProductDyn>;
}

pub mod pose {
    pub fn identity() -> Q<Pose>;
    pub fn exp(xi: Q<Vector<6>>) -> Q<Pose>;                   // eq:motion-exp
    pub fn from_parts(q: Q<Rotation>, p: Q<Vector<3>>) -> Q<Pose>;
    pub fn from_product(x: Q<ProductDyn>) -> Q<Pose>;          // SpaceMismatch unless S³ × ℝ³
    /// eq:motion-jacobians, with Q of eq:motion-q.
    pub fn jl(xi: Q<Vector<6>>) -> Q<Matrix<6, 6>>;
    pub fn jr(xi: Q<Vector<6>>) -> Q<Matrix<6, 6>>;
    pub fn jl_inv(xi: Q<Vector<6>>) -> Q<Matrix<6, 6>>;
    pub fn jr_inv(xi: Q<Vector<6>>) -> Q<Matrix<6, 6>>;
}

impl QMul for ExtendedPose { type Output = ExtendedPose; }

pub trait ExtendedPoseMaps: Sized {
    fn inverse(self) -> Q<ExtendedPose>;
    fn between(self, other: Q<ExtendedPose>) -> Q<ExtendedPose>;
    fn rotation(self) -> Q<Rotation>;
    fn velocity(self) -> Q<Vector<3>>;
    fn position(self) -> Q<Vector<3>>;
    fn pose(self) -> Q<Pose>;
    fn matrix(self) -> Q<Matrix<5, 5>>;
    fn adjoint(self) -> Q<Matrix<9, 9>>;                       // eq:extended-adjoint
    fn log(self) -> Q<Vector<9>>;
    fn log_shorter(self) -> Q<Vector<9>>;
    fn interpolate(self, other: Q<ExtendedPose>, t: Q<Real>) -> Q<ExtendedPose>;
    fn interpolate_shorter(self, other: Q<ExtendedPose>, t: Q<Real>) -> Q<ExtendedPose>;
}

pub mod extended_pose {
    pub fn identity() -> Q<ExtendedPose>;
    pub fn exp(xi: Q<Vector<9>>) -> Q<ExtendedPose>;
    pub fn from_parts(q: Q<Rotation>, v: Q<Vector<3>>, p: Q<Vector<3>>) -> Q<ExtendedPose>;
    pub fn jl(xi: Q<Vector<9>>) -> Q<Matrix<9, 9>>;
    pub fn jr(xi: Q<Vector<9>>) -> Q<Matrix<9, 9>>;
    pub fn jl_inv(xi: Q<Vector<9>>) -> Q<Matrix<9, 9>>;
    pub fn jr_inv(xi: Q<Vector<9>>) -> Q<Matrix<9, 9>>;
}

A map into a motion computes its storage and projects, so its rotation is normalized and its translations pass through. rotation() projects the slice 0..40..4 of the inclusion onto Rotation, and from_parts concatenates the inclusions and projects onto the motion; as_product and from_product are the identity on storage, a product of Rotation and Vector<3> built with scope::product and read back by factor. The matrices are concatenated column by column, the adjoints and Jacobians block by block from π(q)\pi(q), [p]×[p]_\times, JlJ_l and QQ, with the blocks in the order (ϕ,ρ)(\phi, \rho) and (ϕ,η,ρ)(\phi, \eta, \rho). Q(ϕ,ρ)Q(\phi, \rho) of (28) is a composite, skoro.spatial.motion_q, of two Vector(3)s, with BB, DD and EE from series.rs; the inverses are the block forms of (27), with Jl−1J_l^{-1} of the rotations.

The extended pose’s maps go beyond what the mathematics lists in two places, both by the same formulas: the inverses of its Jacobians, the block lower-triangular inverse with the blocks −Jl−1Q(ϕ,η)Jl−1-J_l^{-1} Q(\phi, \eta) J_l^{-1} and −Jl−1Q(ϕ,ρ)Jl−1-J_l^{-1} Q(\phi, \rho) J_l^{-1}, and its interpolation by the group, T1Exp⁡(tLog⁡(T1−1T2))T_1 \Exp(t \Log(T_1^{-1} T_2)). Its action on points is that of its pose.

What each map is#

Every map of the mathematics’ tables, with the item that implements it, its composite, its equation, its kind, and the test that checks it. Smooth maps have derivatives of both orders on their domain; removable ones are smooth, with their singularity at the identity computed by series.rs; discrete ones select between smooth formulas, and have no derivative across the jump.

mapitemcomposite skoro.spatial.equationkindtest
the rotation’s chart and volumeRotationrotation.*quaternion-chartsmoothtypes_pass_the_core_checks
identityrotation::identity(a constant)smoothgroup_laws
compositionQ<Rotation> * Q<Rotation>composeproductsmoothgroup_laws
inverseinverseinversesmoothgroup_laws
relative rotationbetweenbetweensmoothgroup_laws
action, inverse action* Q<Vector<3>>, unrotaterotate, unrotaterotationsmoothactions_are_the_matrix
matrix, adjointmatrix, adjointmatrixrotation, conjugationsmoothactions_are_the_matrix, conjugation_is_exact
hat, veeso3::hat, so3::vee(inline)smoothhat_and_vee
exponentialrotation::expexpexpremovableexp_and_log
logarithmlogloglogremovableexp_and_log
rotation vectorlog_shorterlog_shorterrotation-vectordiscreteexp_and_log
Jacobians and inversesso3::jl, jr, jl_inv, jr_invjl, jl_invjacobians, jacobian-inversesremovablejacobians_are_the_passes
interpolationslerp, slerp_shorterslerp, slerp_shorterslerpremovable, discreteinterpolations
angleangle_toangleanglediscreteinterpolations
elementary, axis–anglerotation::elementary, about, axis_angleabout, axis_anglesmooth, discreteconstructions
two directionsrotation::from_two_vectorsfrom_two_vectorstwo-vectorssmoothconstructions
Euler anglesrotation::from_euler, eulerfrom_euler, eulereuler, statement eulersmooth, discreteeuler_round_trips
angle residualangle_residual(inline)angle-residualdiscreteangle_residual_is_on_the_circle
from a matrixrotation::from_matrixfrom_matrixfrom-matrixdiscretefrom_matrix_branches
alignmentaligned_with, host::alignaligndiscretealignment
the motions’ charts and volumesPose, ExtendedPosepose.*, extended_pose.*statement motionssmoothtypes_pass_the_core_checks
composition, inverse, relative*, inverse, betweenpose.compose, …smoothmotion_group_laws
actions* Q<Vector<3>>, rotate, untransformpose.transform, …smoothmotion_group_laws
partsrotation, position, velocity, pose, from_parts(inline)smoothparts_and_products
productas_product, pose::from_product(inline)smoothparts_and_products
matricesmatrixpose.matrix, extended_pose.matrixsmoothmotion_group_laws
adjointsadjointpose.adjoint, extended_pose.adjointmotion-adjoint, extended-adjointsmoothadjoints_conjugate
exponentials, logarithmspose::exp, log, log_shorterpose.exp, pose.log, …motion-exp, motion-logremovable, discretemotion_exp_and_log
Jacobianspose::jl, …, extended_pose::jl, …motion_q, pose.jl, …motion-jacobians, motion-qremovablejacobians_are_the_passes
interpolationsinterpolate, interpolate_parts, …pose.interpolate, …motion-slerpremovable, discreteinterpolations
every discretizationthe discrete maps abovediscretediscretizations_jump_cleanly

Host helpers#

host.rs, on [f64; 4] in the order (w,x,y,z)(w, x, y, z), in double precision, for the values a model is given:

pub mod host {
    /// `sign⟨z, r⟩ z`, normalized.
    pub fn align(z: [f64; 4], reference: [f64; 4]) -> [f64; 4];
    pub fn compose(a: [f64; 4], b: [f64; 4]) -> [f64; 4];
    pub fn matrix(q: [f64; 4]) -> [[f64; 3]; 3];
    /// eq:from-matrix, by rows.
    pub fn from_matrix(m: [[f64; 3]; 3]) -> [f64; 4];
    pub fn from_euler(angles: [f64; 3], convention: Euler) -> [f64; 4];
    pub fn euler(q: [f64; 4], convention: Euler) -> [f64; 3];
    pub fn exp(omega: [f64; 3]) -> [f64; 4];
    pub fn log(q: [f64; 4]) -> [f64; 3];
}

They are the same formulas in plain f64, with branches where the composites select. The mathematics asks for alignment on the host because an observed value is fixed before it is observed; aligned_with exists as well for a quaternion a model computes.

Errors and domains#

A wrong input is refused when the map is applied, by the composite’s call, with SpaceMismatch naming the composite, at the caller’s line; nothing else is refused at build time.

A map is undefined at the singular rows the mathematics names: the inverse retraction at y=−xy = -x, log at −1-1, jl_inv and the motions’ logarithms at an angle of 2π2\pi, from_two_vectors at opposite or zero directions, and angle_to’s derivatives where the angle is 00 or π\pi. These rows are not detected. At a row exactly on one, the composite takes a logarithm of zero, a norm of zero or an atan2(0, 0), and its values or its passes are non-finite. At a row within rounding of one, which is how such a row usually arrives, the composite computes finite values: large ones where the map grows without bound toward the row (the inverse retraction, jl_inv), and where only its conditioning does (the direction of from_two_vectors, of log near −1-1), values whose error is the rounding times that conditioning, meaningless at the row itself. Each item’s documentation says which. The alternative, a guard that makes a band around each singular row non-finite, lost for two reasons. A composite cannot see its precision, so one band is either wide enough for single precision, refusing rows that double precision computes well, or narrow enough for double, leaving single precision’s meaningless rows finite. And the mathematics leaves the maps undefined there, not refused: a model that may meet such a row must keep away from it, as from the Euler angles’ lock, and no band tells it more than the documentation does.

The selections of the discrete maps keep their values and the derivatives of the selected formula finite on both sides of every jump.

Tests#

In crates/skoro-spatial/tests/, at both precisions of the Flex device through precision_tests! wherever a pass is compared, with testing::Tolerance, at points drawn by testing::random and normalized, together with fixed rows: the identity, rotations whose angles sit at 0.90.9 and 1.11.1 times each cutoff, and for the logarithm a row with w<0w < 0. A smooth or removable map is checked at all of them, and at a half-turn about each axis. A discrete map is checked by central differences only at rows at least ten single-precision steps, 0.10.1, from its jumps, which discretizations_jump_cleanly checks instead: log_shorter, the shorter interpolations and the motions’ log_shorter away from w=0w = 0; angle_to away from r=±1r = \pm 1; axis_angle away from the identity; euler away from its lock, which for a proper sequence includes the identity, and from its wrap, α\alpha and γ\gamma at least 0.10.1 from ±π\pm\pi; angle_residual at differences at least 0.10.1 from an odd multiple of π\pi; from_matrix at rows whose largest coordinate beats the next by more than the step; aligned_with away from ⟨q,r⟩=0\langle q, r \rangle = 0.

  • types_are_declared: the three declarations and every composite are defined without error, and register adds three names to a Registry::core() and refuses them a second time. Shows the unreachable! branches are dead.
  • types_pass_the_core_checks: testing::check_embedded and testing::check_volume on Rotation, Pose and ExtendedPose, at the fixed rows and random ones. Shows Proposition 5, Proposition 7 and Proposition 23 as built, with the area formula.
  • chart_is_stereographic: on the host, Q(x, R(x, t)) = t at lengths up to 10310^3; the angle of δ(t)\delta(t) is 4arctan⁡(∣t∣/4)4 \arctan(\lvert t \rvert / 4); π(x⊕t)=π(x)(I+[t]×)+O(∣t∣2)\pi(x \oplus t) = \pi(x)(I + [t]_\times) + O(\lvert t \rvert^2) at ∣t∣=10−3\lvert t \rvert = 10^{-3}; and RR of a base point scaled by 1.011.01 equals RR of the unit one. Shows the chart is the statement’s, and the normalization of the base point.
  • volume_has_the_stated_mass: ∫R3eλ(t)dt=16π2\int_{\R^3} e^{\lambda(t)} \dd t = 16 \pi^2 by quadrature in polar coordinates. Shows the normalization of ν\nu independently of the area formula.
  • group_laws: on random rows, associativity, identity and inverse of the composition, between against inverse and *, and π\pi a homomorphism, the same at qq and −q-q, all against host references written with matrices.
  • actions_are_the_matrix: q * x, unrotate, the action on a Matrix<3, 4> of columns and matrix against the host’s π(q)\pi(q); matrix of a product is the product of the matrices.
  • conjugation_is_exact: (6) at lengths 0.10.1, 11 and 1010.
  • hat_and_vee: [ω]×x=ω×x[\omega]_\times x = \omega \times x; vee inverts hat, and gives the skew part’s vector of a matrix that is not skew.
  • exp_and_log: log inverts exp on the ball of radius 2π2\pi, at lengths up to 66; log_shorter is the same at ±q\pm q, agrees with log where w>0w > 0, and has length at most π\pi; exp at an angular rate integrated against the matrix exponential of [ω]×[\omega]_\times.
  • series_meet_closed_forms: every coefficient of series.rs, as a map of ω\omega or of (n2,w)(n^2, w), against the series summed to convergence below its cutoff and the closed form above, at 0.90.9 and 1.11.1 times the cutoff, within 10−1510^{-15} in double precision; and testing::check_operation on every composite that uses one, at the identity and at both sides of the cutoff. Shows the measured table of Series and cutoffs holds in the code, and that every pass is finite at the identity.
  • composites_pass_check_operation: testing::check_operation on every composite of the crate, at the fixed and random rows, at both precisions: tangent, cotangent and second-order maps against finite differences in the types’ charts. Shows every map has its derivatives of both orders.
  • jacobians_are_the_passes: the tangent pass of rotation::exp at ω\omega, read in the chart at exp(ω), equals so3::jr(ω); of log, so3::jr_inv(log q); of pose::exp and extended_pose::exp, their jr; and each *_inv times its Jacobian is the identity. Shows Proposition 14, and with it (28) in the order of the coordinates here.
  • second_order_agrees_on_rotations: the Hessian pass of a scalar map of a rotation, x↦⟨π(x) a,b⟩x \mapsto \langle \pi(x)\, a, b \rangle, at xx equals that of the same map read in exponential coordinates by finite differences; for a pose they differ by the term the statement names. Shows the second claim of Proposition 14.
  • interpolations: slerp and its variants at t=0t = 0 and t=1t = 1 give the endpoints; the angle from the start grows linearly in tt; slerp_shorter takes the shorter turn where ⟨q1,q2⟩<0\langle q_1, q_2 \rangle < 0 and slerp the longer; angle_to against the host’s arccos⁡((tr⁡π(qˉ1q2)−1)/2)\arccos((\operatorname{tr} \pi(\bar q_1 q_2) - 1)/2); the motions’ interpolations at their endpoints, the screw’s twist constant in tt and the parts’ position linear.
  • constructions: elementary and about against the host’s matrices; axis_angle inverts about and is finite at the identity; from_two_vectors carries aa to bb for random pairs, and is non-finite for opposite pairs whose norms are exact, so that the argument vanishes exactly. Its behaviour at pairs opposite only up to rounding is the ill-conditioning its documentation states, and is not checked.
  • euler_round_trips: for all twelve sequences, intrinsic and extrinsic, euler(from_euler(θ)) is θ\theta modulo 2π2\pi for random angles away from the lock and the wrap, the same for qq and −q-q; the extrinsic rotation equals the product of the fixed axes’ matrices; at an exact lock the angles are finite, γ=0\gamma = 0, and reproduce the rotation, at the exact locks of discretizations_jump_cleanly; for the proper sequences, whose rearrangement is the quaternion itself, at rows within the threshold of the lock, with the vanishing coordinates of size 10−1810^{-18}, the convention γ=0\gamma = 0, reproducing the rotation within tolerance, and at rows just outside it, of size 10−1610^{-16}, the statement’s angles, reproducing it too; for the Tait–Bryan sequences, from_euler at β=±π2\beta = \pm\tfrac\pi2 read back as angles with β\beta and α±γ\alpha \pm \gamma accurate and the rotation reproduced, whether or not the row is selected; Euler::YAW_PITCH_ROLL against a textbook example of yaw, pitch and roll. Shows Proposition 19.
  • angle_residual_is_on_the_circle: at random pairs, angle_residual(a, b) equals a−ba - b brought into (−π,π](-\pi, \pi] on the host, on Real and on Vector<3>; b + angle_residual(a, b) lies in (b−π,b+π](b - \pi, b + \pi] and is aa modulo 2π2\pi; across the wrap of either angle, aa at π−10−5\pi - 10^{-5} and −π+10−5-\pi + 10^{-5} with b=3b = 3, the residual is continuous, changing by 2⋅10−52 \cdot 10^{-5}, and its passes are the same on both sides; and along rotations about zz through the half-turn, at angles π∓10−5\pi \mp 10^{-5}, the residual of the yaw of euler with Euler::YAW_PITCH_ROLL against a reference yaw of 33 is continuous where the yaw itself jumps. Shows (21) and the use of it the mathematics gives.
  • from_matrix_branches: at quaternions whose largest coordinate is each of the four in turn, from_matrix(matrix(q)) is ±q\pm q with that coordinate positive, both through the model and through host::from_matrix; the matrix’s storage order is checked by a rotation about zz alone. Shows (22) and catches a transposed index.
  • alignment: aligned_with and host::align return zz or −z-z, whichever is on the side of the reference, and the same rotation.
  • discretizations_jump_cleanly: for each discrete map, at rows on either side of each of its jumps, closer than a central difference’s step and farther than rounding, the values are those of the formula the side selects, and the tangent, cotangent and second-order passes are finite and equal to the selected formula’s, computed by the same passes over that formula alone. At an exact lock of euler, built in storage so that the vanishing norm is zero exactly, (1,0,1,0)/2(1, 0, 1, 0)/\sqrt 2 for the sequence (x,y,z)(x, y, z), where w−uy=0w - u_y = 0, and quaternions with exact zeros for proper sequences, the angles and every pass are finite. At the wrap of euler, for every sequence, at rows built by host::from_euler with α\alpha, and then γ\gamma, at π−10−5\pi - 10^{-5} and −π+10−5-\pi + 10^{-5} and the other angles away from the lock, the wrapped angle is near π\pi on one side and near −π-\pi on the other, values 2π−2⋅10−52\pi - 2 \cdot 10^{-5} apart, the other two angles agree, and the tangent, cotangent and second-order passes agree across the cut within tolerance. Shows The discretizations of the mathematics: values on both sides, derivatives those of the selected formula.
  • motion_group_laws: the composition, inverse, relative motion and actions of Pose and ExtendedPose against their homogeneous matrices on the host, and matrix a homomorphism.
  • parts_and_products: from_parts and rotation, position (and velocity, pose) invert each other; as_product and from_product are the identity on storage, and the derivative of from_product in charts is diag⁡(I,R⊤)\operatorname{diag}(I, R\transpose).
  • adjoints_conjugate: TExp⁡(ξ)T−1=Exp⁡(Ad⁡(T) ξ)T \Exp(\xi) T^{-1} = \Exp(\operatorname{Ad}(T)\, \xi) for both motions, and T⊕hξ=(1⊕hAd⁡(T)ξ) T+O(h2)T \oplus h\xi = (1 \oplus h \operatorname{Ad}(T) \xi)\, T + O(h^2).
  • motion_exp_and_log: pose::exp and extended_pose::exp against the matrix exponential of the twist on the host; their logarithms invert them; log_shorter the same at ±q\pm q.
  • normal_density_on_rotations: with skoro-normal, the normal’s term on Rotation integrates to one through the chart, ∫R3exp⁡(ℓ(μ⊕t)+λμ(t)) dt=1\int_{\R^3} \exp(\logterm(\mu \oplus t) + \lambda_\mu(t))\, \dd t = 1, by quadrature in polar coordinates with r=4tan⁡(u/4)r = 4 \tan(u/4), for an isotropic and an anisotropic scale.
  • normal_density_on_poses: on Pose, ℓ(μ⊕t)+λμ(t)=log⁡N(t;0,Σ)\logterm(\mu \oplus t) + \lambda_\mu(t) = \log \mathcal N(t; 0, \Sigma) at random tt, which with a global, full chart and a checked volume is the density integrating to one, without a quadrature in six dimensions.
  • normal_draws_on_rotations: over 10510^5 draws, the expectations of three bounded functions of the rotation, through π\pi, agree within five standard errors with their quadratures against p(q)+p(−q)\density(q) + \density(-q) over the hemisphere w>0w > 0. Shows Proposition 8.

The core’s acceptance test is not touched, as the mathematics settles.

Open questions#

None remain.

Revisions#

2026-11-03. Reopened with the mathematics, which now treats the Euler angles at the wrap as well as at the lock and gives the residual on the circle. LOCK is 10−3410^{-34}, chosen by the mathematics’ bound 2arcsin⁡c2 \arcsin \sqrt c below double precision’s rounding, which the earlier 10−3010^{-30} did not meet; Euler angles says why, and that the threshold decides finiteness rather than the round trip. The wrap is taken as atan2’s cut, with the core’s atan2 added to the constraints. angle_residual implements the residual, over a sealed trait of the markers whose values may be angles. Errors and domains no longer promises non-finite values at singular rows: the build found from_two_vectors finite and meaningless at opposite directions that rounding leaves slightly apart, and the same holds near every singular row; a band of refused rows is considered and set aside. The tests add the wrap, the lock within its threshold, the Tait–Bryan lock under rounding, and angle_residual_is_on_the_circle, and constructions checks the non-finite case only where the argument vanishes exactly.

Built on by