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. No grid, no cells, no neighbor averages — just grains, each one ignorant of calculus, and the smooth fields of Course 2 reappearing as crowd behavior.
In words: two bookkeepings for one physics
A random walker's entire rulebook is one sentence: every tick, take one blind step. It never reads a derivative, never consults a neighbor, never knows where the crowd is. Each grain is pure chance — and yet zoom out, and the crowd's density obeys the deterministic heat equation, every time. The law doesn't live in any walker; it lives in the counting.
So there are two honest ways to keep the books. Stand at a fixed point and track how much stuff is here — that's the grid world of Courses 2–4, and it's called the Eulerian view. Or ride along with one grain and track where it goes — the Lagrangian view, this page. Same physics, opposite bookkeeping: the PDE is the exact law of the average cloud, and the walk is one honest sample of it. Run n walkers and the histogram hugs the PDE's solution with fluctuations that shrink like 1/√n. The graininess you'll see below isn't rendering noise — it's the physics the smooth field throws away. Real diffusion, at low concentration, is grainy.
In math: count, don't integrate
Why coin flips add up to the heat equation, in two lines. For a walker to stand at x a tick from now it must be one stride away right now — at x−h or x+h — and each arrives with probability ½. So the density's bookkeeping is:
The change in one tick is the average of my neighbors, minus me — the exact bracket every bead chased in Course 2, Step 6. Shrink the stride and the tick together and the bracket becomes a second derivative:
Note what D turned out to be: the walk's own stride, squared, per tick. The material constant of Course 2 is just how hard the grains jitter. And the single grain has its own law — the one the simulator below actually runs. Its displacement each tick is a drift plus a jitter:
Each term is one knob of the lab. The drift v is advection — a current everything rides (our reaction–diffusion dish just grew the same knob). The jitter √(2DΔt) is diffusion. And if D varies from place to place, the grain simply uses the local value where it stands — with the delicious side effect that grains linger wherever the jitter is weak, so crowds silently pile up on slow ground. One species, zero interactions, and already a pattern-maker. (Getting rid of that pile-up — when you don't want it — needs a correction drift ∇D; real transport codes carry it. The lab keeps the naive scheme, because the pile-up is the show.)
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²³.