Grouping and Maxwell’s Demon
Neil D. Lawrence
2026-11-03
FW26, William Gates Building
Define This Week
Questions; MacKay’s balance; die grouping \(H=H(w)+\sum_i w_i H(p_i)\)
Gaussian vs Maxwell: \(H\) without a measure \(m\)
The demon: compartments and two ledgers
Worksheet 3: where can the entropy sit?
This Session
Quiz 2 (ten minutes); collect Worksheet 2
Questions / MacKay / grouping; then the missing measure
Compartments and two ledgers
Worksheet 3 after the fork
After This Lecture
Worksheet 2 due today, before the quiz
Worksheet 3 released (due 17 November, with Quiz 3)
Quiz 2
Paper; no notes, no network, no LLMs
Ten minutes
Worksheet 2 in as you sit
Questions, a Balance, and a Die
Composition wrapper only. Through-line: the game is the idealised yes/no world; the pans and then the cube are where mechanism spoils it. Stop MacKay after two-versus-three readings if the clock is tight. Protect three-faces-left as the known-ball echo, then the \(1\) –\(3\) / \(4\) –\(6\) cut versus odd/even as different groupings, then the extensive/intensive sentence. Do not include the Gaussian–Maxwell measure files here — lectures that want both include this file, then that one.
Bits as Balanced Questions
A fair yes/no answer distinguishes two equally likely cases — one bit .
\(N\) equally likely objects \(\Rightarrow\) worst case \(\lceil\log_2 N\rceil\) bits
Twenty questions reach about a million hypotheses (\(2^{20}\) )
Unequal priors: best questions still split probability as evenly as possible
The same idea, with a different instrument, comes next — MacKay’s balance.
MacKay’s Balance and Balls
Twelve Balls, One Odd
MacKay’s weighing problem, Exercise 4.1 (MacKay, 2003) : twelve balls; exactly one is odd; it may be heavier or lighter.
A two-pan balance and twelve identical balls.
Instrument: a two-pan balance
Task: identify the odd ball and whether it is heavy or light
State the puzzle. Do not list the readings of the balance, and do not walk through which balls go on which pan.
How Should We Proceed?
We have a finite list of hypotheses and a physical instrument. How should we think?
What, exactly, do we need to name?
What would count as a useful use of the balance?
When would we know we were done?
Leave this live. Do not say left, right, or level, and do not say three. After they have named the hypotheses, try the two-outcome story next — as if this were the information game again.
Let’s Try Two Outcomes
Treat the balance as the information game: left heavy or right heavy only.
Two readings \(\Rightarrow\) at most \(\log_2 2\) bits per use
Mechanism next: what we actually put on the pans
Maths stays on its own slides — the two accounts can disagree
Say ``log two bits’’ — one bit if the two readings are equally likely. Do not yet mention a third reading. Board 6 vs 6 as the move people reach for from twenty questions.
Maths: Two Readings
Maths. Start from \(\log_2 24\) . Each use returns at most \(\log_2 2\) .
\[
\log_2 24 \approx 4.58,\qquad 2^4 = 16 < 24 \le 32 = 2^5
\]
Four uses cannot name 24 hypotheses
Five uses are not ruled out, if each use really returns one bit
That ``if’’ is mechanism, not maths
Mechanism: 6 vs 6
Mechanism. Put six against six.
The pans will tip — the odd ball is on one side
Follow the down pan, as if the odd ball were heavier
Six balls remain under that story
Ask what we actually learned. Under ``it is heavier’’, 12 balls become 6, one bit toward which ball. We do not know the direction. The down pan is six maybe-heavies; the up pan is six maybe-lights. All twelve balls are still in play. Maths next.
Maths: What 6 vs 6 Bought
Maths. Score the same physical act on the 24 hypotheses.
24 \(\to\) 12 remaining hypotheses: exactly \(\log_2 2\) bits
Zero balls eliminated — each ball is still possibly odd
The bit went into a coupling of group and direction
Mechanism: 3 vs 3
Mechanism. Keep going as a binary search of the balls: three against three.
Under the heavier-side story, three balls remain
Same move, smaller pile
We are still not asking about light versus heavy
Mechanism: Three Left
Mechanism. Three balls remain. We cannot put one and a half on a pan.
2 vs 2 needs a fourth ball
Borrow one of known normal mass
Then 1 vs 1 on whatever the 2 vs 2 leaves
Make them say the known ball out loud. Ask: how many bits do we get from 2 vs 2 now? Do not calculate before they see that the split of three remaining balls cannot be even.
Maths: The Known Ball Taxes the Bit
Maths. Three remaining heavier-suspects; pans are 2 vs 1+known.
\[
\left(\tfrac{2}{3},\tfrac{1}{3}\right)
\quad\Rightarrow\quad
H = h_2\!\left(\tfrac{2}{3}\right) \approx 0.92 < 1 \text{ bit}
\]
The even split was \(\log_2 2\) ; the pans cannot make it
Padding with a known ball is a mechanism patch
Information gain falls because the probabilities are no longer equal
Mechanism: 1 vs 1
Mechanism. If two suspects remain, weigh them against each other.
Now the split can be even
Under the heavier story, this names the ball
We still have not asked light versus heavy
Mechanism: Lighter or Heavier?
Mechanism. We have a candidate ball. Can we name the direction?
Weigh the candidate against a known normal
Two outcomes name heavy versus light — if it tips
If it balances , our heavier-side story was wrong
This is the crack in the two-outcome attempt. A known-normal comparison is the natural test for direction, and it keeps offering a third reading: level. The instrument was never a yes/no question. Pause, then the aha slide.
Two Accounts, One Experiment
Keep the columns separate.
Maths: \(\log_2 24\) to close; at most \(\log_2 2\) per two-outcome use
Mechanism: 6 vs 6, 3 vs 3, 2 vs 2 with a known, 1 vs 1, then direction
The known ball, and the unused ``level’’ reading, are mechanism — they change the gain
Aha: It Balances Three Ways
The pans also sit level . Left heavy, right heavy, or balance.
The instrument was never a yes/no question
6 vs 6 made the third reading impossible
That was a mechanism choice that threw away a symbol
Let them say the three readings. Then go straight to the new budget. Do not start the 4 vs 4 tree.
Maths: Three Readings
Maths. Each use now returns at most \(\log_2 3\) .
\[
\log_2 3 \approx 1.58,\qquad 3^2 = 9 < 24 \le 27 = 3^3
\]
Two uses cannot name 24 hypotheses
Three uses can, if each use really returns \(\log_2 3\)
Same ``if’’ as before: mechanism must realise the split
Mechanism Must Collect \(\log_2 3\)
Mechanism. To earn \(\log_2 3\) , all three readings must be possible and near equal.
First weighing: 4 vs 4, not 6 vs 6 — so level can happen
A known ball, or emptying a reading, is again a tax
Optimal play keeps the three readings as near equiprobable as possible
Doable in Three — Strategy Deferred
The counting argument shows three weighings must be enough in principle.
We do not give the sequence of groupings today
Info gained and mechanism are separate ledgers — score both
Same moral as twenty questions: split the prior evenly, now three ways
Stop here. Invite them to try Exercise 4.1 before reading MacKay’s solution figure. Optional aside: 1–6 vs 7–12 can never balance, so it yields only one bit and is already suboptimal once we know there are three readings .
Coarse-Graining a Die
A fair die has \(H(X)=\log_2 6\approx 2.58\) bits.
Stage the question: does every yes/no cost one bit?
First cut: odd or even?
Second cut: is it a six?
Same total either way — different prices for the first answer
Board both partitions. Odd/even is balanced so exactly 1 bit. ``Is it six?’’ is not one bit — students often assume every binary question buys a bit. That is the MacKay moral applied to grouping.
Odd or Even: Exactly One Bit
Groups \(\{1,3,5\}\) and \(\{2,4,6\}\) are equiprobable.
\[
H(G_{\mathrm{parity}})=1 \text{ bit},
\qquad
H(X\mid G_{\mathrm{parity}})=\log_2 3 \approx 1.585 \text{ bits}
\]
Group label: fair coin — one bit
Inside either group: three equally likely faces
Total: \(1+\log_2 3=\log_2 6\)
“Is It a Six?”: Not One Bit
A yes/no question is one bit only when the two answers are equiprobable.
\[
w=\Bigl(\tfrac16,\tfrac56\Bigr),
\qquad
H(G_{\mathrm{six}})=h_2\Bigl(\tfrac16\Bigr)\approx 0.65 \text{ bits}
\]
Yes (\(X=6\) ): no residual uncertainty
No: five faces left, \(H=\log_2 5\)
Remaining: \(\tfrac56\log_2 5\approx 1.93\) bits
Total again \(\approx 0.65+1.93=2.58=\log_2 6\)
Same Total, Different First Cut
However you slice the questions, you pay \(\log_2 6\) in total.
Odd/even first: pay \(1\) , then \(\log_2 3\)
Six-or-not first: pay \(\approx 0.65\) , then \(\approx 1.93\)
Coarse-graining keeps only the group term and throws away the rest
Grouping Composition
Uncertainty splits into stages: which group, then where inside the group.
\[
H(X)=H(w)+\sum_i w_i\, H(p_i)
\]
\(w_i\) : probability of group \(i\)
\(p_i\) : distribution inside group \(i\)
First term: cost of the coarse label; second: average residual detail
This is the chain rule for a deterministic grouping \(G=g(X)\) : \(H(X)=H(G)+H(X\mid G)\) . Board that identification. Khinchin pointer only — consistency under staged questions characterises Shannon \(H\) ; no proof today.
Reverse Direction
Learning the face determines the group for free. What is left to find after the group?
\(H(G\mid X)=0\) : the coarse label is redundant given \(X\)
Information extracted by the group: \(I(X;G)=H(G)\)
Information still to find : \(H(X\mid G)\)
Why the Total Is Invariant
Entropy is the uncertainty that is consistent no matter how you decompose a question into stages.
Any partition: \(H(w)+\sum_i w_i H(p_i)\) returns the same \(H(X)\)
That consistency is special to the Shannon form (Khinchin; later Baez–Fritz–Leinster)
Pointer only today — grouping is Shannon’s third requirement in 1948; the axioms stay parked
Grouping Is a Choice of Abstraction
Keeping \(\{1,2,3\}\) versus \(\{4,5,6\}\) and refusing the face is the same move as a macrostate.
The group label is what we keep; \(\sum_i w_i H(p_i)\) is what we refuse
Macroscopic variables: extensive \(N,V,E,S\) ; intensive \(T,P\)
We cannot follow Laplace’s curves, so we keep a few numbers
Callback only — extensive versus intensive was week 2. Do not re-derive. Do not open MaxEnt, Lagrange, or the demon. The next include, if you want it, is the Gaussian-Maxwell measure arc. Units: the die was bits; those figures are nats. Same \(H\) , different \(\log\) base.
Gaussian, Maxwell–Boltzmann, and the Missing Measure
Composition wrapper only. Children carry the figures. Stop before MaxEnt / Lagrange / the die.
Entropy of a Gaussian Velocity Histogram
Equal-width bins of one Cartesian component. Discrete \(H\) is a sum over masses.
\(p_i = n_i/N\) from equal-\(\Delta v\) bins of \(v_x\sim\mathscr{N}\left(0,\sigma^2\right)\)
\(H=-\sum_i p_i \log p_i\) depends only on those masses
Analytic \(h=\tfrac12\log(2\pi e \sigma^2)\) ; the histogram tracks \(h-\log\Delta\)
Callback to the week-2 velocity histogram. Board \(p_i\approx f\Delta\) once. The two numbers on the figure should agree; \(h\) itself is smaller by \(\log\Delta\) (and is negative if \(\Delta\) is large). Nats throughout.
Histograms as Riemann Sums
A histogram replaces \(f(x)\) by a piecewise-constant function: height \(f(x_i)\) on each bin of width \(\Delta\) .
Bin mass \(p_i = \int_{\text{bin } i} f(x)\,\text{d}x \approx f(x_i)\Delta\) (midpoint rule)
\(\sum_i g(x_i)\Delta \to \int g(x)\,\text{d}x\) as \(\Delta\to 0\)
Used twice: \(\sum_i f_i\Delta \approx 1\) and \(-\sum_i f_i\log f_i\,\Delta \approx h\)
So \(H \approx h - \log\Delta\) : the \(-\log\Delta\) comes from the \(\Delta\) inside the log
Draw the Gaussian, overlay rectangles of width \(\Delta\) and height \(f(x_i)\) , shade one rectangle and label its area \(p_i\) . Then split \(\log(f_i\Delta)\) on the board. Point out that the second sum is not a Riemann sum of anything finite as \(\Delta\to 0\) , which is why \(H\) diverges while \(h\) doesn’t.
Equal-width histogram of one Cartesian velocity component. Discrete \(H\) matches \(h-\log\Delta\) ; \(h\) itself is the remainder after the bin-width term is subtracted.
Pushed Bins Keep the Same Entropy
The same cells, written on the speed axis: masses unchanged, widths change.
Equal-volume shells in 3D velocity: equal width in \(u=s^3\)
Push the edges to \(s=u^{1/3}\) ; \(\Delta s_i\) now grows then shrinks
\(H\) is a functional of the masses — it does not see the widths
Left panel: probability bars, equal visual width, height \(p_i\) . Right: density \(p_i/\Delta s_i\) with the true speed widths. Same \(H\) on both. This is a 1–1 relabelling of a partition of speed (volume coordinate \(\leftrightarrow\) speed). Folding \(v\mapsto|v|\) , or grouping Cartesian cubes into shells, merges cells and drops \(H\) . That is not this figure.
Equal-volume shells in 3D velocity, written two ways. Left: probability masses. Right: the same masses as a density on the speed axis. The bins change shape; \(H\) does not.
The Continuous Limit Drops \(\log\Delta\)
As the bins shrink, discrete \(H\) tracks \(-\log\Delta\) to infinity. Differential \(h\) is what remains.
\(H(X^\Delta)\approx h-\log\Delta\)
\(-\log\Delta\to+\infty\) as \(\Delta\to 0\)
Passing to a density throws that term away
The scatter should sit on the line \(h-\log\Delta\) . The horizontal line at \(h\) is the finite remainder. The move to a continuous entropy is exactly ignoring a term that is driving to \(+\infty\) .
Discrete entropy of an equal-width Gaussian histogram against \(-\log\Delta\) . The points track \(h-\log\Delta\) ; \(h\) is the finite part. The continuous limit discards a term that diverges.
Entropy of the Maxwell Speed Law
The speed \(s=|\mathbf{v}|\) is a different random variable, with a different \(h\) .
\(f(s)=4\pi s^2(2\pi\sigma^2)^{-3/2}e^{-s^2/2\sigma^2}\)
\(h(s)=\log(\sigma\sqrt{2\pi})+\gamma-\tfrac12\) , not \(\tfrac12\log(2\pi e\sigma^2)\)
Why is this number not the Gaussian’s \(h\) ?
Overlay the Maxwell curve on an equal-\(\Delta s\) histogram of the same 3D sample. Read both numbers. The Gaussian \(h\) was for \(v_x\) ; this \(h\) is for \(s\) . Different variable and different Lebesgue measure. Leave the Jacobian for the next snippet.
Equal-width histogram of speed from the same 3D Gaussian sample. Discrete \(H\) tracks \(h(s)-\log\Delta\) . The Maxwell \(h(s)\) is not the Gaussian \(h(v_x)\) .
Two Discretisations of the Same Speeds
Equal \(\Delta s\) is a different partition from the pushed equal-volume cells. Discrete \(H\) changes.
Same samples \(s=|\mathbf{v}|\) , two partitions
Pushed: equal 3D volume (\(u=s^3\) ); uniform: equal \(\Delta s\)
The discretisation is the measure
Side by side: same \(N\) , same \(s_{\max}\) , same number of bins. Only the edge placement changes. Two values of \(H\) . Uniform-in-\(s\) is Lebesgue on the speed axis; equal-volume is Lebesgue in 3D, written in \(s\) .
The same speed samples, two partitions, two values of discrete \(H\) . Left: equal 3D volume, pushed to the speed axis. Right: equal \(\Delta s\) . The discretisation is the measure.
Bin Widths Are a Radon-Nikodym Derivative
The ratio of widths is the discrete Jacobian. It converts one \(h\) into the other.
Same cells: \(H\) is shared; \(h\approx H+\sum_i p_i\log\Delta_i\)
\(\Delta s_i/\Delta u_i \to |{\mathrm{d}s}/{\mathrm{d}u}|=1/(3s^2)\)
Continuum name: Radon-Nikodym derivative between the two measures
Board \(h\approx H+\sum p_i\log\Delta_i\) for unequal bins. The difference of the two remainders is \(\sum p_i\log(\Delta s_i/\Delta u_i)\) , which tracks \(\mathbb{E}\log|J|\) . Do not do \(\sigma\) -algebras. The width ratio is the discrete RN derivative.
Width ratio of the pushed equal-volume cells, against the Jacobian \(1/(3s^2)\) . The average log-ratio converts \(h(u)\) into \(h(s)\) . That ratio is the discrete Radon-Nikodym derivative.
Maxwell’s Demon, Compartments, Two Ledgers
Composition wrapper only. Overview (quote and canvas), then extra partitions, then number versus energy at the gate, then the fork. Canvas handedness: hot left to right, right bulk heats. Detailed-balance already includes the compartments and the fork, so a lecture that already pulls that file gets the new order. Do not include Gaussian–Maxwell, grouping composition, Szilard, Landauer, or Ellis here. Stop before the worksheet.
Maxwell’s Demon
Maxwell’s demon was designed to highlight the statistical nature of the second law of thermodynamics.
Maxwell’s Demon. The demon decides balls are either cold (blue) or hot (red) according to their velocity. Balls are allowed to pass the green membrane from right to left only if they are cold, and from left to right only if they are hot. The displayed entropy is the Shannon entropy of the velocity histogram (a coarse-grained proxy, not full thermodynamic entropy).
Detailed Balance Across the Membrane
What Does the Membrane Do?
The JavaScript demon is a selective membrane : one speed threshold \(v_\star\) , opposite rules on each side.
Left \(\to\) right: pass only if \(v > v_\star\) (hot)
Right \(\to\) left: pass only if \(v \le v_\star\) (cold)
Elastic collisions remix velocities; the membrane only gates crossings
Match the canvas: red = hot, blue = cold, green strip = membrane. Threshold in the sim is \(v_\star=3\) with initial speed \(5\) .
Steady State \(=\) Balanced Fluxes
In a steady state the number of balls leaving left equals the number leaving right — detailed balance of membrane crossings.
Assume each side thermalises to a 2D Maxwellian at its own \(T_L\) , \(T_R\)
Particle flux \(L\to R\) : only the hot tail, \(v>v_\star\)
Particle flux \(R\to L\) : only the cold body, \(v\le v_\star\)
Steady state: \(\Phi_L^{\mathrm{hot}}(n_L,T_L)=\Phi_R^{\mathrm{cold}}(n_R,T_R)\)
Local equilibrium is an approximation: collisions fast compared with crossings. Energy flux need not balance under the same Maxwellians — flag that after the calculation.
Left: temperatures on each side of the selective membrane from particle-flux detailed balance at equal populations (simulation energy budget). Right: entropy of the two-Maxwellian state minus the single-temperature equilibrium. The red point is the simulation threshold \(v_\star=3\) .
Temperatures Split; Entropy Falls
For the simulation budget, particle-flux balance at equal \(N\) yields \(T_L\approx 1.9\) , \(T_R\approx 23\) (\(k_B=1\) ) — a large split.
Unconstrained equilibrium: one \(T_0=\langle\mathrm{KE}\rangle\) , entropy \(S_0\)
Membrane steady state: \(S_{\mathrm{ss}}<S_0\) (here \(\Delta S\approx -24\) nats at \(N=39\) )
The gas alone looks like a second-law violation
Live the numbers from the plotcode printout. Canvas entropy is a coarse velocity-bin proxy; this \(S\) is the ideal-gas Shannon entropy of two Maxwellians.
Maxwellians Are Only an Approximation
Particle balance and energy balance cannot both hold for two Maxwellians — the true steady state depletes velocity tails.
Hot crossings carry more energy per ball than cold crossings
Equal number fluxes still leave a net energy flux under Maxwellians
Collisions rebuild the tails; the membrane continually sculpts them
Local-\(T\) picture still predicts the direction and an entropy deficit
Do not oversell the numbers as exact NESS values. The point is the ledger: gas entropy down; cost elsewhere.
Where Did the Entropy Go?
The membrane implements Maxwell’s sorting policy. The gas entropy falls; Clausius is not repealed.
Prescription: the velocity gate (who may cross)
No-go: you cannot harvest that \(\Delta S\) for free in a cycle
Next: Szilard priced measurement; Landauer priced erasure; Bennett (1982) made the erasure resolution
Bridge forward. Ellis locates dissipation at measurement/gating; information ledger locates it at stored outcomes and erasure. Same Clausius, different bookkeeping.
The Demon Sorts Groups
Hot versus cold is a coarse label — this lecture’s grouping, now with a policy.
Group \(G\) : pass / no-pass under the membrane rule (tail vs body)
Within group: collisions try to restore a Maxwellian \(\pi_G\)
Local-equilibrium assumption: mixing inside each side is fast vs crossings
Callback to the die: the demon pays attention to \(H(w)\) over coarse velocity sets and hopes the within-group term stays near equilibrium. The detailed-balance calculation above already used that hypothesis.
Lumpability (Pointer)
When do the groups themselves form a Markov process?
If exit rates agree for every microstate in a group \(\Rightarrow\) coarse chain is Markov (lumpable)
Otherwise coarse-graining leaves memory — projection operators (Zwanzig/Mori), not this course’s core
Demon membrane: approximately lumpable only while local equilibrium holds