I'm trying to understand the Dirac notation to understand quantum mechanics better. I'm trying to show the above relation using the Dirac notation.
Given
$$\mathrm{Tr}(X)~=~\sum_j\langle j|X|j\rangle$$ and $$\mathrm{Tr}(Y)~=~\sum_j\langle j|Y|j\rangle.$$ Thus,$$\mathrm{Tr}(XY)~=~\sum_{ij}\langle j|X|i\rangle \langle i|Y|j\rangle.$$ And isn't that just equal to the following $$\mathrm{Tr}(XY)~=~\sum_j \langle j|XY|j\rangle?$$ But that shouldn't equal the following $$\mathrm{Tr}(XY)~=~\sum_j\langle j|YX|j\rangle,$$ since $XY \neq YX$, right?