I am reading James P. Sethna, Statistical Mechanics : Entropy, Order Parameters, and Complexity, p.137 and stuck at some equality. I think that this question is like homework-question ( In fact this is more of a mathematical question ) but even if I think about it alone, I can't really understand why that equality is true. So please understanding.
Let me present his argument in p.137 about Canonical distribution.
Canonical Distribution. The canonical distribution is a mixture of the energy eigenstates $|E_n\rangle$ with Boltzmann weights $\operatorname{exp}(-\beta E_n)$. Hence the (canonical) density matrix $\rho_{\operatorname{canon}}$ is diagonal in the energy basis :
$$\rho_{\operatorname{canon}}=\sum_{n} \frac{\operatorname{exp}(-\beta E_n)}{Z}|E_n\rangle \langle E_n|. $$
We can write the canonical density matrix in a basis-independent form using the Hamiltonian operator $\mathcal{H}$. First, the parition function is given by the trace
$$ Z=\sum_n\operatorname{exp}(-\beta E_n)= \sum_n \langle E_n| \operatorname{exp}(-\beta\mathcal{H})|E_n \rangle = \operatorname{Tr}(\operatorname{exp}(-\beta \mathcal{H})).$$
Second, the numerator
$$\sum_n |E_n \rangle \operatorname{exp}(-\beta E_n)\langle E_n| =\sum_n|E_n \rangle \operatorname{exp}(-\beta\mathcal{H})\langle E_n| \stackrel{?}{=} \operatorname{exp}(-\beta \mathcal{H}) $$
since $\mathcal{H}$ ( and thus $\operatorname{exp}(-\beta \mathcal{H})$ ) is diagonal in the 'energy basis'. Hence
$$ \rho_{\operatorname{canon}} = \frac{\operatorname{exp}(-\beta \mathcal{H})}{\operatorname{Tr}(\operatorname{exp}(-\beta \mathcal{H}))} .$$
I don't understand why the second equality marked by the question symbol is true.
By 'energy basis' above, I understand this term as existing basis consisting of eigen vectors of $\mathcal{H}$ (true?). Since $\mathcal{H}$ is hermitian, this kind of eigenvectors exists. And the matrix representation of $\mathcal{H}$ with respect to this basis is a diagonal matrix whose entries consisting of eigenvalues ( energies ? ) But I don't make sure that the matrix representation of $\operatorname{exp}(-\beta \mathcal{H})$ with respect to the basis is also diagonal. We can't ensure that $\operatorname{exp}(-\beta \mathcal{H})$ is also hermitian so it doesn't gaurantee the existence of basis consisting of eigenvectors ( of $\operatorname{exp}(-\beta \mathcal{H})$ ). Can someone arrange this mathematical issue more clean?
Now, let's go to next step. Assume that $\operatorname{exp}(-\beta \mathcal{H})$ is diagonal in the energy basis. Then why the question mark is true? What the notation $\sum_n|E_n \rangle \operatorname{exp}(-\beta\mathcal{H})\langle E_n| $ exactly means? I think that I saw that kind of form in Quantum mechanics course, matrix mechanics etc.. but I don't remember its exact definition well.
I examined some example but I think that this example is not consistent well with the above equality. Example that I examined is as follows. Let $L_A : R^2 \to R^2 $ be a operator given by a matrix $A := \begin{pmatrix} 1 & 3 \\ 4 & 2 \end{pmatrix} $, $v_1 := \begin{pmatrix} 1 \\ -1 \end{pmatrix}$, and $v_2 := \begin{pmatrix} 3 \\ 4 \end{pmatrix}$. Then through some calculation, we can show that $\beta := \{ v_1, v_2\}$ is an ordered basis for $R^2$ consisting of eigenvectors of $L_A$, and $[L_A]_{\beta} = \begin{pmatrix} -2 & 0 \\ 0 & 5 \end{pmatrix} $, which is diagonalized matrix.
But, if my calculation is correct(?), neither $ \begin{pmatrix} v_1 \\ v_2 \end{pmatrix}\begin{pmatrix} -2 & 0 \\ 0 & 5 \end{pmatrix} \begin{pmatrix} v_1 & v_2 \end{pmatrix} $ nor $ \begin{pmatrix} v_1 & v_2 \end{pmatrix}\begin{pmatrix} -2 & 0 \\ 0 & 5 \end{pmatrix} \begin{pmatrix} v_1 \\ v_2 \end{pmatrix} $ is equal to $\begin{pmatrix} -2 & 0 \\ 0 & 5 \end{pmatrix}$.
Where did problem occur? Again, what is the exact definition for $\sum_n|E_n \rangle \operatorname{exp}(-\beta\mathcal{H})\langle E_n| $? Can anyone helps?