A physics perspective on entropy

Count the ways particles can fill a set of jars to connect Boltzmann entropy with Shannon entropy, then use a Lagrange multiplier to find the distribution that maximizes entropy.

In information theory, entropy measures how much information it takes, on average, to specify a random outcome. The idea comes from thermodynamics, where entropy is often described as a measure of disorder in a system.

Place $N$ identical particles into $M$ jars, one particle at a time, and write down the jar number after each placement. If jar $i$ ends up with $n_i$ particles, then $i$ appears $n_i$ times in the sequence. How many sequences give those final counts?

\[W = \frac{N!}{\prod_{i=1}^{M} n_i!}\]

Imagine writing the jar numbers on $N$ slips of paper and laying the slips in a row. There are $N!$ ways to arrange the slips. Swapping any of the $n_i$ slips marked $i$ leaves the sequence of numbers unchanged. That is why we divide by $n_i!$ for each jar.

In this model, each sequence specifies one microstate. The number $W$ of sequences that give the same counts $(n_1,\ldots,n_M)$ is called the multiplicity. The Boltzmann entropy is $S=k_B\ln W$, where $k_B$ is the Boltzmann constant. The entropy per particle, in units of $k_B$, is

\[\begin{aligned} \frac{S}{Nk_B} &= \frac{1}{N} \ln W \\[4pt] &= \frac{1}{N} \ln \frac{N!}{\prod_{i=1}^{M} n_i!} \end{aligned}\]

To simplify the factorials, we can use Stirling’s approximation,

\[\ln N! \approx N \ln N - N\]

Let $p_i=n_i/N$ be the fraction of particles in jar $i$. When $N$ and each $n_i$ are large, substituting the approximation gives

\[\begin{aligned} \frac{S}{Nk_B} &= \frac{1}{N} \ln \frac{N!}{\prod_{i=1}^{M} n_i!} \\[4pt] &= \frac{1}{N} \left( \ln N! - \sum_{i=1}^{M} \ln n_i! \right) \\[4pt] &\approx \frac{1}{N} \left( N \ln N - N - \sum_{i=1}^{M} (n_i \ln n_i - n_i) \right) \\[4pt] &= \frac{1}{N} \left( N \ln N - \sum_{i=1}^{M} n_i \ln n_i \right) \qquad \left(\because \sum_{i=1}^{M} n_i = N\right) \\[4pt] &= \ln N - \sum_{i=1}^{M} \frac{n_i}{N} \ln n_i \\[4pt] &= - \sum_{i=1}^{M} \frac{n_i}{N} \ln \frac{n_i}{N} \\[4pt] &= - \sum_{i=1}^{M} p_i \ln p_i \end{aligned}\]

Now pick a particle at random and let $X$ be the number of the jar containing it. The probability that the particle is in jar $i$ is $P(X=i)=p_i$. The last line of the calculation gives the Shannon entropy of this distribution,

\[H[p]=-\sum_{i=1}^{M} p_i \ln p_i\]

Suppose we put four particles into two jars. Each particle goes left or right independently, with equal probability. Only one sequence sends all four to the left. For an even split, any two of the four placements can go left, giving six sequences. Two particles in each jar is therefore six times as likely as all four in the left jar.

That count is $W$. Since every sequence is equally likely, the most likely distribution of particles is the one with the largest $W$. With $N$ fixed, the same distribution maximizes $\frac{1}{N}\ln W$ because the logarithm is increasing.

With $M$ jars, then, what fraction of the particles should go in each jar to maximize entropy? Suppose there are enough particles that we can vary the fractions $p_i$ continuously. To increase one jar’s share, we have to take particles from the others. The total number of particles is fixed, so $\sum_{i=1}^{M} p_i=1$.

To maximize $H[p]$ under this constraint, we form the Lagrangian $\mathcal L$. The coefficient $\lambda$ that multiplies the constraint term is the Lagrange multiplier.

\[\mathcal L(p,\lambda) =-\sum_{i=1}^M p_i\ln p_i +\lambda\left(\sum_{i=1}^M p_i-1\right).\]

Setting the partial derivative of $\mathcal L$ with respect to each $p_i$ to zero gives $-\ln p_i-1+\lambda=0$. The same $\lambda$ appears in every equation, so all the fractions must be equal. They sum to one, giving $p_i=1/M$. Entropy is concave, so this distribution is a maximum. For two jars, $p_1=p_2=1/2$. With four particles, that is two in each jar.