Part 2 of 5

Keeping the Receipts

Part 1 promised that a flow keeps a receipt for every stretch and squeeze. This part opens the ledger: the change-of-variables theorem, the Jacobian, and why the receipts literally add up. From here on we use real equations — every one is earned by a picture.

Section 1The slogan becomes a theorem

Deriving “new height = old height ÷ stretch”

Part 1's one rule was a slogan. Here is where it comes from — a four-line argument you can check yourself. Let X have density pX, and push it through a smooth, increasing map f to get Y = f(X). The trick is to reason about accumulated probability (the CDF, F), because accumulation survives relabeling: Y is below y exactly when X is below f−1(y).

FY(y) =P(Y≤y) =P(X≤f−1(y)) =FX(f−1(y))

Density is the derivative of accumulated probability, so differentiate both sides in y, using the chain rule on the right:

pY(y) = pX(f−1(y)) · (f−1)′ (y) = pX(x) f′(x)

writing x = f−1(y) and using the inverse-function rule (f−1)′ = 1/f′. That fraction is the slogan: old height at the source point, divided by the local stretch f′. If f is decreasing instead, the same argument runs with flipped inequalities and delivers a minus sign — which the density absorbs as an absolute value. Hence the theorem in its adult form:

pY(y) = pX(f−1(y)) | f′(f−1(y)) |−1
The change-of-variables formula in one dimension. If you have met u-substitution in calculus, this is the same fact wearing a probability hat: relabel the axis, pay the |f′| exchange rate.
Section 2Two dimensions: enter the Jacobian

A matrix at every point

In one dimension, “local stretch” was a single number, f′(x). In d dimensions a smooth map T can stretch each direction differently and rotate and shear — so the local behavior at a point is not a number but a linear map: zoom in far enough and T looks like multiplication by a matrix. That matrix of partial derivatives is the Jacobian:

JT(x) = ( ∂T1∂x1 ∂T1∂x2 ∂T2∂x1 ∂T2∂x2 )

And the “stretch factor” is its determinant. Feed the linear map a tiny unit square; out comes a parallelogram; the parallelogram's area is |det J|. A negative determinant just means the map flipped orientation (a mirror image) — the area is still |det|, which is why the formula wears absolute-value bars. So the theorem generalizes with one substitution — derivative → Jacobian determinant:

pY(y) = pX(T−1(y)) |det JT−1 (y)|
The multivariate change-of-variables formula — the load-bearing equation of the whole subject. Equivalently, dividing instead of multiplying: pY(y) = pX(x) / |det JT(x)|.

Watch it happen. Below, a nonlinear warp acts on the plane (the slider morphs it in from the identity). The dashed blue square is a small patch at your probe point before the warp; the orange parallelogram is that same patch after. The matrix on the right is the Jacobian at the probe, computed live — click or drag anywhere on the canvas to move the probe, and watch the matrix and its determinant chase the local geometry.

Interactive · the Jacobian probe click / drag to move the probe
Jacobian at the probe
1.000.000.001.00

Two things worth noticing in the readout. The parallelogram's measured area really is |det J| times the square's area — the determinant is not a metaphor, it is the area. And the map in this demo has a special form: its first output depends only on x₁. That makes the Jacobian triangular (top-right entry is exactly zero) — hold that thought for Section 4.

Section 3The ledger: logs, sums, stacks

Receipts add

Now stack layers, as a real flow does: T = TK ∘ ⋯ ∘ T2 ∘ T1. The chain rule says the Jacobian of a composition is the product of the layer Jacobians, and determinants multiply along with them. Products are awkward — a hundred numbers multiplied together overflow or vanish — so everyone works in logs, where the product becomes a sum:

logpX(x) = logpZ(z) + ∑k=1K log |detJk|
z is the point x reaches after running all the way back to the base distribution. This is the exact log-density a flow reports — a bell-curve score plus a ledger of per-layer receipts. Part 4 turns this very expression into a training objective.

The ledger metaphor is now literal: each layer appends one line — its local log-|det| — and the total is a sum. Nothing is approximated anywhere; that exactness is inherited by everything built on top.

Where does space actually expand and contract? Paint it. The heatmap below colors the plane by the local receipt log |det J| of the whole map: red where a patch grew, blue where it shrank, neutral where area was preserved. Try both maps.

Interactive · the receipt field colors = local log |det J|
contracts ÷3.5
expands ×3.5

The second map holds a small surprise. Its stretch layer has the same receipt everywhere (×1.7 · ×0.4 = 0.68 — a flat field), and its swirl layer's receipt is exactly zero: a radius-dependent rotation moves points along circles without changing any areas at all, so det = 1 identically. All that visual drama in Part 1's spiral, and the ledger records a single constant line. Rotations, permutations, and shears are “free” layers — expressiveness without receipts.

Section 4Why structure matters

Triangular is the magic word

Here is the engineering problem the next part solves. For a d-dimensional layer, det J is a determinant of a d×d matrix — an O(d³) computation, done at every data point, every training step. For images, d is in the hundreds of thousands. Generic layers are unaffordable.

But determinants have a famous escape hatch: if a matrix is triangular — everything above the diagonal is zero — its determinant is just the product of the diagonal entries, O(d). And you can force a Jacobian to be triangular by architecture: make output 1 depend only on input 1, output 2 only on inputs 1–2, and so on. Each output may depend on earlier inputs in any wild, nonlinear way — those derivatives land below the diagonal, where the determinant never looks. The probe demo's warp was exactly this: its top-right entry stayed pinned at 0.00 no matter where you put the probe, and its determinant was always just J₁₁·J₂₂.

A generic Jacobian. Every entry can be anything; the determinant needs the whole matrix and O(d³) work. Fine at d = 2. Fatal at d = 100,000.
A triangular Jacobian. Zeros above the diagonal by construction. det = product of the diagonal — read it off in O(d). The lower cells can be arbitrarily nonlinear, for free.

This is the design space of the whole field: layers whose Jacobians are triangular (cheap dets), orthogonal (det = ±1, free), or otherwise structured — composed into stacks expressive enough to bend a bell curve into anything. Building those layers well is Part 3.

Section 5Check yourself

Four questions

RecapIf you remember three things
1
The theorem is the slogan, derived. Push a density through an invertible map and it divides by the local stretch — |f′| in 1-D, |det J| in general. Four lines of CDF algebra, no hand-waving.
2
The Jacobian is local geometry. At every point, a smooth map acts like a matrix; its determinant is the area of the parallelogram a unit square becomes. Negative det = mirror flip; rotations and shears cost det = 1.
3
Receipts add, and structure makes them cheap. Stacked layers sum their log-|det|s into an exact ledger, and triangular Jacobians read their determinant off the diagonal in O(d).