Solution (source code)

= Solution

For the canonical <quantum Gibbs state>,
$$
\boxed{\rho=\frac{e^{-\beta H}}Z,\qquad
Z=\operatorname{Tr}e^{-\beta H},\qquad
\beta=\frac1{k_BT}.}
$$
If $H|n\rangle=E_n|n\rangle$, its spectral form is $\rho=Z^{-1}\sum_ne^{-\beta E_n}|n\rangle\langle n|$, with a sum over any degeneracy and an integral where a continuous spectrum needs one. It is Hermitian, positive and has unit <trace>, and it commutes with $H$. The formula presumes a well-defined finite <partition function>. At zero <temperature> a nondegenerate stable system approaches its ground-state projector; a degenerate ground space requires specifying the ensemble or preparation.