An interactive demo created by Claude Opus 5.5, based on the lecture notes by Sang Hoon Lee (Chapter 7, Quantum Statistics)

The grand canonical ensemble

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.

Particles come and go

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.

Measured frequency of each \(N\) Poisson prediction with the same mean
Share of the box covered by the system.

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.
Predicted \(\bar{N}\)
–
Measured \(\bar{N}\)
–
Measured \(\sigma_N\)
–
\(\sqrt{\bar{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.

The Gibbs factor

As in the canonical case, the probability of a system state is proportional to the number of reservoir microstates compatible with it:

\[ \frac{P(s_2)}{P(s_1)} = \frac{\Omega_R(s_2)}{\Omega_R(s_1)} = e^{[S_R(s_2) - S_R(s_1)]/k_{\mathrm{B}}} \]

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):

\[ dS_R = \frac{1}{T}\left(dU_R + P\,dV_R - \mu\,dN_R\right) \]

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:

\( \displaystyle P(s) = \frac{1}{\mathcal{Z}}\, e^{-[E(s) - \mu N(s)]/k_{\mathrm{B}}T} \)
\[ \mathcal{Z} = \sum_s e^{-[E(s) - \mu N(s)]/k_{\mathrm{B}}T} \]

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.

Why carbon monoxide wins

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.

Unoccupied

Gibbs factor1
Probability–

Holding O2

Gibbs factor–
Probability–

Holding CO

Gibbs factor–
Probability–
\( \mathcal{Z} = {} \)

One site, sampled again and again. Each cell is a snapshot: gray empty, blue O2, red CO.

–
of sites carry oxygen
95 to 100%Normal range
91 to 94%Mild hypoxemia, worth watching
81 to 90%Hypoxemia with difficulty breathing
80% or belowSevere hypoxemia
\(k_{\mathrm{B}}T = {}\) meV
Lower values mean thinner air, as at high altitude or deep in tissue.
Then \(\mu' = \mu - k_{\mathrm{B}}T \ln(\text{ratio}) = {}\) eV

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.

How big are the fluctuations?

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\):

\( \displaystyle \bar{N} = \frac{k_{\mathrm{B}}T}{\mathcal{Z}}\,\frac{\partial \mathcal{Z}}{\partial \mu}, \)\( \displaystyle \overline{N^2} = \frac{(k_{\mathrm{B}}T)^2}{\mathcal{Z}}\,\frac{\partial^2 \mathcal{Z}}{\partial \mu^2} \)

Subtracting \(\bar{N}^2\) and comparing with \(\partial\bar{N}/\partial\mu\) gives a compact result:

\( \displaystyle \sigma_N = \sqrt{\overline{N^2} - \bar{N}^2} = \sqrt{k_{\mathrm{B}}T \,\frac{\partial \bar{N}}{\partial \mu}} \)

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.

\(\sigma_N = \sqrt{\bar{N}}\)
–
\(\sigma_N/\bar{N}\)
–

It works beyond the ideal gas, too

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 = {}\)–.

The grand free energy

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:

\( \displaystyle \Phi = -k_{\mathrm{B}}T \ln \mathcal{Z} \)

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\).

\(\Phi\) at this \(\mu\)
–
\(-\partial\Phi/\partial\mu\) (tangent slope)
–
\(\bar{N}\) from the Gibbs sum
–