Search

Search papers and lessons

Partition Function

Level 3 · 10 min read

The partition function Z is the sum of Boltzmann factors over all states of a system; dividing by it gives probabilities, and its logarithm gives the free energy.

On this page

  • Colour = topic mix
  • Discrete math
  • Thermal physics
  • Probability
  • Sign in to see your progress

TL;DR

The partition function ZZ is one number that adds up the Boltzmann factor e−E/kBTe^{-E/k_B T} over every state a system can be in. Dividing each factor by ZZ gives the probability of that state. The logarithm of ZZ carries the thermodynamics: energy, entropy and free energy all come from it.

Where you'll see it: computing the average energy of a gas, a magnet or a molecule at a given temperature, predicting how a chemical reaction shifts with temperature, and estimating free-energy differences in computer simulations.

Intuition

A system at fixed temperature does not sit in one state. It keeps wandering through its possible states, and the Boltzmann distribution says how often it visits each one: low-energy states dominate, high-energy states are rarer (see Boltzmann Distribution). To turn that into numbers you need a normalising total, the sum of all the weights, so that the probabilities add to 1. That total is the partition function.

It is worth thinking of ZZ as a count of how many states the system effectively has access to at temperature TT. A state with energy far above kBTk_B T contributes almost nothing to the count. A state with energy well below kBTk_B T contributes almost one full unit. So ZZ is roughly the number of states that are "reachable" given the thermal energy available.

For a system with just two states, the ground state at energy 0 and an excited state at energy ΔE\Delta E, the partition function is Z=1+e−ΔE/kBTZ = 1 + e^{-\Delta E / k_B T}. The plot below shows how it depends on the ratio ΔE/kBT\Delta E / k_B T.

01234511.21.41.61.82energy gap divided by k_B Tpartition function Z
  • two-state Z
When the gap is zero, both states count fully and Z equals 2. When the gap is much larger than k_B T, only the ground state counts and Z approaches 1.

The reason ZZ matters beyond normalising probabilities is that it packs all the thermodynamics into a single function. If you know how ZZ depends on temperature, you know the rest.

The math

Let a system have states labelled i=1,2,3,…i = 1, 2, 3, \dots, with energies EiE_i. Let TT be the absolute temperature in kelvin and kBk_B the Boltzmann constant. Write β=1/(kBT)\beta = 1/(k_B T) as shorthand for the inverse thermal energy.

Definition: Partition function

For a system in thermal equilibrium with a heat bath at temperature TT, the partition function is

Z=∑ie−βEi=∑ie−Ei/kBT.Z = \sum_{i} e^{-\beta E_i} = \sum_{i} e^{-E_i / k_B T}.

The sum runs over every state of the system, counted once each. The probability of state ii is then Pi=e−βEi/ZP_i = e^{-\beta E_i} / Z.

Probabilities and averages

The probabilities follow directly from the definition, and they sum to 1 by construction: ∑iPi=∑ie−βEi/Z=Z/Z=1\sum_i P_i = \sum_i e^{-\beta E_i}/Z = Z/Z = 1.

The average energy is the probability-weighted sum of the energies, ⟨E⟩=∑iPiEi\langle E \rangle = \sum_i P_i E_i. There is a shortcut. Differentiate ln⁡Z\ln Z with respect to β\beta:

∂ln⁡Z∂β=1Z∑i(−Ei)e−βEi=−⟨E⟩.\frac{\partial \ln Z}{\partial \beta} = \frac{1}{Z} \sum_i (-E_i) e^{-\beta E_i} = -\langle E \rangle.

So

⟨E⟩=−∂ln⁡Z∂β.\langle E \rangle = -\frac{\partial \ln Z}{\partial \beta}.

One derivative of the logarithm gives the average energy. No separate sum over probabilities is needed.

Free energy and entropy

Define the Helmholtz free energy FF by

F=−kBTln⁡Z.F = -k_B T \ln Z.

From F=U−TSF = U - TS with U=⟨E⟩U = \langle E \rangle, the entropy follows as S=(U−F)/TS = (U - F)/T. Substituting gives

S=⟨E⟩T+kBln⁡Z.S = \frac{\langle E \rangle}{T} + k_B \ln Z.

This also agrees with the Gibbs entropy S=−kB∑iPiln⁡PiS = -k_B \sum_i P_i \ln P_i. Taking the logarithm of Pi=e−βEi/ZP_i = e^{-\beta E_i}/Z gives ln⁡Pi=−βEi−ln⁡Z\ln P_i = -\beta E_i - \ln Z. Multiplying by −kBPi-k_B P_i and summing gives −kB∑iPiln⁡Pi=kBβ⟨E⟩+kBln⁡Z-k_B \sum_i P_i \ln P_i = k_B \beta \langle E \rangle + k_B \ln Z, and since kBβ=1/Tk_B \beta = 1/T this is the same expression.

Differences between systems

Only ratios of partition functions are needed to compare two systems, or two conditions of the same system, at the same temperature. The free-energy difference is

FB−FA=−kBTln⁡ZBZA.F_B - F_A = -k_B T \ln\frac{Z_B}{Z_A}.

This is why simulations often estimate ZZ ratios rather than ZZ itself. Any constant shift in all energies multiplies every term by the same factor e−βE0e^{-\beta E_0}, so it cancels from the probabilities and from differences of free energy, but it shifts the absolute value of FF by E0E_0.

Worked examples

Example 1: a two-state magnet

A tiny magnet has two states. In a field BB its magnetic moment μ\mu either aligns with the field, with energy −μB-\mu B, or points against it, with energy +μB+\mu B. Choose the temperature so that μB=kBT\mu B = k_B T, which means βμB=1\beta \mu B = 1.

Example
Two-state magnet at $\mu B = k_B T$
  1. Boltzmann factors: aligned gives e−β(−μB)=e1≈2.71828e^{-\beta(-\mu B)} = e^{1} \approx 2.71828; opposed gives e−β(μB)=e−1≈0.36788e^{-\beta(\mu B)} = e^{-1} \approx 0.36788.
  2. Partition function: Z=2.71828+0.36788=3.08616Z = 2.71828 + 0.36788 = 3.08616.
  3. Probability aligned: P↑=2.71828/3.08616≈0.88080P_\uparrow = 2.71828 / 3.08616 \approx 0.88080.
  4. Probability opposed: P↓=0.36788/3.08616≈0.11920P_\downarrow = 0.36788 / 3.08616 \approx 0.11920.
  5. Average energy in units of μB\mu B: ⟨E⟩/μB=−0.88080+0.11920=−0.76159\langle E \rangle / \mu B = -0.88080 + 0.11920 = -0.76159. This matches −tanh⁡(1)=−0.76159-\tanh(1) = -0.76159, the closed form ⟨E⟩=−μBtanh⁡(βμB)\langle E \rangle = -\mu B \tanh(\beta \mu B) from Z=2cosh⁡(βμB)Z = 2\cosh(\beta \mu B).
  6. Entropy in units of kBk_B: S/kB=⟨E⟩/(kBT)+ln⁡Z=−0.76159+1.12693=0.36533S / k_B = \langle E \rangle / (k_B T) + \ln Z = -0.76159 + 1.12693 = 0.36533.

Interpretation: the magnet is aligned about 88 percent of the time. Its entropy, 0.37 kBk_B, is well below the maximum of ln⁡2≈0.69 kB\ln 2 \approx 0.69\,k_B that two equally likely states would give. The gap between the two states is large enough to bias the system, but not large enough to freeze it.

Example 2: a vibrating molecule

A diatomic molecule vibrates like a mass on a spring. Its energy levels are En=(n+12)ℏωE_n = (n + \tfrac12)\hbar\omega for n=0,1,2,…n = 0, 1, 2, \dots, where ℏω\hbar\omega is the energy quantum. Let x=ℏω/kBTx = \hbar\omega / k_B T. The partition function is a geometric series (see Summation Notation):

Z=∑n=0∞e−x(n+1/2)=e−x/2∑n=0∞(e−x)n=e−x/21−e−x.Z = \sum_{n=0}^{\infty} e^{-x(n + 1/2)} = e^{-x/2} \sum_{n=0}^{\infty} \left(e^{-x}\right)^n = \frac{e^{-x/2}}{1 - e^{-x}}.
Example
Vibration when the quantum equals the thermal energy
  1. Set x=1x = 1, which means ℏω=kBT\hbar\omega = k_B T.
  2. Partition function: Z=e−0.5/(1−e−1)=0.60653/0.63212≈0.95952Z = e^{-0.5} / (1 - e^{-1}) = 0.60653 / 0.63212 \approx 0.95952.
  3. Cross-check: the same value is 1/(2sinh⁡0.5)=1/1.04219≈0.959521 / (2 \sinh 0.5) = 1 / 1.04219 \approx 0.95952.
  4. Ground-state probability: P0=e−0.5/Z=0.63212P_0 = e^{-0.5} / Z = 0.63212, which equals 1−e−11 - e^{-1} exactly.
  5. Average energy from the shortcut: ⟨E⟩=ℏω(12+1ex−1)=ℏω(0.5+0.58198)=1.08198 ℏω\langle E \rangle = \hbar\omega\left(\tfrac12 + \dfrac{1}{e^{x} - 1}\right) = \hbar\omega(0.5 + 0.58198) = 1.08198\,\hbar\omega.
  6. Check against the sum: the probabilities of levels n=0n = 0 to 55 are 0.63210.6321, 0.23250.2325, 0.08550.0855, 0.03150.0315, 0.01160.0116 and 0.00430.0043. Weighting their energies and adding the small tail gives about 1.08, in agreement with step 5.

Interpretation: at this temperature the molecule is in its ground level 63 percent of the time, and the average energy sits just above the zero-point energy 12ℏω\tfrac12\hbar\omega. Now take a carbon monoxide bond, whose ℏω\hbar\omega corresponds to about 3100 kelvin. At room temperature x≈10x \approx 10, so ZZ is close to e−5e^{-5} and almost every molecule sits in the ground level. The partition function tells you that the vibration is frozen out and does not contribute to the heat capacity.

Tradeoffs and failure modes

The partition function ZZ at fixed temperature, volume and particle number is the right object for a system in contact with a heat bath. It stops being the right object when the setup changes.

SituationProblemBetter choice
The system is isolated, so its total energy is fixedTemperature is not fixed, so the canonical ZZ does not applyThe microcanonical ensemble, which counts states with energy EE
Particles can exchange with a reservoirThe number of particles changes, so ZZ at fixed NN is incompleteThe grand partition function, which uses a Chemical Potential
Particles are identicalCounting each arrangement as distinct overcounts, which gives wrong entropy for gasesA 1/N!1/N! correction for classical gases, or Fermi-Dirac Statistics and Bose statistics for quantum particles (see Indistinguishable Particles)
The state space is huge, for example many interacting spinsZZ is a sum of exponentially many terms and cannot be enumeratedSampling with the Metropolis Algorithm or Monte Carlo Method, which estimate averages without computing ZZ
Interactions are strong and near a critical pointZZ has no simple closed form, and approximations break downCoarse-graining methods such as the Renormalization Group

Two more failure modes come up often in practice. First, the zero of energy is arbitrary. Shifting all energies changes ZZ by a constant factor and changes FF by the same shift, but leaves probabilities alone, so an answer for absolute free energy is only meaningful relative to a reference. Second, the equilibrium ZZ describes a system at rest. A system pushed far out of equilibrium does not have its populations given by the Boltzmann formula, although certain exact identities, such as the Jarzynski equality, still relate work done on it to equilibrium free-energy differences.

History

The idea grew out of Ludwig Boltzmann's work in the 1870s and 1880s on the statistical meaning of entropy. Boltzmann wrote the sum of weights over states as a single quantity, which in German is called the Zustandssumme, or state sum. It is the older name for what is now called the partition function. Exact dates for the early papers vary between sources, so treat the decade as approximate.

J. Willard Gibbs gave the systematic framework in his 1902 book on statistical mechanics, developing the ensembles and free-energy relations that are used today. The English name "partition function" came into use later. This framework made the sum over states the central tool of statistical mechanics.

The idea caught on because it turned thermodynamics into a calculation. Given the energy levels of a molecule, a crystal or a magnet, one function predicts its heat capacity, its entropy and its response to pressure or field. The same logic underlies modern simulation, where averages are estimated by sampling rather than by summing over all states.

Check yourself

QuestionRecall: what does dividing each Boltzmann factor by ZZ accomplish?Show answer

Each factor e−Ei/kBTe^{-E_i / k_B T} is a weight, not a probability, because the weights do not add up to 1. Dividing each one by ZZ, which is the sum of all the weights, turns them into probabilities that sum to 1. The division does not change the ratio between any two states.

QuestionComputation: a two-level system has a ground state at energy 0 and an excited state at energy kBTk_B T. What is ZZ, and what fraction of the system is in the excited state?Show answer

Z=1+e−1=1+0.36788=1.36788Z = 1 + e^{-1} = 1 + 0.36788 = 1.36788. The excited-state probability is e−1/Z=0.36788/1.36788≈0.269e^{-1} / Z = 0.36788 / 1.36788 \approx 0.269, so about 27 percent of the system is in the excited state.

QuestionWhy: the average energy is written as −∂ln⁡Z/∂β-\partial \ln Z / \partial \beta rather than as a sum of PiEiP_i E_i. What does the logarithm buy you?Show answer

Both give the same answer, but the derivative form needs only ZZ as a function of β\beta. Once ZZ is known in closed form, one differentiation gives the average energy, with no need to list every state and its probability. It also extends to the entropy and free energy, which all come from the same function.

QuestionApplied: a simulation needs the free-energy difference between two conditions of a molecule, but computing either ZZ directly is infeasible. Why is estimating the ratio ZB/ZAZ_B / Z_A enough?Show answer

The free-energy difference is FB−FA=−kBTln⁡(ZB/ZA)F_B - F_A = -k_B T \ln(Z_B / Z_A), so the ratio is all that is needed. Common factors such as the zero-point energy and any constant prefactor cancel between the two conditions. Simulation methods can estimate such ratios by sampling transitions between the conditions, which avoids computing either partition function on its own.

Sources