In this post I derive the virial expansion for a classical gas of hard spheres. The nice part is watching the excluded volume correction come out of the algebra on its own, and at the end I look at the higher-order coefficients (which lead to a surprisingly good closed-form equation of state).
What the virial expansion actually computes
The ideal gas law works well, but it makes two simplifying assumptions that break down for real gases:
- Particles are point-like (zero volume)
- Particles don’t interact (no forces between them)
Real atoms and molecules violate both: they have finite size and exert forces on each other. The virial expansion systematically corrects for these effects by expanding in powers of the density:
where is the number density. The virial coefficients encode how interactions and finite size change the pressure. At low density (), we recover the ideal gas. As density increases, higher-order terms become important.
The hard sphere model captures the simplest finite-size effect: particles are impenetrable balls of diameter . The potential is:
This is more than a toy model (it is the starting point for real gases, liquids and even the glass transition). So the question is: how does this simple exclusion change the equation of state?
The partition function and why it’s hard to compute
For particles with Hamiltonian:
the classical partition function separates into momentum and position integrals:
where is the thermal wavelength. The momentum integral is easy (it gives the ideal gas result), but the position integral is the challenge:
For interacting particles, the Boltzmann factor doesn’t factorize, so we can’t separate this integral into independent pieces. This is why we need the Mayer expansion.
The Mayer f-function: turning a hard problem into a series
The trick is to define:
For hard spheres, this is very simple:
With this, the partition function becomes:
where . Now we can expand the product:
Each term represents a distinct cluster of interacting particles. The first term () gives the ideal gas. The linear terms () represent two-particle interactions. The quadratic terms represent three- and four-particle clusters, and so on.
Physically, the Mayer -function measures how far the Boltzmann factor of a pair deviates from the non-interacting value of 1. means no interaction (particles independent). means complete exclusion (particles can’t overlap).
Keeping only the first correction: why this is enough at low density
At low density, most particles are far apart and don’t interact. We only need to keep terms where a small number of particles are close together. Keeping only the linear term in :
The first term gives (the ideal gas contribution). The second term requires evaluating:
All pairs contribute equally, so we just need to compute one integral and multiply by the number of pairs.
Now change to center-of-mass and relative coordinates:
The Jacobian is , and the integral separates:
The center-of-mass integral just gives the volume . The relative coordinate integral is what contains the physics.
The second virial coefficient: what it actually means
Carrying through the algebra, the equation of state becomes:
For hard spheres:
This integral is the volume excluded by one sphere (of radius ), but with a negative sign because in the excluded region.
Plugging this in:
where the second virial coefficient is:
Geometrically, is four times the volume of one sphere. Where does the 4 come from? Each particle excludes a sphere of radius around itself (volume ), and we have to divide by 2 to avoid double-counting pairs.
Excluded volume: the physical picture
Rewriting the result as:
where is the excluded volume, we get a very clean statement:
The hard sphere gas behaves like an ideal gas with reduced volume.
Two spheres of diameter can’t have their centers closer than , so each particle forbids the center of any other particle from a sphere of radius around itself. That region has volume , which is 8 times the particle’s own volume . Each such exclusion is shared by a pair, so each particle is charged half of it: per particle, i.e. 4 particle volumes. For particles this gives .
So the pressure is higher than the ideal gas at the same density and temperature:
This makes sense: collisions between finite-sized particles transfer momentum more effectively than non-interacting point particles. The particles “bounce off” each other, increasing the pressure on the container walls.
Higher-order corrections
The virial expansion doesn’t stop at . The next term involves three-particle clusters and gives . For hard spheres:
Each higher coefficient involves more complicated cluster integrals. A convenient variable is the packing fraction , the fraction of the volume actually occupied by the spheres (equivalently ):
where the coefficients are pure numbers determined by geometry. The exact values are:
Only (from ) and (from ) are integers. is known in closed form, but it’s an ugly expression involving . The higher ones come from increasingly nasty cluster integrals, evaluated numerically. They lie very close to the integers , i.e. . Summing that integer sequence exactly gives the famous Carnahan–Starling equation of state:
This is an approximation, not an exact resummation, but an excellent one: it matches simulations of the hard-sphere fluid to within about a percent all the way up to the freezing point, . The pole at is unphysical. Hard spheres can’t be packed beyond (close packing), and the fluid branch ends well before that.
When does this matter? The expansion parameter is . For gases at STP, , so is a small correction. For liquids, , and many terms are needed.
Where this leaves us
So the virial expansion is a systematic way to go from point particles to a gas of particles with finite size, and already the first correction is the excluded volume: the particles have less room to move than in an ideal gas, so they hit the walls more often and the pressure goes up. For any other intermolecular potential you do the same thing, just with a different in the cluster integrals.