Solution (source code)

= Solution

In the <grand canonical ensemble>, the system exchanges both <energy> and particles with a reservoir at fixed <temperature> $T$ and <chemical potential> $\mu$. The probability of a particular many-body <microstate> $i$, with <energy> $E_i$ and <particle number> $N_i$, is its <Boltzmann weight> $e^{-\beta(E_i-\mu N_i)}$ divided by the <grand canonical partition function> $\Xi$, where $\beta=1/(k_BT)$. The denominator normalizes $\sum_i p_i=1$; a degeneracy is accounted for by counting distinct microstates, rather than changing an individual state's probability.

For noninteracting particles, specify a microstate by the <occupation numbers> $n_r$ of one-particle levels of <energy> $\epsilon_r$. Then $E-\mu N=\sum_r(\epsilon_r-\mu)n_r$, so the Gibbs probability factorizes between levels. Put $x_r=e^{-\beta(\epsilon_r-\mu)}$.

For <fermions>, the <Pauli exclusion principle> permits $n_r=0,1$ in each complete one-particle state, giving $\Xi_r=1+x_r$. Its mean occupancy is
$$
\boxed{\langle n_r\rangle=\frac{0+x_r}{1+x_r}
=\frac1{e^{\beta(\epsilon_r-\mu)}+1},}
$$
the <Fermi-Dirac distribution>.

For <bosons>, $n_r=0,1,2,\ldots$, so the geometric sum is $\Xi_r=1/(1-x_r)$ when $x_r<1$. Differentiating that sum gives
$$
\boxed{\langle n_r\rangle=
\frac{\sum_{n=0}^\infty n x_r^n}{\sum_{n=0}^\infty x_r^n}
=\frac{x_r}{1-x_r}
=\frac1{e^{\beta(\epsilon_r-\mu)}-1},}
$$
the <Bose-Einstein distribution>. Finite-system convergence requires $\mu<\epsilon_{\min}$; condensation is the limiting approach to the lowest <energy> with macroscopic ground-state occupation. Both quantum distributions reduce to $e^{-\beta(\epsilon_r-\mu)}$ when occupation is small. The quantities derived here are mean occupancies of states, rather than normalized probabilities over the set of one-particle energies.