Maths Applied1.7

All books

S08 — From SymPy to WebAssembly, and from the corner to the car

The capstone of the S track, in two parts. Part one follows the corner from its symbolic derivation to the WebAssembly kernel the book runs in the browser: what is compiled, what stays free, how the browser is shown to agree with Python, and what the derivation costs against the evaluation. Part two steps back from the corner to the car: what a four-corner model costs, what roll and load transfer add, and what a bigger model still cannot answer. It closes the track with a method-choice review.

Sources: solvers/otkd/docs/wasm.md and solvers/ABI.md (the two kernel ABIs), the committed bundle under books/maths-applied/docs/assets/data/otkd/, and §1.7 The full vehicle with the Chapter 1 Review in books/maths-applied. The solver numbers are otkd's own, run live and cached.

The question. The book solves the corner in a browser with every geometry number free. What was compiled once, what is left free, how do we know the browser and Python agree, and why does the same trick not simply scale to the whole car?

By the end you can:

  • run the derive → CSE → print pipeline on a toy, and say what CSE changes and what it does not
  • read a committed kernel's arena layout and find any Jacobian entry in MEM
  • replay a selftest and say when agreement must be bit for bit and when to a tolerance
  • say why the source is byte-reproducible but the .wasm is tested by behaviour
  • weigh derivation time against evaluation time, and say where the derivation belongs
  • estimate load transfer and roll, and turn the corner's camber into camber to the road
  • for a suspension question, name the model, the method and the check

Assumes: M01–M08 and S01–S07: Newton, least squares and the SVD, energy minimisation, time stepping, Monte Carlo, and the corner models of books/maths-applied Chapter 1.

How to use it: predict before you reveal, commit before you check, and move the controls until the equation's behaviour stops surprising you.

Predict first. Try first: a car with four of these corners and a body has 91 unknowns instead of 21. What stops the book shipping it as an interactive browser kernel, the way it ships one corner?

Choose a prediction

Check answer (without scripting)

Answer: Deriving it: the symbolic step takes minutes for each topology. dynamics.md §7 measured the derivation at minutes and names it, not the integration, as the wall. Every change of topology pays it again, before CSE and rustc have even started.

Warm-up: remember

1. The quarter car is Mq¨=f−ΦqTλM\ddot q = f - \Phi_q^{\mathsf T}\lambda with Φ(q)=0\Phi(q) = 0. Why can an ODE solver not take it as it stands?

Question 1
How sure?

2. otkd stores compliance cc rather than stiffness k=1/ck = 1/c. What does that buy?

Question 2
How sure?

3. Drive a square mechanism towards a fold, where the drive angle reaches its limit. With δ\delta the distance to the fold, the smallest singular value of JJ falls like

Question 3
How sure?

Show answers and explanations

1. No equation fixes the multiplier until the constraint is differentiated twice. Φ(q)=0\Phi(q) = 0 contains no λ\lambda and no q¨\ddot q. Differentiate it twice to Φqq¨=γ\Phi_q\ddot q = \gamma and, with the dynamics, the saddle-point system fixes q¨\ddot q and λ\lambda together: index 3 reduced to index 1.

2. c = 0 is the rigid row exactly, but for small c > 0 the residual still divides by c. The spring term g/cg/c is in the stationarity rows, so the Newton matrix carries aaT/ca a^{\mathsf T}/c and its condition number grows like 1/c1/c.

3. the square root of delta. δ≈cs2\delta \approx c s^2 at a fold and σmin⁡∝s\sigma_{\min} \propto s, so σmin⁡∝δ\sigma_{\min} \propto \sqrt\delta and κ∝δ−1/2\kappa \propto \delta^{-1/2}.

1. The same steps on a toy: derive, eliminate, print

Setting: the problem, its sets and its symbols

Problem. Given k∈N≥1k \in \mathbb{N}_{\ge 1} links with lengths L∈R>0kL \in \mathbb{R}^{k}_{>0} and a target (X,Y)∈R2(X, Y) \in \mathbb{R}^2, take the residual Φ:Rk→R2\Phi : \mathbb{R}^k \to \mathbb{R}^2 and its Jacobian J=∂Φ/∂θ∈R2×kJ = \partial\Phi/\partial\theta \in \mathbb{R}^{2 \times k}. Find a straight-line program w1,…,wrw_1, \dots, w_r that evaluates every entry of E=(Φ,J)E = (\Phi, J) exactly, and compare its operation count cc with that of EE as written.

Symbol In Meaning
kk N≥1\mathbb{N}_{\ge 1} number of links (data)
θ\theta Rk\mathbb{R}^{k} relative link angles, rad (the unknowns)
LL R>0k\mathbb{R}^{k}_{>0} link lengths, m (data)
(X,Y)(X, Y) R2\mathbb{R}^{2} target for the tip, m (data)
x,yx, y Rk→R\mathbb{R}^{k} \to \mathbb{R} tip coordinates as functions of θ\theta, m
Φ\Phi Rk→R2\mathbb{R}^{k} \to \mathbb{R}^{2} residual (x−X, y−Y)(x - X,\ y - Y), m
JJ R2×k\mathbb{R}^{2 \times k} ∂Φ/∂θ\partial\Phi/\partial\theta, m/rad
EE expressions2+2k\text{expressions}^{2 + 2k} the residual rows followed by the Jacobian entries
w1,…,wrw_1, \dots, w_r R\mathbb{R} CSE replacements, assigned in evaluation order; r∈Nr \in \mathbb{N}
cc expressions→N\text{expressions} \to \mathbb{N} operation count, SymPy's count_ops
How these symbols connect

Given the data kk, L∈R>0kL \in \mathbb{R}^{k}_{>0} and (X,Y)∈R2(X, Y) \in \mathbb{R}^2, the planar chain maps the relative angles θ∈Rk\theta \in \mathbb{R}^k to tip coordinates (x(θ),y(θ))(x(\theta), y(\theta)), yielding the residual Φ(θ)∈R2\Phi(\theta) \in \mathbb{R}^2 (m) and its Jacobian J(θ)∈R2×kJ(\theta) \in \mathbb{R}^{2 \times k} (m/rad). Collecting all 2+2k2 + 2k symbolic entries into EE lets common-subexpression elimination extract shared subtrees into rr ordered temporaries w1,…,wrw_1, \dots, w_r without changing the numerical map, and the counter cc compares the operation counts before and after elimination.

Symbol-by-symbol notes
$\theta$ — relative, not world, angles

Each entry θj\theta_j is the angle of link jj relative to link j−1j - 1 (with θ1\theta_1 measured from the xx-axis), in radians. The orientation of link jj in the plane is therefore the cumulative sum ∑i≤jθi\sum_{i \le j} \theta_i, so every earlier angle enters every later link's sine and cosine.

$\Phi$ and $J$ — residual and Jacobian units

The residual Φ(θ)=(x(θ)−X, y(θ)−Y)\Phi(\theta) = (x(\theta) - X,\ y(\theta) - Y) is in metres and vanishes when the tip reaches (X,Y)(X, Y). Differentiating with respect to angles in radians gives J=∂Φ/∂θJ = \partial\Phi/\partial\theta in m/rad, the units of a lever arm.

$E$ — symbolic expressions, not floating-point arrays

Rather than numbers at a single pose, EE is a flat list of 2+2k2 + 2k SymPy expression trees (the two residual rows followed by the 2k2k entries of JJ). Passing Φ\Phi and JJ together into CSE allows repeated subtrees to be shared across residual and derivative entries alike.

$w\lt em>1, \dots, w\lt /em>r$ — straight-line CSE temporaries

Each wiw_i names a repeated subexpression built from the inputs (θ,L,X,Y)(\theta, L, X, Y) and earlier temporaries w1,…,wi−1w_1, \dots, w_{i-1}, with no loops or branches. Evaluating w1,…,wrw_1, \dots, w_r in sequence and then the reduced outputs computes the exact same mathematical map as EE.

$c$ — SymPy's operation count

SymPy's count_ops tallies arithmetic operators and elementary function calls across an expression tree. After CSE, the total count sums count_ops over all rr replacement definitions plus the reduced outputs, so each shared subtree is counted once.

otkd turns a model into a kernel in four steps:

topology + geometry ─► Φ(q, g, t), J = ∂Φ/∂q ─► CSE ─► Rust ─► wasm32 ─► kernel.js
                         (SymPy, once)        circuit  source  module   (base64)

Take a planar chain of kk links of lengths LjL_j at relative angles θj\theta_j. The tip sits at

x=∑j=1kLjcos⁡(∑i≤jθi),y=∑j=1kLjsin⁡(∑i≤jθi),x = \sum_{j=1}^{k} L_j \cos\Big(\sum_{i \le j} \theta_i\Big), \qquad y = \sum_{j=1}^{k} L_j \sin\Big(\sum_{i \le j} \theta_i\Big),

and the residual asks it to reach a target: Φ=(x−X, y−Y)\Phi = (x - X,\ y - Y). Differentiating gives ∂x/∂θm=−∑j≥mLjsin⁡(⋅)\partial x / \partial \theta_m = -\sum_{j \ge m} L_j \sin(\cdot), a tail sum of the same sines that yy uses, so the 2k2k Jacobian entries repeat one another's work.

Common-subexpression elimination (CSE) walks the expression trees, gives each repeated subtree a name, and returns (replacements, reduced): assignments x0 = …, x1 = … in evaluation order, then the outputs in terms of them. The map is unchanged; only the program that evaluates it is. sympy.printing.rust_code then prints each line as Rust.

Predict first. With 8 links, the two residual rows and their 2×82 \times 8 Jacobian take 648 operations as SymPy writes them. After CSE, about how many?

Choose a prediction

Check answer (without scripting)

Answer: about 60. The cost after CSE grows linearly in the links, about eight operations per link, while the written-out form grows like the square.

Reveal result (lock in your prediction above first)
12.754.56.258-31.5148328507686before CSEafter CSElinks koperations
links before CSE after CSE
1 11 7
2 34 15
3 73 23
4 132 31
5 215 39
6 326 47
7 469 55
8 648 63

With k=2k = 2: 34 operations before, 15 after, in 5 assignments. At a random point the two forms agree exactly: the same map, evaluated in a different order.

let x0 = theta0 + theta1;
let x1 = L1*x0.cos();
let x2 = L0*theta0.cos() + x1;
let x3 = L1*x0.sin();
let x4 = L0*theta0.sin() + x3;
out[0] = -X + x2;
out[1] = -Y + x4;
out[2] = -x4;
out[3] = -x3;
out[4] = x2;
out[5] = x1;

The integer-literal trap. SymPy prints 2*x; Rust refuses {integer} * f64. otkd's printer prints every integer as 2.0 except a .powi(…) exponent; array indices live in symbol names and never reach it. On 2θ0+θ02+Y22\theta_0 + \sqrt{\theta_0^2 + Y^2}:

rust_code: 2*theta0 + (Y.powi(2) + theta0.powi(2)).sqrt()
otkd:      2.0*theta0 + (Y.powi(2) + theta0.powi(2)).sqrt()
source: `open_textbook.otkd.emitters.wasm._cse_block` — `solvers/otkd/src/open_textbook/otkd/emitters/wasm.py:687`
def _cse_block(problem: Problem, n: int, rows: int) -> tuple[list[str], list[str]]:
    mapping = _symbol_map(problem)
    # Row-major: jac[row*N + col]. The two-leg model has more rows than unknowns, so the
    # iteration order matters and the square case must use the same layout.
    flat = [problem.jacobian_expr[i, j] for i in range(rows) for j in range(n)]
    exprs = [expression.xreplace(mapping) for expression in [*problem._exprs, *flat]]
    replacements, reduced = cse(exprs, optimizations="basic")
    body = [f"    let {symbol} = {_rust(expression)};" for symbol, expression in replacements]
    out = [f"    out[{i}] = {_rust(reduced[i])};" for i in range(rows)]
    out += [f"    jac[{k}] = {_rust(reduced[rows + k])};" for k in range(n * rows)]
    return body, out
source: `open_textbook.otkd.emitters.wasm._rust` — `solvers/otkd/src/open_textbook/otkd/emitters/wasm.py:751`
def _rust(expression) -> str:
    return _Printer().doprint(expression)
When common-subexpression elimination breaks
  • Assumes: the expressions are fixed at build time and evaluated as given, with no branches
  • When it fails: a branch (a max, a contact that opens) has no straight-line form; and expand before CSE can turn a short product into a long sum that cancels
  • Check: evaluate the plain and the eliminated forms at random points: they should agree to a few units of ϵ\epsilon relative

2. The real kernel, read from the committed bundle

Setting: the problem, its sets and its symbols

Problem. Given the committed kernel's blocks b∈Bb \in B with sizes sb∈Ns_b \in \mathbb{N}, laid end to end in the arena A∈RN\mathcal{A} \in \mathbb{R}^{N}, find each offset obo_b, the arena index of any Jacobian entry JijJ_{ij}, and the set S⊆{0,…,mn−1}S \subseteq \{0, \dots, mn - 1\} of entries the kernel computes as other than a literal zero.

Symbol In Meaning
BB finite set\text{finite set} blocks q, g, t, out, jac, met, world, pts, axs, num, in order
sbs_b N\mathbb{N} size of block bb, in f64 slots
obo_b N\mathbb{N} offset of block bb: the sum of the sizes before it, slots
A\mathcal{A} RN\mathbb{R}^{N} the arena MEM, N=∑bsbN = \sum_b s_b f64 slots
n,mn, m N\mathbb{N} unknowns (seven per moving body) and residual rows
qq Rn\mathbb{R}^{n} pose: positions in m, unit quaternions dimensionless (unknowns)
gg RG\mathbb{R}^{G} geometry numbers: m, unit axes, compliances in m/N (data)
tt RA\mathbb{R}^{A} drive values, rad (data)
Φ\Phi Rn×RG×RA→Rm\mathbb{R}^{n} \times \mathbb{R}^{G} \times \mathbb{R}^{A} \to \mathbb{R}^{m} residual, m or dimensionless by row
JJ Rm×n\mathbb{R}^{m \times n} ∂Φ/∂q\partial\Phi/\partial q, stored row-major: entry (i,j)(i, j) at ojac+in+jo_{\mathrm{jac}} + i n + j
SS {0,…,mn−1}\{0, \dots, mn - 1\} flat indices of the computed entries
How these symbols connect

The ten blocks b∈Bb \in B sit end to end in one contiguous f64 arena A∈RN\mathcal{A} \in \mathbb{R}^N, where each block's slot count sbs_b fixes the next block's starting offset obo_b and the total length N=∑bsbN = \sum_b s_b. A host page writes inputs into q, g (via pack() from pts, axs, num) and t, then calls compute() to write Φ(q,g,t)\Phi(q, g, t) into out and J=∂Φ/∂qJ = \partial\Phi/\partial q row-major into jac. Comparing the flat indices S⊆{0,…,mn−1}S \subseteq \{0, \dots, mn - 1\} computed in kernel.rs against Python's symbolic Jacobian ties the compiled arena layout directly to the linkage topology.

Symbol-by-symbol notes
$s\lt em>b$, $o\lt /em>b$ and $\mathcal{A}$ — f64 slots vs byte offsets

Every size sbs_b and offset obo_b in kernel.json counts 64-bit floating-point (f64) slots, not bytes. WebAssembly exports MEM.value as a byte address, so JavaScript divides by 8 before indexing slot obo_b in a Float64Array view.

$q$, $g$ and $t$ — unknowns, free geometry and drives

The unknown vector q∈Rnq \in \mathbb{R}^n holds seven pose numbers per moving body (three positions in m and a dimensionless unit quaternion), g∈RGg \in \mathbb{R}^G holds the resolved geometry parameters (coordinates, unit axes, compliances), and t∈RAt \in \mathbb{R}^A holds drive values in radians. Keeping gg and tt in the arena lets a page move pivots or drives without recompiling.

pts, axs, num vs g — raw inputs and pack()

The blocks pts, axs and num receive raw editable points, axes and scalar numbers from the page, while g stores the completed internal representation (such as orthonormal site frames) that compute() reads. Calling pack() fills g from those raw blocks using the same rules as the Python loader.

$J$ and $o_{\mathrm{jac}} + in + j$ — row-major indexing

With 0-based row index i∈{0,…,m−1}i \in \{0, \dots, m - 1\} and column index j∈{0,…,n−1}j \in \{0, \dots, n - 1\}, entry Jij=∂Φi/∂qjJ_{ij} = \partial\Phi_i/\partial q_j sits at flat index in+jin + j within jac, and therefore at slot ojac+in+jo_{\mathrm{jac}} + in + j in A\mathcal{A}.

$S$ — structurally computed Jacobian slots

The set S⊆{0,…,mn−1}S \subseteq \{0, \dots, mn - 1\} lists the flat indices in+jin + j for which kernel.rs emits a computed expression rather than the literal constant 0.0. Its membership is fixed at build time by which bodies each constraint row couples.

The book ships one kernel per model under models/<name>/kernel/. For the wishbone (dw-1dof, ABI otkd-kernel-2, solver square):

file bytes
kernel.js 110377
kernel.json 3686
kernel.rs 186480
kernel.wasm 76476
provenance.json 1046

kernel.json is the contract a page reads. The whole state is one f64 array, MEM, exported as a global holding its byte address; offsets are indices into MEM, so JavaScript starts at instance.exports.MEM.value / 8. Nothing is allocated, and the sizes are fixed when the kernel is emitted:

block offset size offset = sum of sizes before
q 0 21 0
g 21 67 21
t 88 1 88
out 89 21 89
jac 110 441 110
met 551 10 551
world 561 30 561
pts 591 30 591
axs 621 6 621
num 627 1 627

Every offset is the sum of the sizes before it: True. q holds the 21 pose unknowns (seven per moving body), g the 67 resolved geometry numbers, t the drive. The page writes raw points into pts and axs and calls pack(), which completes each site's frame and fills g with the same rules as the Python loader. So the module is topology-scoped, not geometry-scoped: move any pivot and the same kernel solves it; add a joint and it is a new kernel.

The exports are design, pack, compute (residual into out, Jacobian into jac), solve(iters) (Newton, compiled in, returning ∥r∥∞\|r\|_\infty or −1-1 if singular), metrics and world.

Predict first. The jac block holds all 21 × 21 = 441 entries of ∂Φ/∂q\partial\Phi/\partial q, row-major. How many does the generated kernel compute as something other than a literal zero?

Choose a prediction

Check answer (without scripting)

Answer: about a third. A joint row touches one or two bodies of seven coordinates each, and a norm row touches four. The pattern is known at build time, from the derivation.

Reveal result (lock in your prediction above first)
0616263646513613713813913102011201220132014201520162017618619132020unknown (column)

161 of 441 entries are computed; 280 are the literal 0.0. Python's symbolic Jacobian has its non-zeros in exactly the same places: True. The block structure is the topology: rows of a joint between ground and one arm touch that arm's seven columns, the knuckle's rows touch two bodies, the norm rows touch four quaternion columns. Before those outputs, compute_inner runs 1239 straight-line assignments, the CSE replacements in evaluation order.

source: books/maths-applied/docs/assets/data/otkd/models/double-wishbone/kernel/kernel.rs:308-318

The first CSE assignments.

fn compute_inner(q: &[f64; N], g: &[f64; G], t: &[f64; A], out: &mut [f64; M], jac: &mut [f64; N*M]) {
    let x0 = g[39]*g[3];
    let x1 = g[42]*g[4];
    let x2 = g[45]*g[5];
    let x3 = q[3].powi(2);
    let x4 = q[4].powi(2);
    let x5 = q[5].powi(2);
    let x6 = q[6].powi(2);
    let x7 = 2.0*q[3];
    let x8 = g[39]*q[6];
    let x9 = g[4]*x8;
source: books/maths-applied/docs/assets/data/otkd/models/double-wishbone/kernel/kernel.rs:2013-2022

The export a page calls: copy in, evaluate, copy out.

pub extern "C" fn compute() {
    let q: [f64; N] = read(O_Q);
    let g: [f64; G] = read(O_G);
    let t: [f64; A] = read(O_T);
    let mut out = [0.0f64; M];
    let mut jac = [0.0f64; N*M];
    compute_inner(&q, &g, &t, &mut out, &mut jac);
    write(O_OUT, &out);
    write(O_JAC, &jac);
}

Provenance. provenance.json records the generator, rustc, and the SHA-256 of the four config files and the wasm at emission time. Recomputed now:

model sources matching provenance differs wasm matches provenance
double-wishbone 4 / 4 — yes
double-wishbone-compliant 4 / 4 — yes
double-wishbone-two-leg 4 / 4 — yes
double-wishbone-ubj 4 / 4 — yes
four-corner-multilink 4 / 4 — yes
four-corner-tyre-spring 4 / 4 — yes
quarter-car 4 / 4 — yes
ride-height 4 / 4 — yes

Every shipped source matches the digest recorded when its kernel was emitted.

When a fixed arena breaks
  • Assumes: the page and the module agree on every block's offset and size
  • When it fails: a fresh kernel.json beside a stale .wasm reads jac from the wrong slots, and the numbers look plausible
  • Check: the ABI string (otkd-kernel-2), and for ot-solve the FNV-1a layout hash the loader compares with the manifest

3. Proving the browser and Python agree

Setting: the problem, its sets and its symbols

Problem. Given a recorded native run of newton-root (parameters x0,λx_0, \lambda, step count KK, recorded outputs y∗∈RMy^{*} \in \mathbb{R}^{M}), compute a replay y∈RMy \in \mathbb{R}^{M} by the same operations in the same order and find max⁡i∣yi−yi∗∣\max_i \lvert y_i - y^{*}_i \rvert; also compute the layout hash h(s)h(s) of the block sizes. For an otkd kernel, find whether ∥Φwasm−Φpy∥∞≤τ\lVert \Phi_{\mathrm{wasm}} - \Phi_{\mathrm{py}} \rVert_\infty \le \tau.

Symbol In Meaning
ff R→R\mathbb{R} \to \mathbb{R} f(x)=x3−2x−5f(x) = x^3 - 2x - 5, dimensionless
x0x_0 [−4,4][-4, 4] starting value (parameter)
λ\lambda [0.1,1.5][0.1, 1.5] damping factor, dimensionless (parameter)
xkx_k R\mathbb{R} iterates, k=0,…,Kk = 0, \dots, K
KK N\mathbb{N} steps recorded in the case
y∗,yy^{*}, y RM\mathbb{R}^{M} the out and diag blocks, recorded and replayed; MM slots
F\mathbb{F} ⊂R\subset \mathbb{R} the IEEE 754 doubles; each operation rounds into it
ss N4\mathbb{N}^{4} sizes of params, state, out, diag, slots
hh N4→{0,…,232−1}\mathbb{N}^{4} \to \{0, \dots, 2^{32} - 1\} FNV-1a over the sizes' little-endian bytes
Φwasm,Φpy\Phi_{\mathrm{wasm}}, \Phi_{\mathrm{py}} Rm\mathbb{R}^{m} an otkd residual from the kernel and from Python
τ\tau R>0\mathbb{R}_{>0} a conformance tolerance, in the row's units
How these symbols connect

For newton-root, the parameters (x0,λ)(x_0, \lambda) and step count KK run damped Newton iteration on f(x)=x3−2x−5f(x) = x^3 - 2x - 5 in IEEE 754 double precision F\mathbb{F}, filling the MM slots of out and diag so the Python replay yy can be compared against the recorded native run y∗y^{*}. Alongside this numerical replay, hashing the four block sizes s∈N4s \in \mathbb{N}^4 through h(s)h(s) verifies that the manifest and binary agree on the arena layout. For an otkd kernel, conformance is checked by comparing Φwasm\Phi_{\mathrm{wasm}} against the Python reference Φpy\Phi_{\mathrm{py}} in the infinity norm against a tolerance τ\tau.

Symbol-by-symbol notes
$\lambda$ — damping factor, not a Lagrange multiplier

In newton-root, λ∈[0.1,1.5]\lambda \in [0.1, 1.5] scales each Newton step, xk+1=xk−λf(xk)/f′(xk)x_{k+1} = x_k - \lambda f(x_k)/f'(x_k): λ=1\lambda = 1 is full Newton, λ<1\lambda \lt 1 under-relaxes and λ>1\lambda > 1 over-relaxes. It is dimensionless and unrelated to the constraint multipliers of S07.

$y^{*}$ and $y$ — concatenated out and diag slots

Each selftest case packs the kernel's out block (iterate history, residual history and sampled curve points) together with its diag block (step count, last residual and convergence flag) into one vector of MM floats. Checking max⁡i∣yi−yi∗∣\max_i \lvert y_i - y^{*}_i \rvert compares every recorded slot, not only the final iterate xKx_K.

$\mathbb{F}$ — IEEE 754 binary64 doubles

The set F⊂R\mathbb{F} \subset \mathbb{R} consists of 64-bit IEEE 754 floating-point numbers (f64 in Rust and WebAssembly, float in CPython). Because each operation rounds back into F\mathbb{F}, the replayed vector yy depends on both the operations executed and their exact evaluation order.

$s$ and $h(s)$ — 32-bit FNV-1a layout hash

The four-tuple ss lists the slot counts of params, state, out and diag in order, each encoded as a 4-byte little-endian unsigned integer before hashing with FNV-1a. The resulting 32-bit digest h(s)h(s) guards the ABI boundary so a fresh manifest cannot silently drive a stale binary.

$\Phi\lt em>{\mathrm{wasm}}$, $\Phi\lt /em>{\mathrm{py}}$ and $\tau$ — tolerance-based conformance

For an otkd kernel, Φwasm\Phi_{\mathrm{wasm}} is evaluated in WebAssembly and Φpy\Phi_{\mathrm{py}} in Python at the same inputs (q,g,t)(q, g, t). The conformance check verifies that their worst-case component discrepancy stays within τ\tau, measured in each residual row's units.

The repository has two kernel ABIs. otkd's (otkd-kernel-2, above) is generated from a derivation. solvers/ABI.md (version 1) is the hand-written ot-solve family behind books/numerical-methods: an arena of four blocks params | state | out | diag, seven exports, and a status code instead of a trap. Its manifest.json names every output by block and offset, and selftest.json records native runs that scripts/check-solvers.mjs replays through the page's own loader, catching a stale artefact, a wrong offset, the wrong endianness or a broken base64 string.

newton-root iterates x←x−λf(x)/f′(x)x \leftarrow x - \lambda f(x)/f'(x) on f(x)=x3−2x−5f(x) = x^3 - 2x - 5. Its blocks: params 2, state 3, out 384, diag 4; 2 recorded cases. A Python replay of init and step is below; the question is how closely it must match.

Predict first. newton-root is marked exact: true. Replaying its selftest cases in Python, with the same operations in the same order, how closely should the outputs match the recorded run?

Choose a prediction

Check answer (without scripting)

Answer: bit for bit, every slot. Its only operations are +−×÷+ - \times \div, each correctly rounded by IEEE 754. Same inputs, same order, same doubles, on any conforming platform.

Reveal result (lock in your prediction above first)

| case | slots compared | identical | largest |difference| | root | | --- | --- | --- | --- | --- | | from 3, undamped | 388 | 388 | 0.0e+00 | 2.094551481542347 | | from -3, undamped | 388 | 388 | 0.0e+00 | 2.094551481542327 |

The layout hash, FNV-1a over the four block sizes, is 4224630315 here and 4224630315 in the manifest: True. A page refuses a module whose hash differs, so a fresh manifest beside a stale wasm cannot be mixed silently.

otkd's conformance is behavioural. tests/test_wasm.py runs each otkd kernel under node against the Python engine, with tolerances wasm.md §5 states: poses 1e-9, residual and Jacobian < 1e-12, looser for compliant and dynamics kernels. These kernels call sqrt and atan2 and evaluate a CSE-reordered program, so they agree to a tolerance, not to the bit. Python is the reference: the emitter never re-derives. It prints the same SymPy expressions the engine lambdifies, so a disagreement cannot be a second opinion. It means the committed artefact is stale.

The source is reproducible; the binary is tested by behaviour. Two emissions of kernel.rs and kernel.json are byte-identical, because they depend only on the derivation and the printer. The .wasm depends on rustc's version and flags, so its hash would prove only which toolchain built it; its behaviour is what is tested. Here the emitter re-ran in memory for the world() and metrics() blocks of the wishbone (120 lines): found verbatim in the committed file, True.

What CSE bought on the real corner. Written out, the 21 rows take 11,313 operations and the Jacobian 29,653 (SymPy's count_ops), 40,966 in all. The committed compute_inner has about 23,675 arithmetic operators and calls, counted in its text. wasm.md §1 quotes about 7 000 operations after CSE, which this count does not reproduce; its "1 350 nodes" is the size of the replacement list before otkd renames the symbols.

Press the button to re-emit and compare every byte.

When a selftest replay breaks
  • Assumes: the recorded run and the replay evaluate the same operations in the same order
  • When it fails: a transcendental call (sin, atan2) or a fused multiply–add can move the last bit, so an exact comparison fails without a bug
  • Check: exact in the manifest: bit for bit when true, 1e-12 relative when false

4. Derivation once, evaluation many times

Setting: the problem, its sets and its symbols

Problem. Given the wishbone's derivation time TdT_d and per-call costs tΦ,tJ,tFD,tframet_\Phi, t_J, t_{\mathrm{FD}}, t_{\mathrm{frame}}, find the cost C(N)=Td+N tframeC(N) = T_d + N\,t_{\mathrm{frame}} of solving NN frames, and compare JJ with the forward difference J:,jFD=(Φ(q+hej)−Φ(q))/hJ^{\mathrm{FD}}_{:,j} = (\Phi(q + h e_j) - \Phi(q))/h, j=1,…,nj = 1, \dots, n.

Symbol In Meaning
NN N\mathbb{N} frames solved (the slider)
TdT_d R>0\mathbb{R}_{>0} derivation: SymPy, symbolic Jacobian, lambdify, s per topology
tΦ,tJ,tFDt_\Phi, t_J, t_{\mathrm{FD}} R>0\mathbb{R}_{>0} one residual, symbolic Jacobian, forward-difference Jacobian, s
tframet_{\mathrm{frame}} R>0\mathbb{R}_{>0} one Newton frame from the neighbouring pose, s
tkernelt_{\mathrm{kernel}} R>0\mathbb{R}_{>0} one kernel frame, s, as wasm.md §1 reports it
CC N→R>0\mathbb{N} \to \mathbb{R}_{>0} total time for NN frames, s
qq Rn\mathbb{R}^{n} pose, nn unknowns
Φ\Phi Rn→Rm\mathbb{R}^{n} \to \mathbb{R}^{m} residual at fixed g,tg, t
J,JFDJ, J^{\mathrm{FD}} Rm×n\mathbb{R}^{m \times n} exact and forward-difference Jacobians
hh R>0\mathbb{R}_{>0} difference step, 10−710^{-7} in each coordinate's units
eje_j Rn\mathbb{R}^{n} jj-th unit vector
How these symbols connect

The cost model separates the one-off per-topology derivation time TdT_d (s) from the per-frame evaluation cost tframet_{\mathrm{frame}} (s, or tkernelt_{\mathrm{kernel}} in WebAssembly), combining them into the affine total C(N)=Td+N tframeC(N) = T_d + N\,t_{\mathrm{frame}} over NN solved frames. Inside a Newton frame at pose q∈Rnq \in \mathbb{R}^n, one residual Φ(q)\Phi(q) costs tΦt_\Phi, while forming the m×nm \times n Jacobian costs either tJt_J via the lambdified symbolic expression JJ or tFDt_{\mathrm{FD}} via forward differences JFDJ^{\mathrm{FD}} using step hh along each unit vector eje_j.

Symbol-by-symbol notes
$T\lt em>d$ vs $t\lt /em>{\mathrm{frame}}$ and $t_{\mathrm{kernel}}$ — fixed vs marginal cost

Derivation time TdT_d covers building Φ\Phi, differentiating symbolically to obtain JJ, and lambdifying both, paid once per topology regardless of NN. By contrast, tframet_{\mathrm{frame}} (Python) and tkernelt_{\mathrm{kernel}} (WebAssembly) are paid on every slider tick, giving an amortised cost per frame of C(N)/N=Td/N+tframeC(N)/N = T_d/N + t_{\mathrm{frame}}.

$t\lt em>\Phi$, $t\lt /em>J$ and $t_{\mathrm{FD}}$ — per-call Jacobian timings

All three timings are measured in seconds per call at the same solved pose qq with fixed (g,t)(g, t). While tJt_J times one call to the lambdified symbolic Jacobian, tFDt_{\mathrm{FD}} times evaluating Φ(q)\Phi(q) once plus Φ(q+hej)\Phi(q + h e_j) for each j=1,…,nj = 1, \dots, n (n+1n + 1 residual evaluations in total).

$J^{\mathrm{FD}}$, $h$ and $e_j$ — column-by-column finite differences

Adding hejh e_j perturbs only coordinate qjq_j by h=10−7h = 10^{-7} (in metres for a position coordinate, dimensionless for a quaternion entry). Dividing Φ(q+hej)−Φ(q)\Phi(q + h e_j) - \Phi(q) by hh approximates column jj of JJ with step size hh.

$N$ — logarithmic slider scale

The slider sets log⁡10N\log_{10} N from 00 to 77, spanning N=1N = 1 frame up to 10710^7 frames so both short sweeps and long interactive sessions appear on one log–log plot.

Two costs with different shapes. The derivation (SymPy builds Φ\Phi, forms J=∂Φ/∂qJ = \partial\Phi/\partial q symbolically, and lambdifies both) is paid once per topology. The evaluation is paid on every call: a residual, a Jacobian, a Newton frame of a few iterations. A slider sweep is a few hundred frames; an evening of dragging is many thousands. Measured here on the wishbone, cached after the first run.

Predict first. Per Jacobian of the corner in Python, which is cheaper: the lambdified symbolic Jacobian, or forward differences, which call the lambdified residual n+1n + 1 times?

Choose a prediction

Check answer (without scripting)

Answer: the symbolic Jacobian, and it is exact as well. One call returns every entry, with no step size to choose; forward differences make n+1n + 1 calls and carry an error of order ϵ\sqrt{\epsilon} relative (M01).

Reveal result (lock in your prediction above first)
cost seconds per
derive (SymPy, Jacobian, lambdify) 4.1 topology
residual Φ 2.20e-04 call
symbolic Jacobian J 4.50e-04 call
forward-difference J (22 residuals) 4.80e-03 call
Newton frame (3 iterations) 3.00e-03 slider tick

The symbolic Jacobian is 11× cheaper than forward differences here, and exact; the forward-difference one is off by up to 3.6e-07 on entries of size up to 2.0. The derivation costs as much as 1,367 Python frames. wasm.md §1 times one kernel frame at 0.09 ms (and Python at 7 ms on its machine).

10⁰10²10⁴10⁶10⁻⁴10⁻²10⁰10²10⁴derivation, oncePython frameskernel frames (wasm.md)frames solved Nseconds

At N=1,000N = 1,000 frames: Python evaluation 3.0 s, kernel evaluation 0.09 s, derivation 4.1 s. The derivation depends only on the topology, so it belongs at build time, once for every reader; the page ships only the evaluation.

When deriving once and evaluating many times breaks
  • Assumes: many evaluations per derivation: the topology stays fixed while numbers change
  • When it fails: when the topology changes often (a design study that adds joints), every change pays the derivation again
  • Check: count evaluations per derivation; below the break-even, a finite-difference Jacobian without a symbolic one is cheaper

5. The corner is not the car: what four corners cost

Setting: the problem, its sets and its symbols

Problem. Given bcb_c moving bodies per corner, b0b_0 for the chassis and seven pose coordinates per body, find the four-corner unknown count n4=7(4bc+b0)n_4 = 7(4 b_c + b_0), and compare the four-corner derivation and Jacobian costs with one corner's.

Symbol In Meaning
bc,b0b_c, b_0 N\mathbb{N} moving bodies per corner, and in the chassis
n1,n4n_1, n_4 N\mathbb{N} unknowns for one corner and for four corners
n2n^2 N\mathbb{N} entries of a square Jacobian with nn unknowns
Td(1),Td(4)T_d^{(1)}, T_d^{(4)} R>0\mathbb{R}_{>0} derivation times, s (one: measured here; four: dynamics.md §7)
tJ(1),tJ(4)t_J^{(1)}, t_J^{(4)} R>0\mathbb{R}_{>0} one Jacobian evaluation, s
How these symbols connect

Counting the moving bodies per corner bcb_c and the chassis body b0b_0 determines the unknown counts n1=7bcn_1 = 7 b_c for one fixed-chassis corner and n4=7(4bc+b0)n_4 = 7(4 b_c + b_0) for a four-corner car, along with the dense square Jacobian sizes n12n_1^2 and n42n_4^2. Placing the single-corner timings (Td(1),tJ(1))(T_d^{(1)}, t_J^{(1)}) measured in §4 beside the four-corner figures (Td(4),tJ(4))(T_d^{(4)}, t_J^{(4)}) from dynamics.md §7 compares how derivation time and per-call Jacobian evaluation scale with problem size.

Symbol-by-symbol notes
$b\lt em>c$, $b\lt /em>0$ and the factor of $7$

Each moving rigid body contributes seven entries to qq (three position coordinates in m and four unit-quaternion components). The single-corner kinematic model fixes the chassis so n1=7bcn_1 = 7 b_c, whereas a full car frees the chassis (b0=1b_0 = 1) alongside all four corners, giving n4=7(4bc+b0)n_4 = 7(4 b_c + b_0).

$n^2$ — dense Jacobian entry count

A square system of nn constraint rows and nn unknowns has n2n^2 entries in its full Jacobian, growing quadratically in nn. The ratio n42/n12n_4^2 / n_1^2 gives a geometric baseline for how much larger the four-corner derivative matrix is before sparsity is taken into account.

$T\lt em>d^{(1)}, T\lt /em>d^{(4)}$ vs $t\lt em>J^{(1)}, t\lt /em>J^{(4)}$ — cross-machine comparison

Superscripts (1)(1) and (4)(4) label one-corner and four-corner models rather than powers. Because (Td(1),tJ(1))(T_d^{(1)}, t_J^{(1)}) are timed live on this machine while (Td(4),tJ(4))(T_d^{(4)}, t_J^{(4)}) are quoted from dynamics.md §7, their ratios are order-of-magnitude comparisons rather than exact scaling laws.

Part two. §1.7 of the book is an outline of the whole car, and says so. Count first. The wishbone has 3 moving bodies (two arms and the knuckle); the quarter car adds 1 (the chassis). Four corners on one body: 4×3+1=134 \times 3 + 1 = 13 moving bodies, at seven coordinates each n=91n = 91. solvers/otkd/docs/dynamics.md §7 (and follow-ups.md, which points to it) records a four-corner model that was measured, not shipped. What did it run into?

Reveal result (lock in your prediction above first)

The measurement: 13 moving bodies, 91 unknowns (the count above agrees: True), 167 s to derive, 11 ms per Jacobian. The file does not say where the Jacobian was timed.

one corner (measured here) four corners (dynamics.md §7) ratio
unknowns 21 91 4.3
Jacobian entries, square 441 8,281 18.8
derivation 4.1 s 167 s 40.7
one Jacobian 0.45 ms 11 ms 24.4

The derivation here was timed on this machine under whatever else it was running, so the ratios are orders of magnitude, not laws.

dynamics.md's verdict: usable for a precomputed figure, not an interactive one; the derivation, not the integration, is the wall. The evaluation is milliseconds, and a straight-line kernel would cut it further. The derivation is minutes, paid again for every change of topology, and the CSE and rustc steps for a kernel come on top. The follow-up item's done means is a four-corner example CI can afford to load, or a measured reason it cannot.

When scaling one corner to four breaks
  • Assumes: cost grows with unknowns in a way one corner predicts
  • When it fails: symbolic work grows with the expression sizes and the Jacobian's m×nm \times n entries, not with the unknowns, so the derivation hits a wall first
  • Check: measure the derivation, not just the evaluation, on the bigger model before promising an interactive page

6. What roll and load transfer add

Setting: the problem, its sets and its symbols

Problem. Given a car of mass mm, centre-of-gravity height hh, track tt, wheel rate kk, the corner's camber curve γ\gamma and a steady lateral acceleration aya_y, find the load transfer per wheel ΔF\Delta F, the travel Δz\Delta z, the roll φ\varphi, and the outer and inner cambers relative to the road, γoroad,γiroad\gamma_o^{\mathrm{road}}, \gamma_i^{\mathrm{road}}.

Symbol In Meaning
aya_y [0,0.6] g[0, 0.6]\,g steady lateral acceleration (the slider)
gg R>0\mathbb{R}_{>0} 9.819.81 m/s²
mc,mm_c, m R>0\mathbb{R}_{>0} sprung mass per corner and of the car, kg
hh R>0\mathbb{R}_{>0} centre-of-gravity height, m (assumed)
tt R>0\mathbb{R}_{>0} track, m (assumed)
kk R>0\mathbb{R}_{>0} wheel rate, N/m, from the quarter car's static sag ss in m
zz [zmin⁡,zmax⁡][z_{\min}, z_{\max}] wheel-centre travel relative to the body, mm; bump positive
γ\gamma [zmin⁡,zmax⁡]→R[z_{\min}, z_{\max}] \to \mathbb{R} camber relative to the body, deg; positive when the top leans outboard
ΔF\Delta F R≥0\mathbb{R}_{\ge 0} vertical load gained by an outer wheel and lost by an inner one, N
Δz\Delta z R≥0\mathbb{R}_{\ge 0} spring deflection each side, m
φ\varphi R≥0\mathbb{R}_{\ge 0} body roll angle, deg
γoroad,γiroad\gamma_o^{\mathrm{road}}, \gamma_i^{\mathrm{road}} R\mathbb{R} outer and inner camber relative to the road, deg
How these symbols connect

Given the car mass m=4mcm = 4 m_c, centre-of-gravity height hh, track tt and steady lateral acceleration aya_y, static moment equilibrium produces the per-wheel load transfer ΔF\Delta F (N). Dividing ΔF\Delta F by the wheel rate kk (N/m) gives the equal and opposite suspension deflections ±Δz\pm\Delta z (m), which fix both the body roll angle φ\varphi (deg) across the track tt and the lookup travels ±1000 Δz\pm 1000\,\Delta z (mm) on the single-corner camber curve γ(z)\gamma(z). Combining the body-relative cambers with the body roll φ\varphi yields the road-relative cambers γoroad\gamma_o^{\mathrm{road}} and γiroad\gamma_i^{\mathrm{road}}.

Symbol-by-symbol notes
$a_y$ and $g$ — multiples of $g$ vs m/s²

The slider sets lateral acceleration as a dimensionless multiple of gg (up to 0.6 g0.6\,g). Multiplying by g=9.81 m/s2g = 9.81\text{ m/s}^2 converts aya_y to m/s² so the lateral force maym a_y lands in newtons.

$t$, $h$ and $k$ — reused symbols and wheel rate

Here tt is the vehicle track in metres (not time or §2's drive vector), and hh is the centre-of-gravity height in metres (not §4's finite-difference step). The wheel rate k=mcg/sk = m_c g / s (N/m) comes from dividing one corner's sprung weight by the quarter car's static sag ss (m).

$\Delta F$ vs $\Delta F_z$ — per-wheel vs total load transfer

Total side-to-side load transfer across the car is ΔFz=mayh/t\Delta F_z = m a_y h / t (N). Assuming equal front and rear roll-stiffness shares splits this evenly across the two axles, so each outer wheel gains and each inner wheel loses ΔF=ΔFz/2\Delta F = \Delta F_z / 2.

$z$, $\Delta z$ and $\varphi$ — mm, m and radians to degrees

Spring deflection Δz=ΔF/k\Delta z = \Delta F / k is in metres, so the small-angle roll 2Δz/t2\Delta z / t is in radians and multiplies by 180/π180/\pi to give φ\varphi in degrees. Evaluating γ(z)\gamma(z) converts Δz\Delta z to millimetres (1000 Δz1000\,\Delta z) to match the wishbone sweep's domain [zmin⁡,zmax⁡][z_{\min}, z_{\max}].

$\gamma$ vs $\gamma\lt em>o^{\mathrm{road}}, \gamma\lt /em>i^{\mathrm{road}}$ — sign convention and frame

The corner model's curve γ(z)\gamma(z) reports camber relative to the chassis, positive when the top of the wheel leans outboard (the opposite of S07's sign convention). The road-relative angles γoroad\gamma_o^{\mathrm{road}} and γiroad\gamma_i^{\mathrm{road}} instead measure each wheel's lean against the flat road once body roll φ\varphi is included.

A full vehicle model calls the corner model once per wheel. What it adds is the body the corners share. In a steady corner at lateral acceleration aya_y, the body's weight acts at the centre of gravity, height hh, while the tyres push sideways at the ground. Take moments about the outer contact patch for a car of mass mm and track tt: the inner wheels lose and the outer wheels gain

ΔFz=m ay ht\Delta F_z = \frac{m\, a_y\, h}{t}

in total, half per wheel with equal front and rear shares. With wheel rate kk each side moves Δz=ΔFz/(2k)\Delta z = \Delta F_z / (2k), the outer into bump and the inner into droop, so the body rolls by φ≈2 Δz/t\varphi \approx 2\,\Delta z / t. The corner model gives camber relative to the body; the road sees that plus the roll on the outer wheel and minus it on the inner (camber is positive when the top of the wheel leans outboard).

The numbers, and where each comes from:

input value source
sprung mass per corner 300 kg the quarter car's chassis
car mass mm 1200 kg four of those, unsprung mass ignored
wheel rate kk 27.7 N/mm mcorner gm_{\text{corner}}\, g over the quarter car's static sag, 106.4 mm, the midpoint of its undamped bounce
camber against travel -42 to +43 mm the wishbone's committed sweep
track tt 1.52 m assumed: twice the wheel centre's lateral coordinate
centre of gravity hh 0.5 m assumed

Two of these are guesses, and a four-corner model needs real values for both. It also needs the front–rear share, which comes from the roll stiffness at each axle, and an anti-roll bar changes it. Pitch under braking is the same calculation about the other axis, with the wheelbase in place of the track.

Predict first. At 0.4 g, with the assumptions above, the outer wheel moves 28 mm into bump and the corner model gives it -0.72° of camber relative to the body. Relative to the road, its camber is

Choose a prediction

Check answer (without scripting)

Answer: positive: the roll more than cancels the camber gain. Road camber is body camber plus roll. With soft springs, no anti-roll bar and a roll centre at the ground, the roll here exceeds the gain.

Figure 1
Reveal result (lock in your prediction above first)
00.150.30.450.6-2.54-1.32-0.1111.12.31outer to bodyouter to roadinner to roadlateral acceleration (g)camber (°)
g transfer per wheel (N) travel (mm) roll (°) outer to body outer to road inner to body inner to road
0.30 581 21.00 1.58 -0.53 1.06 0.47 -1.11

At 0.30 g the outer wheel is at -0.53° to the body and 1.06° to the road; the body has rolled 1.58°. Camber gain in bump is what a designer adds to fight exactly this, and an anti-roll bar or a higher roll centre reduces the roll. None of those decisions can be made from one corner.

When steady-state load transfer breaks
  • Assumes: a rigid body in a steady corner, all transfer through the springs, roll centre at the ground, equal front and rear shares
  • When it fails: a roll centre above the ground carries part of the transfer through the links and reduces roll; an anti-roll bar moves the share between axles; a transient overshoots
  • Check: at zero lateral acceleration both cambers return to the corner's own; the roll angle should scale linearly with aya_y while travel stays in the swept range

7. What a bigger model still cannot answer, and the track in one table

Setting: the problem, its sets and its symbols

Problem. Given a question Q∈QQ \in \mathcal{Q} about the suspension with a tolerance τQ\tau_Q, choose a model M∈MM \in \mathcal{M}, a method S∈SS \in \mathcal{S} and a check c∈Cc \in \mathcal{C} such that cc could show the answer wrong by more than τQ\tau_Q.

Symbol In Meaning
Q\mathcal{Q} set\text{set} questions: a pose, a spread, a ringing, a browser page, a car
τQ\tau_Q R>0\mathbb{R}_{>0} tolerance the question asks for, in its own units (deg, mm, J)
M\mathcal{M} set\text{set} models: rigid square, over-determined, compliant, moving, sampled, generated kernel, four corners
S\mathcal{S} set\text{set} methods: Newton, least squares and SVD, energy minimisation, time stepping, Monte Carlo, convergence study
C\mathcal{C} set\text{set} checks: residual, rank, gradient, energy drift, 1/N1/\sqrt{N}, observed order, replay, measurement
How these symbols connect

Every modelling task starts from a concrete question Q∈QQ \in \mathcal{Q} together with an acceptable error scale τQ\tau_Q in that question's own units. Answering QQ requires choosing a matching triple: a model M∈MM \in \mathcal{M} whose assumptions cover the relevant physics, a numerical method S∈SS \in \mathcal{S} suited to MM's mathematical structure, and a check c∈Cc \in \mathcal{C} capable of catching an error larger than τQ\tau_Q.

Symbol-by-symbol notes
$\tau_Q$ — question-driven tolerance

The tolerance τQ\tau_Q carries the units of the quantity the question asks for (degrees of camber, millimetres of travel, or joules of energy) rather than a generic solver threshold. A check is useful only when it can resolve errors smaller than τQ\tau_Q.

$\mathcal{M}$ vs $\mathcal{S}$ — formulation vs solver

A model M∈MM \in \mathcal{M} states the equations and idealisations (rigid constraints, compliant energy, DAE dynamics, or sampled parameters), whereas a method S∈SS \in \mathcal{S} is the algorithm that solves them. The same model can require different methods depending on QQ, such as static equilibrium versus time stepping on one linkage.

$\mathcal{C}$ — verification vs validation

Internal checks in C\mathcal{C} (residuals, rank, energy drift, observed order, selftest replay) verify that SS solved MM accurately, whereas physical measurement validates whether MM describes the real car. Passing every internal check never substitutes for measurement when the question is about the vehicle itself.

A four-corner model adds a body with mass and inertia, a tyre model that turns slip and camber into force, a road and air. It does not add truth. A full vehicle model with a wrong tyre and a guessed bush stiffness answers its own question precisely and may still be wrong about the car. The limits Chapter 1 established travel with the corner model into every larger model that calls it: the model is kinematic, so a load changes the answer only through a bush; the bush stiffness must be measured or assumed; nothing bends or wears; the tyre is a black box. And every comparison in the chapter is between two models of the same mechanism. Agreement between models is evidence about the mathematics; only measurement is evidence about the suspension.

The whole track, as the decision a modeller actually makes:

question model method check
where is the wheel at this arm angle? rigid corner, square Newton (M02) residual at round-off; the closed form of §1.2
the same, with a spare leg over-determined, consistent least squares, then the SVD (M03, M08) rank, the left null vector names the spare row
how far does a bush let it move under load? compliant, energy minimise energy / KKT (M04) gradient zero; the stiffness ladder tends to rigid
how does it ring after a bump? moving, a DAE stepping with projection (M06); modes (M05) energy drift shrinks with the step; constraint stays at round-off
the bush is known only to ±30 % the compliant model, sampled Monte Carlo (M07) error falls like 1/N1/\sqrt{N}; two seeds agree
is the step or tolerance small enough? any of the above convergence study (M01) observed order settles; Richardson
the reader drags a pivot in the browser the generated kernel (S08) the derivation, compiled once selftest replay; Python as the reference
what does the car do in a corner? four corners and a body the corner model, called per wheel measurement of the car, not agreement of models

Mixed practice: which method, and why?

Each item names a question from either track.

1. A bush stiffness is known only to ±30 %. You want the spread of rest camber it causes. Which method, and why?

Question 1
How sure?

2. A corner model has 22 rows, 21 unknowns and stalls with a rank-21 Jacobian. Which method, and why?

Question 2
How sure?

3. The quarter car's energy drifts. You want to know whether the integrator, not the model, is at fault. Which check?

Question 3
How sure?

4. A page must re-solve the corner as the reader drags a pivot point. Which approach, and which check?

Question 4
How sure?

Show answers and explanations

1. Monte Carlo over the stiffness, an equilibrium solve per sample. Sample the stiffness, solve the compliant model for each, and read the spread; check it by doubling N, which should shrink the error by about 1.4.

2. Least squares, then the SVD to name the spare row. Rows exceed rank: least squares solves it as posed, and the left null vector names which rows are dependent, so one can be dropped.

3. Halve the time step and see whether the drift shrinks at the method's order. A convergence study separates discretisation error from model error: the integrator's drift falls by about 2^p per halving; a model error does not.

4. The generated kernel, checked by replay against the Python engine. The kernel is topology-scoped, so any pivot position is a number written into g; the conformance replay shows it computes the same map.

Practice

Practice A (steps partly filled). In the wishbone kernel the blocks run q, g, t, out, jac with sizes 21, 67, 1, 21, … and jac is row-major with 21 columns. The offset of jac is 21 + 67 + 1 + 21 = ?; entry (row 2, column 5), counting from 0, is at that offset + 2×21+5+ \, 2 \times 21 + 5. Enter its index in MEM.

Worked solution

Offset =110= 110; index =110+2×21+5=157= 110 + 2 \times 21 + 5 = 157. A page reads it as mem[MEM.value / 8 + 157].

Practice B (with a hint). A derivation takes 30 s. Afterwards a symbolic Jacobian costs 2 ms; without it, a forward-difference Jacobian costs 20 ms. After how many Jacobians has the derivation paid for itself?

Worked solution

30=(0.020−0.002)N30 = (0.020 - 0.002)N, so N=30/0.018≈1667N = 30 / 0.018 \approx 1667 Jacobians: a few hundred Newton frames. A book's slider passes that in minutes, and every reader after the first pays nothing if the derivation happens at build time.

Hint 1

Write the total time of each route as a function of the number of Jacobians NN.

Hint 2

Set 30+0.002N=0.020N30 + 0.002N = 0.020N and solve for NN.

Practice C (on your own). A 1200 kg car with its centre of gravity 0.5 m high and a 1.5 m track corners steadily at 0.5 g. Take g=9.81g = 9.81 m/s². Enter the total lateral load transfer, in newtons.

Worked solution

ΔFz=mayh/t=1200×0.5×9.81×0.5/1.5=1962\Delta F_z = m a_y h / t = 1200 \times 0.5 \times 9.81 \times 0.5 / 1.5 = 1962 N, about 981 N per wheel with equal axle shares: a sixth of the car's weight moved from the inside to the outside.

Check yourself (closed book)

1. What does common-subexpression elimination change about the residual map Φ(q,g,t)\Phi(q, g, t)?

Question 1
How sure?

2. The book's corner kernel is compiled once. Which change needs a new kernel?

Question 2
How sure?

3. The Rust kernel and the Python engine disagree on one residual row. What is the right response?

Question 3
How sure?

4. Why is kernel.rs compared byte for byte, but kernel.wasm only by its behaviour?

Question 4
How sure?

5. A kernel declares exact: true and uses only +−×÷+ - \times \div and square roots. A Python replay performs the same operations in the same order. They agree

Question 5
How sure?

6. In a steady corner the outer wheel moves into bump and gains negative camber relative to the body. Relative to the road, its camber is

Question 6
How sure?

7. A full-vehicle model and the corner model agree on camber to 0.01°. What does that agreement show?

Question 7
How sure?

Show answers and explanations

1. Only its representation: the same map, with repeated work done once. CSE names each repeated subexpression once and reuses it. The polynomial is unchanged; the program that evaluates it is a straight line with fewer operations.

2. Adding a toe link as a new joint. A new joint is new rows and new symbols, so a new derivation. The topology is fixed at build time; a new joint or body is a re-emit.

3. Re-emit: the artefact is stale, because the emitter never re-derives. Kernel and engine come from one derivation, so they cannot legitimately differ. A difference means the committed artefact predates the current derivation.

4. The wasm bytes depend on the rustc version and flags; the source depends only on the derivation. Two emissions of the source are identical by construction. The binary is a toolchain artefact: a new rustc may lay it out differently and still be right.

5. bit for bit. IEEE 754 rounds each of these operations correctly, so the same inputs in the same order give the same double on any conforming platform.

6. the body-relative angle plus the roll angle, which can make it positive. Road camber is body camber plus body roll. With soft springs and no anti-roll bar the roll can overwhelm the camber gain.

7. That the two models do the same mathematics, not that either matches the car. Agreement between models is evidence about the mathematics. Only measurement is evidence about the suspension (Chapter 1 Review).

Keep these:

  1. Derive once, symbolically; CSE turns the map into a straight-line program without changing it.
  2. A kernel is topology-scoped: every number is free in one f64 arena, a new joint is a re-emit.
  3. Source is reproducible byte for byte; a binary is tested by behaviour against the reference.
  4. Exact operations replay bit for bit; transcendental ones agree to a stated tolerance.
  5. The derivation is the wall for bigger models; evaluation is the cheap side.
  6. Road camber is body camber plus roll: the car adds what the corner cannot see.
  7. Agreement between models is evidence about the mathematics; only measurement is evidence about the car.

Your connection

Pick one question you would want a full-vehicle model to answer. Which corner-model limit from Chapter 1 would its answer inherit, and what measurement would test it?

Answers

Practice A. 110+2×21+5=157110 + 2 \times 21 + 5 = 157.

Practice B. N=30/0.018≈1667N = 30 / 0.018 \approx 1667 Jacobians.

Practice C. ΔFz=1962\Delta F_z = 1962 N in total.

Mixed practice. Monte Carlo with an equilibrium solve per sample; least squares then the SVD; a time-step convergence study; the generated kernel with a replay check.

Where the maths is derived

Optional. These notes give the intuition and application; the sources below give the full derivations and proofs.

§1 Common subexpressions and code generation

§2 The arena and the exports

§3 Conformance and reproducibility

§4 What a derivative costs

§5 Four corners

§6 Load transfer and roll


Compiled from notebooks/suspension/s08_kernels_and_the_car.py — run locally with cd notebooks && uv run marimo edit suspension/s08_kernels_and_the_car.py for live Python scratch cells.

Back to the book: 1.7 The full vehicle · Chapter 1 Review

Settings

Colour scheme

Light or dark pages. Your colour and layout stay the same.

Colour

The paper, ink and lettering. Your layout stays the same.

Quiet colours
Bold colours
Reading offline

Keep this book on this device and read it offline.