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
.wasmis 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-appliedChapter 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.
Warm-up: remember
1. The same steps on a toy: derive, eliminate, print
Setting: the problem, its sets and its symbols
Problem. Given links with lengths and a target , take the residual and its Jacobian . Find a straight-line program that evaluates every entry of exactly, and compare its operation count with that of as written.
| Symbol | In | Meaning |
|---|---|---|
| number of links (data) | ||
| relative link angles, rad (the unknowns) | ||
| link lengths, m (data) | ||
| target for the tip, m (data) | ||
| tip coordinates as functions of , m | ||
| residual , m | ||
| , m/rad | ||
| the residual rows followed by the Jacobian entries | ||
| CSE replacements, assigned in evaluation order; | ||
operation count, SymPy's count_ops |
How these symbols connect
Given the data , and , the planar chain maps the relative angles to tip coordinates , yielding the residual (m) and its Jacobian (m/rad). Collecting all symbolic entries into lets common-subexpression elimination extract shared subtrees into ordered temporaries without changing the numerical map, and the counter compares the operation counts before and after elimination.
Symbol-by-symbol notes
$\theta$ — relative, not world, angles
Each entry is the angle of link relative to link (with measured from the -axis), in radians. The orientation of link in the plane is therefore the cumulative sum , so every earlier angle enters every later link's sine and cosine.
$\Phi$ and $J$ — residual and Jacobian units
The residual is in metres and vanishes when the tip reaches . Differentiating with respect to angles in radians gives in m/rad, the units of a lever arm.
$E$ — symbolic expressions, not floating-point arrays
Rather than numbers at a single pose, is a flat list of SymPy expression trees (the two residual rows followed by the entries of ). Passing and 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 names a repeated subexpression built from the inputs and earlier temporaries , with no loops or branches. Evaluating in sequence and then the reduced outputs computes the exact same mathematical map as .
$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 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 links of lengths at relative angles . The tip sits at
and the residual asks it to reach a target: . Differentiating gives , a tail sum of the same sines that uses, so the 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.
Reveal result (lock in your prediction above first)
| 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 : 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 :
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; andexpandbefore 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 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 with sizes , laid end to end in the arena , find each offset , the arena index of any Jacobian entry , and the set of entries the kernel computes as other than a literal zero.
| Symbol | In | Meaning |
|---|---|---|
blocks q, g, t, out, jac, met, world, pts, axs, num, in order |
||
| size of block , in f64 slots | ||
| offset of block : the sum of the sizes before it, slots | ||
the arena MEM, f64 slots |
||
| unknowns (seven per moving body) and residual rows | ||
| pose: positions in m, unit quaternions dimensionless (unknowns) | ||
| geometry numbers: m, unit axes, compliances in m/N (data) | ||
| drive values, rad (data) | ||
| residual, m or dimensionless by row | ||
| , stored row-major: entry at | ||
| flat indices of the computed entries |
How these symbols connect
The ten blocks sit end to end in one contiguous f64 arena , where each block's slot count fixes the next block's starting offset and the total length . A host page writes inputs into q, g (via pack() from pts, axs, num) and t, then calls compute() to write into out and row-major into jac. Comparing the flat indices 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 and offset 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 in a Float64Array view.
$q$, $g$ and $t$ — unknowns, free geometry and drives
The unknown vector holds seven pose numbers per moving body (three positions in m and a dimensionless unit quaternion), holds the resolved geometry parameters (coordinates, unit axes, compliances), and holds drive values in radians. Keeping and 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 and column index , entry sits at flat index within jac, and therefore at slot in .
$S$ — structurally computed Jacobian slots
The set lists the flat indices 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 or if singular),
metrics and world.
Reveal result (lock in your prediction above first)
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.jsonbeside a stale.wasmreadsjacfrom the wrong slots, and the numbers look plausible - Check: the ABI string (
otkd-kernel-2), and forot-solvethe 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 , step count , recorded outputs ), compute a replay by the same operations in the same order and find ; also compute the layout hash of the block sizes. For an otkd kernel, find whether .
| Symbol | In | Meaning |
|---|---|---|
| , dimensionless | ||
| starting value (parameter) | ||
| damping factor, dimensionless (parameter) | ||
| iterates, | ||
| steps recorded in the case | ||
the out and diag blocks, recorded and replayed; slots |
||
| the IEEE 754 doubles; each operation rounds into it | ||
sizes of params, state, out, diag, slots |
||
| FNV-1a over the sizes' little-endian bytes | ||
| an otkd residual from the kernel and from Python | ||
| a conformance tolerance, in the row's units |
How these symbols connect
For newton-root, the parameters and step count run damped Newton iteration on in IEEE 754 double precision , filling the slots of out and diag so the Python replay can be compared against the recorded native run . Alongside this numerical replay, hashing the four block sizes through verifies that the manifest and binary agree on the arena layout. For an otkd kernel, conformance is checked by comparing against the Python reference in the infinity norm against a tolerance .
Symbol-by-symbol notes
$\lambda$ — damping factor, not a Lagrange multiplier
In newton-root, scales each Newton step, : is full Newton, under-relaxes and 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 floats. Checking compares every recorded slot, not only the final iterate .
$\mathbb{F}$ — IEEE 754 binary64 doubles
The set consists of 64-bit IEEE 754 floating-point numbers (f64 in Rust and WebAssembly, float in CPython). Because each operation rounds back into , the replayed vector depends on both the operations executed and their exact evaluation order.
$s$ and $h(s)$ — 32-bit FNV-1a layout hash
The four-tuple 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 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, is evaluated in WebAssembly and in Python at the same inputs . The conformance check verifies that their worst-case component discrepancy stays within , 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 on
. 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.
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:
exactin the manifest: bit for bit when true,1e-12relative when false
4. Derivation once, evaluation many times
Setting: the problem, its sets and its symbols
Problem. Given the wishbone's derivation time and per-call costs , find the cost of solving frames, and compare with the forward difference , .
| Symbol | In | Meaning |
|---|---|---|
| frames solved (the slider) | ||
| derivation: SymPy, symbolic Jacobian, lambdify, s per topology | ||
| one residual, symbolic Jacobian, forward-difference Jacobian, s | ||
| one Newton frame from the neighbouring pose, s | ||
| one kernel frame, s, as wasm.md §1 reports it | ||
| total time for frames, s | ||
| pose, unknowns | ||
| residual at fixed | ||
| exact and forward-difference Jacobians | ||
| difference step, in each coordinate's units | ||
| -th unit vector |
How these symbols connect
The cost model separates the one-off per-topology derivation time (s) from the per-frame evaluation cost (s, or in WebAssembly), combining them into the affine total over solved frames. Inside a Newton frame at pose , one residual costs , while forming the Jacobian costs either via the lambdified symbolic expression or via forward differences using step along each unit vector .
Symbol-by-symbol notes
$T\lt em>d$ vs $t\lt /em>{\mathrm{frame}}$ and $t_{\mathrm{kernel}}$ — fixed vs marginal cost
Derivation time covers building , differentiating symbolically to obtain , and lambdifying both, paid once per topology regardless of . By contrast, (Python) and (WebAssembly) are paid on every slider tick, giving an amortised cost per frame of .
$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 with fixed . While times one call to the lambdified symbolic Jacobian, times evaluating once plus for each ( residual evaluations in total).
$J^{\mathrm{FD}}$, $h$ and $e_j$ — column-by-column finite differences
Adding perturbs only coordinate by (in metres for a position coordinate, dimensionless for a quaternion entry). Dividing by approximates column of with step size .
$N$ — logarithmic slider scale
The slider sets from to , spanning frame up to frames so both short sweeps and long interactive sessions appear on one log–log plot.
Two costs with different shapes. The derivation (SymPy builds , forms 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.
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).
At 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 moving bodies per corner, for the chassis and seven pose coordinates per body, find the four-corner unknown count , and compare the four-corner derivation and Jacobian costs with one corner's.
| Symbol | In | Meaning |
|---|---|---|
| moving bodies per corner, and in the chassis | ||
| unknowns for one corner and for four corners | ||
| entries of a square Jacobian with unknowns | ||
| derivation times, s (one: measured here; four: dynamics.md §7) | ||
| one Jacobian evaluation, s |
How these symbols connect
Counting the moving bodies per corner and the chassis body determines the unknown counts for one fixed-chassis corner and for a four-corner car, along with the dense square Jacobian sizes and . Placing the single-corner timings measured in §4 beside the four-corner figures 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 (three position coordinates in m and four unit-quaternion components). The single-corner kinematic model fixes the chassis so , whereas a full car frees the chassis () alongside all four corners, giving .
$n^2$ — dense Jacobian entry count
A square system of constraint rows and unknowns has entries in its full Jacobian, growing quadratically in . The ratio 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 and label one-corner and four-corner models rather than powers. Because are timed live on this machine while 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: moving bodies, at seven coordinates each .
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 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 , centre-of-gravity height , track , wheel rate , the corner's camber curve and a steady lateral acceleration , find the load transfer per wheel , the travel , the roll , and the outer and inner cambers relative to the road, .
| Symbol | In | Meaning |
|---|---|---|
| steady lateral acceleration (the slider) | ||
| m/s² | ||
| sprung mass per corner and of the car, kg | ||
| centre-of-gravity height, m (assumed) | ||
| track, m (assumed) | ||
| wheel rate, N/m, from the quarter car's static sag in m | ||
| wheel-centre travel relative to the body, mm; bump positive | ||
| camber relative to the body, deg; positive when the top leans outboard | ||
| vertical load gained by an outer wheel and lost by an inner one, N | ||
| spring deflection each side, m | ||
| body roll angle, deg | ||
| outer and inner camber relative to the road, deg |
How these symbols connect
Given the car mass , centre-of-gravity height , track and steady lateral acceleration , static moment equilibrium produces the per-wheel load transfer (N). Dividing by the wheel rate (N/m) gives the equal and opposite suspension deflections (m), which fix both the body roll angle (deg) across the track and the lookup travels (mm) on the single-corner camber curve . Combining the body-relative cambers with the body roll yields the road-relative cambers and .
Symbol-by-symbol notes
$a_y$ and $g$ — multiples of $g$ vs m/s²
The slider sets lateral acceleration as a dimensionless multiple of (up to ). Multiplying by converts to m/s² so the lateral force lands in newtons.
$t$, $h$ and $k$ — reused symbols and wheel rate
Here is the vehicle track in metres (not time or §2's drive vector), and is the centre-of-gravity height in metres (not §4's finite-difference step). The wheel rate (N/m) comes from dividing one corner's sprung weight by the quarter car's static sag (m).
$\Delta F$ vs $\Delta F_z$ — per-wheel vs total load transfer
Total side-to-side load transfer across the car is (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 .
$z$, $\Delta z$ and $\varphi$ — mm, m and radians to degrees
Spring deflection is in metres, so the small-angle roll is in radians and multiplies by to give in degrees. Evaluating converts to millimetres () to match the wishbone sweep's domain .
$\gamma$ vs $\gamma\lt em>o^{\mathrm{road}}, \gamma\lt /em>i^{\mathrm{road}}$ — sign convention and frame
The corner model's curve 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 and instead measure each wheel's lean against the flat road once body roll 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 , the body's weight acts at the centre of gravity, height , while the tyres push sideways at the ground. Take moments about the outer contact patch for a car of mass and track : the inner wheels lose and the outer wheels gain
in total, half per wheel with equal front and rear shares. With wheel rate each side moves , the outer into bump and the inner into droop, so the body rolls by . 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 | 1200 kg | four of those, unsprung mass ignored |
| wheel rate | 27.7 N/mm | 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 | 1.52 m | assumed: twice the wheel centre's lateral coordinate |
| centre of gravity | 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.
Reveal result (lock in your prediction above first)
| 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 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 about the suspension with a tolerance , choose a model , a method and a check such that could show the answer wrong by more than .
| Symbol | In | Meaning |
|---|---|---|
| questions: a pose, a spread, a ringing, a browser page, a car | ||
| tolerance the question asks for, in its own units (deg, mm, J) | ||
| models: rigid square, over-determined, compliant, moving, sampled, generated kernel, four corners | ||
| methods: Newton, least squares and SVD, energy minimisation, time stepping, Monte Carlo, convergence study | ||
| checks: residual, rank, gradient, energy drift, , observed order, replay, measurement |
How these symbols connect
Every modelling task starts from a concrete question together with an acceptable error scale in that question's own units. Answering requires choosing a matching triple: a model whose assumptions cover the relevant physics, a numerical method suited to 's mathematical structure, and a check capable of catching an error larger than .
Symbol-by-symbol notes
$\tau_Q$ — question-driven tolerance
The tolerance 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 .
$\mathcal{M}$ vs $\mathcal{S}$ — formulation vs solver
A model states the equations and idealisations (rigid constraints, compliant energy, DAE dynamics, or sampled parameters), whereas a method is the algorithm that solves them. The same model can require different methods depending on , such as static equilibrium versus time stepping on one linkage.
$\mathcal{C}$ — verification vs validation
Internal checks in (residuals, rank, energy drift, observed order, selftest replay) verify that solved accurately, whereas physical measurement validates whether 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 ; 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.
Practice
Hint 1
Write the total time of each route as a function of the number of Jacobians .
Hint 2
Set and solve for .
Check yourself (closed book)
Keep these:
- Derive once, symbolically; CSE turns the map into a straight-line program without changing it.
- A kernel is topology-scoped: every number is free in one
f64arena, a new joint is a re-emit.- Source is reproducible byte for byte; a binary is tested by behaviour against the reference.
- Exact operations replay bit for bit; transcendental ones agree to a stated tolerance.
- The derivation is the wall for bigger models; evaluation is the cheap side.
- Road camber is body camber plus roll: the car adds what the corner cannot see.
- 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. .
Practice B. Jacobians.
Practice C. 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
- otkd, generated kernels: SymPy, Rust and WebAssembly (docs/wasm.md): the arithmetic circuit,
sympy.cse,rust_codeand the integer-literal trap (§1–2).
§2 The arena and the exports
- otkd, generated kernels: SymPy, Rust and WebAssembly (docs/wasm.md): the
MEMbuffer, the block layout and the compiled-in solver (§3–4).
§3 Conformance and reproducibility
- otkd — the model, its exports and a generated solver:
tests/test_wasm.pyand the conformance tolerances;docs/wasm.md§5–6 on the reproducible source and the bundle.
§4 What a derivative costs
- Nocedal and Wright (2006), Numerical Optimization: finite-difference and exact derivatives, their errors and their costs (ch. 8).
§5 Four corners
- otkd — the model, its exports and a generated solver:
docs/dynamics.md§7, the four-corner measurement, anddocs/follow-ups.md.
§6 Load transfer and roll
- Milliken and Milliken (1995), Race Car Vehicle Dynamics: lateral load transfer, roll centres and roll stiffness, and the tyre that turns camber into grip.
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