Solution (source code)

= Solution

A <grand canonical ensemble> describes a system that exchanges both energy and particles with a reservoir, at fixed $T,V,\mu$. If microstate $n$ has occupation $N_n$ and one-particle energy $E_n$, then
$$
\boxed{\mathcal Z=\sum_{\{N_n\}}
\exp\!\left[-\beta\sum_nN_n(E_n-\mu)\right]},
\qquad \beta=(k_BT)^{-1},
$$
with the allowed occupations chosen for the particle statistics.