2b · The walker lab
Diffusion, one grain at a time
Course 2, Step 5 ended on a confession in reverse: a crowd of coin-flipping walkers smoothed itself out by exactly the heat equation, without ever computing one. This page takes that seriously as a way of computing in its own right — just grains, each one ignorant of calculus, and the smooth fields of Course 2 reappearing as crowd behavior.
In words: one blind step at a time
A random walker's entire rulebook is one sentence: every tick, take one blind step — a coin flip picks the direction. Each grain is ignorant of calculus. It has no idea a crowd exists, let alone where the crowd is. And yet release thousands of them and the shape of the crowd — how many grains sit in each patch of space — spreads out exactly the way Course 2 says a temperature curve spreads. The smooth fields of Course 2 reappear here as crowd behavior.
Which raises the obvious question: where does the equation actually live? Not inside a walker — you can read a grain's rule all day and never find a derivative in it. The equation only shows up once you stop following individuals and start counting how many are where. It's that count, not the grains, that obeys the heat equation.
And that's the one real difference between this page and Courses 2–4. Those courses chopped space into fixed boxes and, for each box, tracked the amount inside it: the box never moves, its contents rise and fall. Every bead, every cell of the heat sheet, every cell of the reaction–diffusion dish worked that way. Here we do the opposite — forget the boxes, pick a grain, and record where it goes. The thing you're following moves along with the stuff.
Those two habits have names worth knowing, because you'll meet them in any simulation work: the fixed-box view is Eulerian, the follow-a-grain view is Lagrangian. One asks how full is this place?, the other asks where did this piece go? Same physics, two sets of books — and now the bookkeeping metaphor should land: they're two ways of accounting for identical events.
They don't agree perfectly, and the disagreement is the interesting part. The equation describes the average crowd — what you'd get from infinitely many walkers. Any actual crowd is one sample of that average, so its count in each patch jiggles a little above and below the equation's answer. How much? Roughly one over the square root of the number of grains (written 1/√n): with about 100 grains in a patch the count wobbles by around 10%, with 10,000 by around 1%. Quadruple the crowd and you halve the wobble — but it never reaches zero.
So to be precise about what the smooth field leaves out: it isn't ignoring the wobble, it has no way to express it. A field stores one number per place — an average — and an average has no room in it for "and it jitters by this much." That's not a flaw; it's the trade you make for a law you can solve.
And the wobble is real physics, not a rendering artifact. When a patch of space holds only a handful of particles, 1/√n is large and the graininess is genuinely there and genuinely measurable — that's precisely what Robert Brown saw jittering in his pollen, and what Perrin later measured to weigh an atom. At everyday concentrations the count per patch is astronomically large, the wobble becomes invisible, and the smooth field is indistinguishable from the truth. In short: diffusion really is grainy — you just have to be looking at few enough particles to see it.
In math: count, don't integrate
Four short equations take us from a coin flip to the heat equation. Every symbol in them is defined — hover any colored term to read what it is, or use the full list at the end of this section.
Start by counting. To be standing at position x a moment from now, a walker must be exactly one stride away right now — and half of those neighbors happen to flip our way. So:
Step one · who can possibly be here next tick
In words: the crowd at x, one tick from now, is half the crowd one stride to the left plus half the crowd one stride to the right. It's a probability statement read for everyone at once — those arrivals are the only way to be at x, so they account for the whole crowd there.
Now subtract the crowd that's already at x from both sides, so we're looking at the change rather than the total:
Step two · the same statement, as a change
In words: in one tick, the crowd here changes by the average of its two neighbors, minus itself. Nothing new was added — this is the line above, rearranged.
That bracket is worth slowing down on, because it's the whole bridge to calculus. Read it as a curvature meter. Suppose your two neighbors average out to exactly your own height: then you sit on a straight line, the bracket is zero, and nothing changes — even if that line is steep. If they average higher than you, you're sitting in a dip, and the bracket is positive, so the crowd here grows. Lower, and you're on a bump, so it drains. Course 2, Step 6 named exactly this quantity: comparing a value to the average of its neighbors is what a second derivative measures. That's the connection — not an analogy, the same arithmetic.
So now make the walk finer: smaller strides, faster ticks. Two things happen at once. The bracket shrinks — halve the stride and it gets about four times smaller, because it scales with h² — and the ticks come faster, so more of them land per second. Those two effects fight, and if you shrink stride and tick together at the right rate they balance exactly, leaving a finite answer. Divide the change by the tick, divide the bracket by the stride squared, and every trace of h and Δt collapses into a single constant:
Step three · the limit — and the heat equation appears
In words: how fast the crowd here changes over time equals D times how sharply the crowd's curve bends in space. That is the heat equation of Course 2, arrived at from coin flips.
About that D, since it appears out of nowhere: it's the diffusion coefficient — one number saying how vigorously this particular stuff spreads. And notice it isn't a new ingredient smuggled in. It's built entirely from the walk we already had: the stride squared, divided by twice the tick. A jumpier grain means a bigger D means a faster-spreading crowd. This is the same role played by α in Course 2's heat equation and by Dᵤ and Dᵥ in Course 4's dish — and it's the D on the lab's jitter slider below.
One last equation, and it's the one the simulator actually runs. Everything above described the crowd; this describes a single grain's move in a single tick:
Step four · one grain, one tick
In words: a grain's step is a push everyone shares, plus a random kick. Drop the push and you have pure diffusion; drop the kick and every grain marches in lockstep.
Both terms are knobs in the lab. The push, v, is advection — a current the whole crowd rides, the same knob the reaction–diffusion dish just grew on its tank walls. The kick's size is set by D: that's diffusion.
And here's the fun part. If D changes from place to place, a grain just uses whatever value holds where it's standing — no extra rule needed. That has a lovely side effect: grains dawdle wherever the kicks are weak, so the crowd quietly piles up on slow ground. One species, zero interactions between grains, and already a pattern-maker. (Serious transport codes add a correction to cancel that pile-up when they don't want it. Our lab keeps the naive version, because here the pile-up is the whole show — go paint some.)
Every symbol, once
- ρ
- density — how crowded it is at one spot: grains per unit of length. The tall middle of the curve means "lots of grains here."
- x
- position — where along the line we're looking.
- t
- time — the clock reading right now.
- Δt
- one tick — the gap between one step and the next. "Δ" just means "a small amount of," so Δt is a small amount of time.
- h
- the stride — how far a single blind step carries a grain.
- D
- the diffusion coefficient — how vigorously this stuff spreads, built from the walk itself as h² ⁄ 2Δt. The lab's jitter slider.
- v
- drift — a steady push the whole crowd shares. Zero means no current.
- ξ
- the coin flip, grown up — a fresh random number every tick, centered on zero and typically about ±1. This is the only place chance enters.
- ∂ρ/∂t
- rate of change of density in time — stand still at one spot, watch the clock, and see how fast the crowd there grows or thins. (Course 2, Step 5 introduced the ∂.)
- ∂²ρ/∂x²
- how sharply the density curve bends in space — the curvature meter: me, versus the average of my neighbors.
In code: one line of physics per axis
This is the entire simulator below — no grid for the physics, no Laplacian, no stencil. Compare it with the bead loop of Course 2: dT[i] = α·((T[i−1]+T[i+1])/2 − T[i]). Same equation; the beads update amounts at fixed places, the walkers update places of fixed grains.
The lab
24 000 grains, live. Two regimes. Sealed dish: walls reflect, nothing is born or dies — a drop of ink spreading; add drift and the floor turns it into an atmosphere, dense below, thin above. Flow-through: grains rain in at a slot up top, ride the drift down, and die at rate k — a steady plume, the textbook picture of a contaminant leaking into groundwater. In both, drag on the canvas to paint slow ground and watch the crowd gather where it dawdles.
The walker field every dot is one grain · drag to paint slow ground (violet) · squint to see the field the PDE talks about
What to try: sealed dish, drift up, jitter low — the exponential atmosphere. Then flow-through with a slow patch mid-stream: the plume fattens and brightens inside it, exactly like a contaminant stalling in dense clay. Then hit squint: the moment the grains blur into a field, you're back in the grid world of Courses 2–4. That colormap is 24 000 grains, squinted at — the real ones are 10²³.