---
title: The Partition Function and the Helmholtz Free Energy
module: The Canonical Ensemble
moduleNumber: 4
lessonNumber: 2
order: 402
summary: >
  The normalizing sum of the Boltzmann distribution, the partition function
  $Z=\sum_i e^{-\beta E_i}$, is a generating function for the thermodynamics.
  The mean energy is $-\partial\ln Z/\partial\beta$, and the Gibbs entropy of the
  canonical distribution collapses to the bridge relation $F=-k_BT\ln Z$. From
  $F$ every thermodynamic quantity follows by differentiation, and $Z$ factorizes
  over independent degrees of freedom.
topics: [The Canonical Ensemble]
sources:
  - book: Schroeder
    ref: "Ch. 6 — Boltzmann Statistics; §6.2 Average Values, §6.5–6.6 Free Energy and the Partition Function"
  - book: Reif
    ref: "Ch. 6 — Basic Methods and Results of Statistical Mechanics; §6.5–6.9"
  - book: Kardar (Statistical Physics of Particles)
    ref: "Ch. 4 — Classical Statistical Mechanics; §4.6 The Canonical Ensemble"
  - book: Pathria & Beale
    ref: "Ch. 3 — The Canonical Ensemble; §3.3–3.6"
draft: false
---

The Boltzmann distribution $p_i = e^{-\beta E_i}/Z$ requires a normalizing sum,
$Z = \sum_i e^{-\beta E_i}$, introduced in the previous lesson as a bookkeeping
constant. That sum carries far more than a normalization. Every thermodynamic
quantity of the system — its mean energy, entropy, pressure, and free energy — is
a derivative of $\ln Z$. The partition function is the generating function of the
canonical ensemble, and the single relation $F = -k_B T\ln Z$ ties it to the
Helmholtz free energy, from which classical thermodynamics is recovered by
differentiation.

## The partition function as a sum over states

> **Definition (Partition function).** For a system in equilibrium with a
> reservoir at temperature $T$, the **canonical partition function** is the sum
> of Boltzmann factors over all microstates,
> $$Z(T,V,N) = \sum_i e^{-\beta E_i}, \qquad \beta = \frac{1}{k_B T},$$
> with the microstate energies $E_i = E_i(V,N)$ depending on the volume and
> particle number. When several microstates share an energy $E$ with degeneracy
> $g(E)$, the sum may be written over energy levels, $Z = \sum_E g(E)e^{-\beta E}$.

The name records what $Z$ does: it partitions unit probability among the
microstates in the ratios of their Boltzmann factors.[^schroeder-Z] At low
temperature ($\beta\to\infty$) only the ground state contributes and $Z\to g_0$,
the ground-state degeneracy. At high temperature ($\beta\to 0$) every factor
approaches unity and $Z$ counts the accessible microstates. Between these limits
$Z$ is a smooth, monotonically increasing function of $T$ that measures the
effective number of thermally accessible states.

$$
% caption: The partition function sums the Boltzmann weights over the energy ladder; each level of energy $E_n$ and degeneracy $g_n$ contributes $g_n e^{-\beta E_n}$, the bar lengths, and lower levels dominate.
\begin{tikzpicture}[>=Latex,font=\footnotesize,scale=1.0]
\definecolor{acc}{HTML}{4A6FA5}
\draw[->,black] (0,-0.2)--(0,4.6) node[above,black]{$E$};
\foreach \y/\w/\lab in {0.4/3.6/{E_0}, 1.3/2.1/{E_1}, 2.2/1.1/{E_2}, 3.1/0.5/{E_3}, 3.9/0.22/{E_4}}{
  \draw[black,very thick] (-0.15,\y)--(0.15,\y);
  \node[black!70,left,font=\scriptsize] at (-0.2,\y) {$\lab$};
  \draw[acc,very thick,fill=acc!14] (0.5,\y-0.12) rectangle (0.5+\w,\y+0.12);
}
\node[acc,font=\scriptsize] at (4.4,0.4) {ground level dominates};
\node[black!70,font=\scriptsize] at (3.9,3.3) {small weight high up};
\end{tikzpicture}
$$

## Mean energy from the partition function

The mean energy is the Boltzmann-weighted average
$\langle E\rangle = \sum_i p_i E_i = Z^{-1}\sum_i E_i e^{-\beta E_i}$. The sum in
the numerator is a derivative of $Z$: since $\partial e^{-\beta E_i}/\partial\beta
= -E_i e^{-\beta E_i}$,

$$
\sum_i E_i e^{-\beta E_i} = -\frac{\partial Z}{\partial\beta},
\qquad\text{so}\qquad
\langle E\rangle = -\frac{1}{Z}\frac{\partial Z}{\partial\beta}
= -\frac{\partial\ln Z}{\partial\beta}.
$$

The internal energy $U = \langle E\rangle$ is the logarithmic derivative of $Z$
with respect to $\beta$. In terms of temperature, using
$\partial/\partial\beta = -k_B T^2\,\partial/\partial T$,

$$
U = k_B T^2\left(\frac{\partial\ln Z}{\partial T}\right)_{V,N}.
$$

A single differentiation of $\ln Z$ has produced a full thermodynamic function
without any counting of microstates beyond forming $Z$ itself.

## The Helmholtz free energy

The link between $Z$ and thermodynamics is fixed by evaluating the Gibbs entropy
on the canonical distribution. From $\ln p_i = -\beta E_i - \ln Z$,

$$
S = -k_B\sum_i p_i\ln p_i
= -k_B\sum_i p_i(-\beta E_i - \ln Z)
= k_B\beta\langle E\rangle + k_B\ln Z.
$$

Multiply through by $T$ and use $k_B\beta T = 1$:

$$
TS = \langle E\rangle + k_B T\ln Z
\;\Longrightarrow\;
\langle E\rangle - TS = -k_B T\ln Z.
$$

The left side is the definition of the Helmholtz free energy, $F = U - TS$.
Hence the **bridge equation** of the canonical ensemble.[^reif-bridge]

> **Theorem (Free energy from the partition function).** The Helmholtz free
> energy of a system in equilibrium with a reservoir at temperature $T$ is
> $$F(T,V,N) = -k_B T\ln Z(T,V,N).$$
> All equilibrium thermodynamics of the system follows from $F$ by
> differentiation with respect to its natural variables $T$, $V$, and $N$.

This relation carries the canonical ensemble the way $S = k_B\ln\Omega$ carries
the microcanonical one. There, entropy is the logarithm of a count at fixed
energy; here, free energy is the logarithm of a weighted sum at fixed
temperature. The two are Legendre transforms of one another: fixing $E$ versus
fixing its conjugate $\beta$.

## Thermodynamics by differentiation

The differential of the Helmholtz free energy is $\d F = -S\,\d T - P\,\d V +
\mu\,\d N$, so its first partials return the entropy, pressure, and chemical
potential directly.[^schroeder-derivs] With $F = -k_B T\ln Z$,

$$
S = -\left(\frac{\partial F}{\partial T}\right)_{V,N}
= k_B\ln Z + k_B T\left(\frac{\partial\ln Z}{\partial T}\right)_{V,N},
$$

$$
P = -\left(\frac{\partial F}{\partial V}\right)_{T,N}
= k_B T\left(\frac{\partial\ln Z}{\partial V}\right)_{T,N},
\qquad
\mu = \left(\frac{\partial F}{\partial N}\right)_{T,V}
= -k_B T\left(\frac{\partial\ln Z}{\partial N}\right)_{T,V}.
$$

The entropy expression reproduces $S = (U-F)/T$ obtained above, a check that the
differentiation is consistent. The pressure formula has a direct microscopic
reading: the energies $E_i(V)$ shift as the volume changes, and
$P = -\langle\partial E_i/\partial V\rangle$ is the ensemble-averaged force per
unit area on the walls, which equals $k_B T\,\partial\ln Z/\partial V$. The
internal energy re-emerges as $U = F + TS$, closing the set.

$$
% caption: Every canonical thermodynamic quantity is a derivative of the partition function; the free energy $F$ from the logarithm, then the entropy from its temperature slope, the pressure from its volume slope, and the internal energy from the beta slope.
\begin{tikzpicture}[>=Latex,font=\footnotesize,scale=1.0]
\definecolor{acc}{HTML}{4A6FA5}
\node[draw=acc,very thick,fill=acc!12,minimum width=2.6cm,minimum height=0.9cm] (Z) at (4,3.4) {partition function $Z$};
\node[draw=black,very thick,fill=black!5,minimum width=2.6cm,minimum height=0.9cm] (F) at (4,1.4) {free energy $F$};
\node[draw=black,very thick,fill=black!5,minimum width=2.2cm,minimum height=0.8cm] (U) at (0.4,3.4) {energy $U$};
\node[draw=black,very thick,fill=black!5,minimum width=2.2cm,minimum height=0.8cm] (S) at (0.4,1.0) {entropy $S$};
\node[draw=black,very thick,fill=black!5,minimum width=2.2cm,minimum height=0.8cm] (P) at (7.6,1.0) {pressure $P$};
\draw[->,black,very thick] (Z)--(F) node[midway,right]{logarithm};
\draw[->,black,very thick] (Z)--(U) node[midway,above]{beta slope};
\draw[->,black,very thick] (F)--(S) node[midway,above left]{$T$ slope};
\draw[->,black,very thick] (F)--(P) node[midway,above right]{$V$ slope};
\end{tikzpicture}
$$

## Factorization over independent degrees of freedom

When the energy splits into independent additive pieces, the partition function
factorizes. Suppose the microstate is specified by two independent labels $a$ and
$b$ with energy $E_{ab} = \varepsilon^{(a)}_a + \varepsilon^{(b)}_b$. The double
sum separates,

$$
Z = \sum_{a,b} e^{-\beta(\varepsilon^{(a)}_a + \varepsilon^{(b)}_b)}
= \Big(\sum_a e^{-\beta\varepsilon^{(a)}_a}\Big)
\Big(\sum_b e^{-\beta\varepsilon^{(b)}_b}\Big)
= Z_a\,Z_b.
$$

For $N$ identical independent subsystems whose states do not need to be
distinguished from one another only by relabeling — for instance $N$ localized
oscillators fixed to lattice sites, which are distinguishable by position — the
partition function is the $N$-th power of the single-subsystem partition function,

$$
Z = z_1^{\,N},
\qquad
F = -k_B T\ln Z = -N k_B T\ln z_1.
$$

The free energy is then extensive, proportional to $N$, as a thermodynamic
potential must be. For $N$ identical particles free to occupy the same states —
an ideal gas, where a permutation of labels is not a new microstate — the naive
$z_1^N$ overcounts by the $N!$ permutations, and the correct counting inserts a
factor $1/N!$; that correction and the extensivity it restores are the subject of
the classical-gas module.[^kardar-factor] Factorization reduces the many-body
problem to a single-subsystem sum whenever the parts are independent, and it is
the reason the oscillator and two-level results of the following lessons extend
immediately to macroscopic solids and paramagnets.

$$
% caption: For $N$ independent, distinguishable subsystems the partition function is the product of single-subsystem sums, $Z=z_1^N$, so the free energy $F=-Nk_BT\ln z_1$ is extensive.
\begin{tikzpicture}[>=Latex,font=\footnotesize,scale=1.0]
\definecolor{acc}{HTML}{4A6FA5}
\foreach \x/\lab in {0/1, 1.6/2, 3.2/3, 6.4/N}{
  \draw[acc,very thick,fill=acc!10] (\x,0) rectangle (\x+1.1,1.4);
  \node[acc] at (\x+0.55,0.7) {$z_1$};
  \node[black!70,font=\scriptsize,below] at (\x+0.55,0) {site $\lab$};
}
\node[black] at (5.0,0.7) {$\cdots$};
\node[black] at (8.7,0.7) {$Z=z_1^{\,N}$};
\end{tikzpicture}
$$

## Free energy as the minimized potential

At fixed temperature and volume the equilibrium of a system is the state that
minimizes the Helmholtz free energy, and the canonical distribution realizes that
minimum. Define the free-energy functional of an arbitrary distribution
$\{p_i\}$,

$$
F[\{p_i\}] = \langle E\rangle - TS = \sum_i p_i E_i + k_B T\sum_i p_i\ln p_i.
$$

Minimizing $F[\{p_i\}]$ over normalized distributions reproduces the Boltzmann
weights $p_i = e^{-\beta E_i}/Z$, and the minimum value is $F = -k_B T\ln Z$. The
functional expresses a competition: the energy term $\langle E\rangle$ is lowered
by concentrating probability in the lowest states, while the entropy term $-TS$
is lowered by spreading probability across many states. The balance point is
temperature-dependent.[^schroeder-free]

- **Low temperature.** The factor $T$ multiplying $S$ is small, so $F\approx U$;
  minimizing $F$ minimizes the energy, and the system settles into its
  lowest-energy states. Order wins.
- **High temperature.** The entropy term dominates, so minimizing $F$ maximizes
  $S$; the system spreads over as many microstates as its energy permits.
  Disorder wins.

$$
% caption: The free energy $F=U-TS$ against temperature: the energy $U$ changes slowly while $TS$ grows, so $F$ falls and passes below zero; at low $T$ the energy term controls $F$, at high $T$ the entropy term does.
\begin{tikzpicture}[>=Latex,font=\footnotesize,scale=1.0]
\definecolor{acc}{HTML}{4A6FA5}
\draw[->,black] (0,-1.6)--(0,3.4) node[above,black]{energy};
\draw[->,black] (0,0)--(7.0,0) node[right,black]{$T$};
\draw[black,very thick] plot[domain=0:6.4,samples=40] (\x,{1.4+0.16*\x});
\node[black] at (5.4,2.55) {$U$};
\draw[black,very thick,dashed] plot[domain=0:6.4,samples=40] (\x,{0.09*\x*\x});
\node[black] at (6.1,3.05) {$TS$};
\draw[acc,very thick] plot[domain=0:6.4,samples=40] (\x,{1.4+0.16*\x-0.09*\x*\x});
\node[acc] at (6.2,-1.25) {$F$};
\end{tikzpicture}
$$

The next lesson returns to the fluctuations of the energy about $U$, which a
second derivative of $\ln Z$ measures and which link the canonical ensemble back
to the microcanonical one.

## Summary

- The **partition function** $Z = \sum_i e^{-\beta E_i}$ normalizes the Boltzmann
  distribution and generates the thermodynamics; it counts the ground-state
  degeneracy at low $T$ and the accessible microstates at high $T$.
- The mean energy is the first logarithmic derivative,
  $U = -\partial\ln Z/\partial\beta = k_B T^2(\partial\ln Z/\partial T)_V$.
- Evaluating the Gibbs entropy on the canonical distribution gives the **bridge
  equation** $F = -k_B T\ln Z$; then $S = -(\partial F/\partial T)_V$,
  $P = -(\partial F/\partial V)_T$, and $\mu = (\partial F/\partial N)_{T,V}$
  recover all thermodynamics by differentiation.
- $Z$ **factorizes** over independent degrees of freedom: $Z = Z_a Z_b$ for
  independent parts and $Z = z_1^N$ for $N$ distinguishable identical subsystems,
  making $F$ extensive.
- At fixed $T$ and $V$ the equilibrium distribution **minimizes** the free-energy
  functional $\langle E\rangle - TS$; the energy term controls it at low $T$, the
  entropy term at high $T$.

[^schroeder-Z]: **Schroeder**, _An Introduction to Thermal Physics_, §6.2 — the partition function as the sum of Boltzmann factors and its interpretation as the effective number of accessible states. Companion material at <https://physics.weber.edu/schroeder/thermal/>.
[^reif-bridge]: **Reif**, _Fundamentals of Statistical and Thermal Physics_, §6.5–6.6 — the connection between the partition function and the Helmholtz free energy, $F = -k_B T\ln Z$, and the recovery of thermodynamic quantities as derivatives.
[^schroeder-derivs]: **Schroeder**, _An Introduction to Thermal Physics_, §6.5–6.6, and **Pathria & Beale**, _Statistical Mechanics_ (4th ed.), §3.3–3.4 — the extraction of entropy, pressure, and chemical potential from $F(T,V,N)$ by differentiation with respect to its natural variables.
[^kardar-factor]: **Kardar**, _Statistical Physics of Particles_, §4.6 — factorization of the partition function over independent degrees of freedom, and the distinction between distinguishable subsystems ($Z=z_1^N$) and indistinguishable particles (the $1/N!$ correction). MIT OCW 8.333, <https://ocw.mit.edu/courses/8-333-statistical-mechanics-i-statistical-mechanics-of-particles-fall-2013/>.
[^schroeder-free]: **Schroeder**, _An Introduction to Thermal Physics_, §6.6, and **Reif**, _Fundamentals of Statistical and Thermal Physics_, §6.7 — the free energy as the potential minimized at fixed temperature and volume, and the energy–entropy competition in $F = U - TS$.
