feat(units): typed vector MulDt/DivDt + dimension-checked advance_rigid_body #43

Merged
patman merged 2 commits from patman/uom-typed-integrator into main 2026-07-09 23:20:31 +00:00
Owner

What this does

Extends the existing MulDt/DivDt traits to the *Vec3 boundary types (raw-SI compute, not routed through the dim currency / AngleKind — critique C8), so the jerk-constant polynomial integration becomes dimension-checked: jerk.mul_dt(dt) steps up the integral chain (m/s³ → m/s² → m/s → m), and the wrong chain would not type-check. Then rewrites advance_linear_vec3 and the angular-rate (ω, α) update in advance_rigid_body using them.

The quaternion-exp Lie step stays raw f64 (Ring 3) — byte-for-byte unchanged. The angular mul_dt chain stops at AngularVelocityVec3 (no AngleVec3; finite rotations live on SO(3) via the quaternion).

Verification

buck2 test //common:common-tests107 passed (5 new vector-op tests). All existing integrator proptests pass unchanged (rigid_body_bisected_matches_single_step, ..._forward_then_backward_..., ..._pure_rotation_..., etc.) — the behavior-preserving gate. Two independent adversarial reviews approved (high confidence).

⚠️ Decision point — floating-point rounding

The mul_dt chain reassociates the polynomial products (e.g. ((j·t)·t)·0.5 vs the old (0.5·j)·(t·t)). It is algebraically exact and within approx_eq tolerance, but not bit-identical to the previous grouping (measured ≤4 ULP on random inputs). The new code is fully deterministic run-to-run; the only difference is vs the prior grouping. For a pre-release system with no frozen baselines this is almost certainly fine, but flagging it since KGROO values determinism (digital-twin recordings / cross-platform). If bit-exact preservation is wanted, I can match the original product grouping (at the cost of the elegant mul_dt expression) — say the word.

Hot-path note (C10)

Vector ops use only the const SI accessors (as_meters/as_rad_per_s family via to_si_3), never CNC-unit readouts (runtime uom multiplies). A codegen/bench confirmation that the typed step inlines to the hand-written arithmetic is the one remaining gate item I could not run under buck2 tonight (trybuild-style/cargo-asm); recommend a quick bench before relying on it in the 1 kHz loop.

Stack position

PR 3 → base #42. Night-session build; see docs/superpowers/cam-typed-layer-design.md.

## What this does Extends the existing `MulDt`/`DivDt` traits to the `*Vec3` boundary types (raw-SI compute, **not** routed through the `dim` currency / `AngleKind` — critique C8), so the jerk-constant polynomial integration becomes **dimension-checked**: `jerk.mul_dt(dt)` steps up the integral chain (`m/s³ → m/s² → m/s → m`), and the wrong chain would not type-check. Then rewrites `advance_linear_vec3` and the angular-rate (ω, α) update in `advance_rigid_body` using them. The quaternion-exp **Lie step stays raw f64 (Ring 3)** — byte-for-byte unchanged. The angular `mul_dt` chain stops at `AngularVelocityVec3` (no `AngleVec3`; finite rotations live on SO(3) via the quaternion). ## Verification `buck2 test //common:common-tests` → **107 passed** (5 new vector-op tests). **All existing integrator proptests pass unchanged** (`rigid_body_bisected_matches_single_step`, `..._forward_then_backward_...`, `..._pure_rotation_...`, etc.) — the behavior-preserving gate. Two independent adversarial reviews approved (high confidence). ## ⚠️ Decision point — floating-point rounding The `mul_dt` chain reassociates the polynomial products (e.g. `((j·t)·t)·0.5` vs the old `(0.5·j)·(t·t)`). It is **algebraically exact** and within `approx_eq` tolerance, but **not bit-identical** to the previous grouping (measured ≤4 ULP on random inputs). The new code is fully deterministic run-to-run; the only difference is vs the prior grouping. For a pre-release system with no frozen baselines this is almost certainly fine, but flagging it since KGROO values determinism (digital-twin recordings / cross-platform). If bit-exact preservation is wanted, I can match the original product grouping (at the cost of the elegant `mul_dt` expression) — say the word. ## Hot-path note (C10) Vector ops use only the `const` SI accessors (`as_meters`/`as_rad_per_s` family via `to_si_3`), never CNC-unit readouts (runtime uom multiplies). A codegen/bench confirmation that the typed step inlines to the hand-written arithmetic is the one remaining gate item I could not run under buck2 tonight (trybuild-style/cargo-asm); recommend a quick bench before relying on it in the 1 kHz loop. ## Stack position PR 3 → base #42. Night-session build; see `docs/superpowers/cam-typed-layer-design.md`.
Extend the existing MulDt/DivDt traits to the *Vec3 boundary types (raw-SI
compute, no AngleKind routing per critique C8) so the jerk-constant polynomial
integration becomes dimension-checked: jerk.mul_dt(dt) steps up the integral
chain (m/s^3 -> m/s^2 -> m/s -> m). Rewrite advance_rigid_body's linear and
angular-rate updates with them; the quaternion-exp Lie step stays raw f64 (Ring 3).
Behavior-preserving — existing integrator proptests are the gate.

Co-authored-by: patman-assist <patrick-ai@kgroo.co>
patman changed target branch from patman/uom-rotation-direction to main 2026-07-09 23:11:50 +00:00
merge: main into uom-typed-integrator (import-adjacency conflict)
Some checks failed
CI / build-test (pull_request) Has been cancelled
c6be065f6b
patman merged commit a6734af871 into main 2026-07-09 23:20:31 +00:00
Sign in to join this conversation.
No description provided.