physics2u
Tier
⌕ Search ⌘K
physics2u.com/vault/canonical-partition-function-and-free-energy.html
Derivation

The Partition Function and F = -kT ln Z

Statement

For a system in thermal contact with a reservoir at temperature T, normalizing the Boltzmann distribution pi ∝ e−βEi over microstates i forces the introduction of the canonical partition function Z = ∑i e−βEi (with β = 1/kT). The Helmholtz free energy is then F = −kT ln Z, and the internal energy, entropy, and every thermodynamic quantity follow as derivatives of ln Z.

Why it matters

The partition function is the single bridge between microscopic mechanics and macroscopic thermodynamics. Once you can write down the energy spectrum {Ei} of a system and sum e−βEi, every equilibrium thermodynamic property is obtained by differentiation — no further physical input is required. This is why Z is often called the generating function of statistical mechanics.

The relation F = −kT ln Z is the exact point where the two halves of the subject meet: the left side is a thermodynamic potential defined by a Legendre transform of the energy; the right side is a sum over quantum states. Identifying them turns thermodynamics into arithmetic on spectra.

Assumptions
Canonical ensemble (fixed T, N, V).If the system exchanged particles with the reservoir we would need the grand canonical ensemble and a chemical-potential term −μN in the exponent, giving the grand partition function Ξ instead of Z. Weak system–reservoir coupling.If the interaction energy at the boundary were comparable to the system's own energy, the total energy would not split as Esys + Eres and the Boltzmann factor could not be derived by expanding the reservoir entropy. Reservoir much larger than the system, with a smooth density of states.If dropped, the first-order Taylor expansion of lnΩres(E−Ei) in Ei that produces a single, energy-independent β is not valid, and no unique temperature can be assigned. Discrete, countable spectrum (or a convergent phase-space integral).If the sum ∑ie−βEi diverges — e.g. a spectrum unbounded below, or a free particle in infinite volume without the correct phase-space measure — Z does not exist and F is undefined.
Derivation
1
pi = C e−βEi
Prior result (boltzmann-distribution): the probability of a system microstate of energy Ei in contact with a reservoir at inverse temperature β=1/kT is proportional to the Boltzmann factor. C is an as-yet-undetermined normalization constant. A
2
i pi = 1  ⇒  C ∑i e−βEi = 1
Probabilities over a complete set of mutually exclusive microstates must sum to one. This is the only extra condition needed to fix C. A
3
Z(β,V,N) ≡ ∑i e−βEi  ⇒  C = 1/Z
Define the partition function as the normalizing sum; C = 1/Z is forced. The sum runs over microstates, not energy levels, so a level of degeneracy g contributes g e−βE. A
4
pi = e−βEi / Z
Substitute C=1/Z back. The distribution is now fully specified by the spectrum {Ei} and β. A
5
⟨E⟩ = ∑i pi Ei = (1/Z) ∑i Ei e−βEi
Definition of the ensemble-average energy, which we identify with the thermodynamic internal energy U. A
6
∂Z/∂β = −∑i Ei e−βEi
Differentiate the definition of Z term by term with respect to β at fixed V,N (so the Ei are held fixed). Legal because the sum converges uniformly on a neighbourhood of any β>0. B
7
U = ⟨E⟩ = −(1/Z)(∂Z/∂β) = −∂(ln Z)/∂β
Compare steps 5 and 6, then use (1/Z)∂Z/∂β = ∂(ln Z)/∂β (chain rule). Internal energy is the first log-derivative of Z. A
8
S = −k ∑i pi ln pi
Gibbs entropy of the canonical distribution — the unique measure consistent with thermodynamic entropy for this ensemble. C
9
ln pi = −βEi − ln Z
Take the logarithm of pi=e−βEi/Z from step 4. Pure algebra. A
10
S = −k ∑i pi(−βEi − ln Z) = kβ⟨E⟩ + k ln Z
Insert step 9 into step 8 and split the sum, using ipiEi=⟨E⟩ and ipi=1. The ln Z term factors out because it is a constant. B
11
S = U/T + k ln Z  ⇒  U − TS = −kT ln Z
Use β=1/kT so kβ⟨E⟩=U/T, then multiply by T and rearrange. The left side is exactly the Legendre transform defining the Helmholtz free energy. B
12
F ≡ U − TS = −kT ln Z
Prior result (thermodynamic-potentials-legendre-transforms): F=U−TS is the natural potential of the variables (T,V,N) — the same variables that label the canonical ensemble. Identifying the two expressions is the master relation. A
Result
Z = ∑i e−βEi    F = −kT ln Z    U = −∂(ln Z)/∂β    S = −(∂F/∂T)V,N

Reading. Everything thermodynamic is a derivative of ln Z. Compute the single scalar Z from the spectrum; its logarithm is (up to −kT) the free energy. From F(T,V,N) the standard thermodynamic derivatives deliver the rest: S=−(∂F/∂T)V,N, pressure P=−(∂F/∂V)T,N, chemical potential μ=(∂F/∂N)T,V, and U=F+TS. The differentiation with respect to β pulls down factors of Ei, which is why log-derivatives of Z generate energy moments (mean, variance, …).

Units check. βEi is dimensionless (β in J−1, Ei in J), so every Boltzmann factor and Z itself are dimensionless — ln Z is therefore well-defined. Then kT ln Z carries the units of kT: (J K−1)(K) = J, matching F. U=−∂ln Z/∂β has units J⋅(J−1)−1=J. S=U/T+k ln Z is J K−1. All consistent.

Limiting cases
  • High temperature (β→0): every Boltzmann factor →1, so Z→ the number of accessible microstates g. Then F→−kT ln g and S→k ln g — the microcanonical, equal-probability limit.
  • Low temperature (β→∞): Z→g0e−βE0, dominated by the ground level. Then F→E0−kT ln g0, U→E0, S→k ln g0 (the third law, with residual entropy if g0>1).
  • Two-level system: Z=1+e−βε gives U=ε/(eβε+1) and the Schottky heat-capacity peak — a full solvable check.
  • Factorizable systems: for independent subsystems E=∑aE(a), so Z=∏aZ(a) and ln Z (hence F, U, S) is additive — extensivity emerges automatically.
Breaks when
  • The sum diverges. A spectrum unbounded below, or an attractive potential with no ground state (e.g. point charges collapsing, or a classical hydrogen atom summed over all bound and arbitrarily deep states without cutoff), makes Z=∞. No F exists; the canonical formalism simply does not apply.
  • Long-range interactions / non-additive energy. Gravitating systems and unscreened Coulomb systems violate Esys+Eres additivity, so Z is non-extensive, ln Z is not proportional to N, and ensembles become inequivalent (negative heat capacities appear).
  • Small systems / strong coupling. When the system–bath boundary energy is not negligible, the derived Boltzmann factor is only approximate and F=−kT ln Z acquires coupling-dependent corrections; the very definition of the system's temperature blurs.
  • Broken ergodicity / non-equilibrium. In a glass or a system trapped in a metastable basin below its transition, the accessible states are not the full spectrum; the equilibrium Z overcounts and the measured F is basin-restricted, not the global minimum.
Failure modes
  • Summing over energy levels instead of microstates. Forgetting degeneracy: a level of energy E and degeneracy g contributes g e−βE, not e−βE. This silently corrupts S.
  • Sign errors in F=−kT ln Z. Because Z>1 usually, ln Z>0 and F<0 for the excitation part; dropping the minus sign flips the free energy and reverses which state is favoured.
  • Differentiating Z at fixed β while letting Ei vary. The relation U=−∂ln Z/∂β requires the spectrum to be held fixed; if V is allowed to change you are computing something else (and picking up the pressure term).
  • Confusing ⟨E⟩ with the most probable energy. The distribution is sharply peaked for large N, but U=⟨E⟩ is the mean; only in the thermodynamic limit do mean, mode, and microcanonical energy coincide.
  • Adding an extensive constant to the entropy by hand. For indistinguishable particles the correct single-particle result needs the 1/N! (Gibbs) factor in Z; omitting it produces the Gibbs paradox — a non-extensive S.
Discussion

The deep content of F=−kT ln Z is that a sum over states becomes a minimization of a potential. Thermodynamics says the equilibrium state at fixed T,V,N minimizes F=U−TS — a competition between lowering energy and raising entropy. Statistical mechanics shows this same F is −kT ln Z, where Z automatically weighs each state by e−βEi. The Boltzmann weight is the energy–entropy trade-off resolved microstate by microstate; summing them and taking the log performs the minimization for you.

The two threads of this unit meet here. The chance thread supplies the normalized probability pi=e−βEi/Z and the Gibbs entropy; the energy thread supplies the Legendre structure F=U−TS whose natural variables (T,V,N) are exactly the canonical control variables. That the same four symbols U,T,S,F appear on both sides is not a coincidence but the statement that the canonical ensemble is the microscopic realization of Helmholtz thermodynamics.

Log-derivatives of Z form a generating hierarchy. The first β-derivative gives −U; the second gives the energy variance, 2ln Z/∂β2=⟨E2⟩−⟨E⟩2=k T2CV. This is a fluctuation–dissipation relation: the size of spontaneous energy fluctuations is fixed by the heat capacity, a linear response. Because the variance scales as N while ⟨E⟩ scales as N, the relative fluctuation falls as N−1/2 — which is precisely why the canonical and microcanonical descriptions agree in the thermodynamic limit.

At the rigorous level, F=−kT ln Z is a Legendre transform in disguise on both sides. Thermodynamically, F(T) is the Legendre transform of U(S) swapping S↔T. Statistically, the Laplace transform relating the microcanonical Ω(E) to Z(β)=∫Ω(E)e−βEdE becomes, by the saddle-point/large-deviation evaluation for large N, exactly a Legendre transform between lnΩ(E)=S/k and ln Z(β)=−βF. Convexity of S(E) is what guarantees this transform is single-valued; where S(E) has a concave region (a van der Waals loop, a first-order transition) the ensembles are inequivalent and the naive F=−kT ln Z gives the Maxwell-constructed (convex-hull) free energy, not the metastable branch.

Common misconceptions. Z is not itself a probability and is not dimensionless "because it must be" — it is dimensionless only because each βEi is. It is not the number of states (that is only its T→∞ limit); it is a thermally weighted count, sometimes called the effective number of accessible states. And F=−kT ln Z is exact, not an approximation — the approximations enter only in evaluating Z.

Worked examples
1
Single two-level system (spin in a field): levels 0 and ε
Set up the spectrum. States: ground E=0, excited E=ε, both non-degenerate. A
2
Z = e0 + e−βε = 1 + e−βε
Direct sum of Boltzmann factors over the two microstates. A
3
F = −kT ln(1 + e−ε/kT)
Apply the master relation with β=1/kT. A
4
Numbers: ε = 1.00×10−21 J, T = 300 K, k = 1.381×10−23 J K−1
Compute βε = ε/kT = (1.00×10−21)/((1.381×10−23)(300)) = 0.2414. Then e−0.2414=0.7856, so Z=1.7856. B
5
U = ε e−βε/Z = ε/(eβε+1)
U = (1.00×10−21)(0.7856)/1.7856 = 4.40×10−22 J. Equivalently ε/(e0.2414+1)=ε/2.273. B
Z = 1.786   F = −kT ln Z = −2.40×10−21 J   U = 4.40×10−22 J

Reading. At 300 K the excited state is populated with probability e−βε/Z=0.440 — the level gap is only about a quarter of kT, so the two states are nearly equally occupied and U is close to ε/2. Check: F=−(1.381×10−23)(300)ln(1.786)=−(4.143×10−21)(0.5799)=−2.40×10−21 J.

1
One-dimensional quantum harmonic oscillator: En = ℏω(n + ½), n = 0,1,2,…
Set up the (infinite, non-degenerate) spectrum for a single vibrational mode. A
2
Z = ∑n=0 e−βℏω(n+½) = e−βℏω/2n=0 (e−βℏω)n
Factor out the zero-point term; the remainder is a geometric series with ratio x=e−βℏω<1. B
3
Z = e−βℏω/2 / (1 − e−βℏω) = 1 / [2 sinh(βℏω/2)]
Sum the geometric series ∑xn=1/(1−x), then use e−u/2/(1−e−u)=1/(eu/2−e−u/2)=1/(2 sinh(u/2)). B
4
F = −kT ln Z = kT ln[2 sinh(βℏω/2)]    U = −∂ln Z/∂β = (ℏω/2) coth(βℏω/2)
Apply the master relation; differentiate ln Z=−ln[2 sinh(βℏω/2)] using d/du ln sinh u = coth u. Equivalently U=ℏω(½+1/(eβℏω−1)) — zero-point plus Planck occupation. B
5
Numbers: ℏω = 4.00×10−21 J, T = 300 K ⇒ βℏω = 0.9656
βℏω=(4.00×10−21)/((1.381×10−23)(300))=0.9656. Then sinh(0.4828)=0.5017, coth(0.4828)=1/tanh(0.4828)=1/0.4482=2.231. C
Z = 1/(2⋅0.5017) = 0.997   F = kT ln(1.003) = 1.4×10−23 J   U = (2.00×10−21)(2.231) = 4.46×10−21 J

Reading. Here ℏω≈kT, so the oscillator sits between its quantum and classical regimes. The internal energy U=4.46×10−21 J exceeds the zero-point value ℏω/2=2.00×10−21 J because thermal excitation adds ℏω/(eβℏω−1)=2.46×10−21 J. In the classical limit βℏω→0 this would tend to U→kT=4.14×10−21 J (equipartition), which the exact result approaches from above.

Problems
  1. A three-level system has non-degenerate energies 0, ε, . Write Z and find the probability of the top level at kT=ε.
    SolutionWith x=e−βε, Z=1+x+x2. At kT=ε, βε=1, x=e−1=0.3679, x2=0.1353. So Z=1.5032 and p=x2/Z=0.1353/1.5032=0.0900. The top level holds about 9%.
  2. For the two-level system (Z=1+e−βε) derive the heat capacity CV=dU/dT and locate its qualitative maximum (the Schottky anomaly).
    SolutionU=ε/(eβε+1). Differentiate: CV=dU/dT=k(βε)2 eβε/(eβε+1)2. Writing u=βε=ε/kT, CV=k u2eu/(eu+1)2. This vanishes as T→0 (u→∞, exponential kill) and as T→∞ (u→0, u2 kill), so it peaks at intermediate T. Setting dCV/du=0 gives the transcendental u tanh(u/2)=2, solved by u≈2.40, i.e. kT≈0.417ε — the Schottky peak sits below the level gap.
  3. N distinguishable, independent two-level systems each with gap ε. Write the total ZN and total F, and confirm extensivity.
    SolutionIndependence and additive energy give ZN=(Z1)N=(1+e−βε)N. Then F=−kT ln ZN=−NkT ln(1+e−βε). Since F∝N (and U,S likewise), the free energy is extensive. Note: distinguishable, so no 1/N! is needed — these are localized sites, e.g. paramagnetic ions on a lattice.
  4. Show explicitly that S=−(∂F/∂T)V,N reproduces S=U/T+k ln Z, given F=−kT ln Z and Z=Z(β,V).
    SolutionF=−kT ln Z. Differentiate at fixed V,N: ∂F/∂T=−k ln Z−kT(∂ln Z/∂T). Now ∂ln Z/∂T=(∂ln Z/∂β)(dβ/dT)=(−U)(−1/kT2)=U/kT2, using U=−∂ln Z/∂β and β=1/kT. Hence ∂F/∂T=−k ln Z−kT⋅U/kT2=−k ln Z−U/T. Therefore S=−∂F/∂T=k ln Z+U/T. QED.
  5. A classical particle of mass m in a 1D box of length L has Z1=L/Λ with thermal wavelength Λ=h/√(2πmkT). Compute U and CV and comment on equipartition.
    SolutionZ1=L(2πmkT)1/2/h=L(2πm/h2)1/2β−1/2, so ln Z1=−½lnβ+(const). Then U=−∂ln Z1/∂β=½/β=½kT, and CV=dU/dT=½k. This is exactly the equipartition result: ½kT per translational (quadratic) degree of freedom. The β−1/2 scaling of Z is what encodes the single quadratic degree of freedom — each such power of β−1/2 contributes ½kT to U.