Formally from $Z=\mathrm{tr} \,e^{-\beta H}$ to $Z=\sum_{n_1, n_2} e^{-\beta (E_1 + E_2)}$ for two non-interacting quantum harmonic oscillators Suppose we have a Hamiltonian of two noninteracting quantum harmonic oscillators. Then the Hamiltonian can be written
$H = H_1 \otimes I_2 + I_1 \otimes H_2$.
When I start with $Z=\mathrm{tr}\, e^{-\beta H}$ I know that end result for the partition function is $Z=\sum_{n_1, n_2} e^{-\beta (E_1 + E_2)}$, however, how does one formally, i.e., taking all the tensor products into account arrive at this result?
 A: Let $\{|1, n_1\rangle\}$ be an orthonormal basis for the Hilbert space $\mathscr H_1$ of oscillator 1, and let $\{|2, n_2\rangle\}$ be an orthonormal basis for the Hilbert space $\mathscr H_2$ of oscillator 2, then the set of all tensor products $\{|1, n_1\rangle\otimes |2, n_2\rangle\}$ is an orthonormal basis for the Hilbert space $\mathscr H_1\otimes \mathscr H_2$.  Let us abbreviate:
\begin{align}
  |n_1, n_2\rangle \equiv |1, n_1\rangle\otimes |2, n_2\rangle,
\end{align}
Notice that for this non interacting Hamiltonian, one has
\begin{align}
  e^{-\beta H}
&= e^{-\beta(H_1 \otimes I_2 + I_1 \otimes H_2)} \\
&= e^{-\beta(H_1\otimes I_2)}e^{-\beta(I_1\otimes H_2)} \qquad (\text{since the summands in the exponential commute})\\
&= (e^{-\beta H_1}\otimes I_2) (I_1 \otimes e^{-\beta H_2}) \qquad (\text{use the power series for the exponential}).\\
&= e^{-\beta H_1}\otimes e^{-\beta H_2}
\end{align}
Thus we have
\begin{align}
  \mathrm{tr} e^{-\beta H}
&= \sum_{n_1, n_2}\langle n_1, n_2 |e^{-\beta H_1}\otimes e^{-\beta H_2}|n_1, n_2\rangle \\
&= \sum_{n_1, n_2}\langle n_1, n_2 |e^{-\beta E_{n_1}} e^{-\beta E_{n_2}}|n_1, n_2\rangle \\
&= \sum_{n_1, n_2}e^{-\beta E_{n_1}} e^{-\beta E_{n_2}}\langle n_1, n_2 |n_1, n_2\rangle \\
&= \sum_{n_1, n_2}e^{-\beta (E_{n_1} + E_{n_2})} \\
\end{align}
as desired.
