An interactive demo created by Claude Opus 5.5, based on the lecture notes by Sang Hoon Lee (Chapter 7, Quantum Statistics)
A small system sits against a huge reservoir at fixed temperature \(T\) and chemical potential \(\mu\). It trades energy and particles freely, so even \(N\), the number of particles inside, keeps changing. Watch it happen below.
The box is an ideal gas reservoir. The blue-tinted square is our system: an open region with no walls. Particles inside are drawn solid; those out in the reservoir are faded. Every few frames the demo counts them and adds that count to the histogram, building up the probability distribution of \(N\). Use Add particle type to mix in other species, each with its own chemical potential and mass.
Particle types
For an ideal gas \(\mu = k_{\mathrm{B}}T\ln(n v_Q)\), and a dilute gas has \(n v_Q \ll 1\), so \(\mu\) is negative. Raising it by \(k_{\mathrm{B}}T\) multiplies that type's density by \(e\). Because \(v_Q \propto m^{-3/2}\), a heavier type at the same \(\mu\) is denser, \(n \propto m^{3/2}e^{\mu/k_{\mathrm{B}}T}\), and it also moves more slowly.Histogram shows
| Type | N pred. | N meas. | σN | √N |
|---|---|---|---|---|
| Samples | 0 | |||
Give it a few seconds: the measured \(\sigma_N\) settles onto \(\sqrt{\bar{N}}\), which is exactly the ideal gas result derived in Problem 7.6 further down. With several types, the species don't interact, so each count is Poisson on its own, and so is the total, whose mean is just the sum of the individual means. Whatever the mass and \(\mu\), each histogram is Poisson; those two only set its mean and, through the speed, how quickly it fills. Side by side draws every type's measured histogram together with its own Poisson curve.
As in the canonical case, the probability of a system state is proportional to the number of reservoir microstates compatible with it:
The difference now is that particles can cross the boundary, so the \(\mu\) term in the thermodynamic identity stays (the \(P\,dV\) term is still negligible):
With \(dU_R = -dE\) and \(dN_R = -dN\), each state gets a weight called the Gibbs factor, and normalizing gives the grand partition function, or Gibbs sum:
The sum runs over every state of the system, including every possible value of \(N\). With several particle species, \(\mu N\) becomes \(\mu_A N_A + \mu_B N_B + \cdots\), which is exactly what we need for blood.
A single heme site in hemoglobin is a tiny grand canonical system. It can be empty, hold one O2 (binding energy \(\varepsilon\)), or hold one CO (binding energy \(\varepsilon'\)). Near the lungs, \(\mu\) for oxygen is about \(-0.6\ \mathrm{eV}\). CO binds more tightly, so even a trace of it in the air steals sites.
One site, sampled again and again. Each cell is a snapshot: gray empty, blue O2, red CO.
| 95 to 100% | Normal range |
| 91 to 94% | Mild hypoxemia, worth watching |
| 81 to 90% | Hypoxemia with difficulty breathing |
| 80% or below | Severe hypoxemia |
This is the lecture’s one-site model; real hemoglobin has four cooperating sites. Also, an ordinary two-wavelength pulse oximeter (like a smartwatch) cannot tell CO-bound hemoglobin from O2-bound hemoglobin, so it would still read near normal during CO poisoning. That is part of what makes CO so dangerous.
Problem 7.6. Differentiating the Gibbs sum with respect to \(\mu\) pulls down a factor of \(\beta N(s)\) each time, so with \(\beta = 1/k_{\mathrm{B}}T\):
Subtracting \(\bar{N}^2\) and comparing with \(\partial\bar{N}/\partial\mu\) gives a compact result:
For an ideal gas, \(\mu = -k_{\mathrm{B}}T \ln\!\left(V Z_{\text{int}} / N v_Q\right)\), so \(\partial\mu/\partial N = k_{\mathrm{B}}T/N\) and therefore \(\sigma_N = \sqrt{\bar{N}}\). The relative spread is \(\sigma_N/\bar{N} = 1/\sqrt{\bar{N}}\): large for a handful of particles, utterly invisible for a macroscopic sample.
Distribution of \(N\), drawn from \(0\) to \(2\bar{N}\) so the relative width is what you see.
The heme site above holds either 0 or 1 molecule. With only O2 around, \(\bar{N} = p\), and directly from the Gibbs sum the variance is \(\sigma_N^2 = p - p^2\). The general formula agrees: at the current settings (O2 only), \(\bar{N} = {}\)–, \(p - p^2 = {}\)–, and \(k_{\mathrm{B}}T\,\partial\bar{N}/\partial\mu = {}\)–.
Problem 7.7. The grand free energy \(\Phi \equiv U - TS - \mu N\) satisfies \(d\Phi = -P\,dV - S\,dT - N\,d\mu\), so \(N = -(\partial\Phi/\partial\mu)_{T,V}\). The candidate \(\tilde{\Phi} = -k_{\mathrm{B}}T\ln\mathcal{Z}\) obeys the same equation, since \((\partial\tilde{\Phi}/\partial\mu)_{T,V} = -\bar{N}\). At \(\mu = 0\) the Gibbs sum reduces to the ordinary partition function \(Z\), where \(-k_{\mathrm{B}}T\ln Z = F = \Phi\). Same differential equation, same starting point:
Below, \(\Phi(\mu)\) is plotted for the O2-only heme site, using the temperature and binding energy set in the hemoglobin section. Slide \(\mu\) and compare the slope of the tangent with the occupancy computed from the Gibbs sum.
\(\Phi = -k_{\mathrm{B}}T\ln\!\left(1 + e^{-(\varepsilon-\mu)/k_{\mathrm{B}}T}\right)\), in eV, with the tangent at the chosen \(\mu\).
Occupancy \(\bar{N}\) from the Gibbs sum. It switches on as \(\mu\) passes \(\varepsilon\).