# Trace of an operator matrix (Quantum computation and quantum information)

I'm reading the book Quantum computation and quantum information by Mike & Ike and I'm stuck at 2.60/2.61. There, the author says that, given the operator $A|ψ⟩⟨ψ|$, its trace is:

$${\rm tr}(A|\psi\rangle\langle\psi|) = \sum\limits_i\langle i|A|\psi\rangle\langle\psi|i\rangle$$

Why would that be true? Why can we rearrange the bras and kets like that?

-
I worked backwards from equation 2.61 as follows but I'm concerned that my argument is circular so I will post as a comment: $$\langle\psi|A|\psi\rangle =\sum_{i'}\sum_{i''}\langle\psi| i'\rangle\langle i'| A| i''\rangle\langle i''|\psi\rangle$$ $$=\sum_{i'}\sum_{i''}\langle i'| A| i''\rangle \langle i''|\psi\rangle \langle\psi|i'\rangle =\sum_{i'}\langle i'|A|\psi\rangle\langle\psi|i'\rangle =tr(A|\psi\rangle\langle\psi|)$$ – Julien Mar 18 '14 at 21:35
An entry of a matrix $M$ in Dirac notation is obtained (given a basis $\{|i\rangle\}$) via $M_{ij}=\langle i|M|j\rangle$. The trace is the sum of the diagonal entries, i.e. $\operatorname{tr}(M)=\sum_i M_{ii}$ and that's it... – Martin Mar 18 '14 at 23:50

1. Let $\{|i\rangle\}$ be an orthonormal basis for the Hilbert space of the system. Then the trace of an operator $O$ is given by (See the Addendum below) \begin{align} \mathrm {tr}(O) = \sum_i \langle i|O|i\rangle \end{align}

2. For a given state $|\psi\rangle$, we define an operator $P_\psi$ by \begin{align} P_\psi|\phi\rangle = \langle\psi|\phi\rangle|\psi\rangle. \end{align} As a shorthand, we usually write $P_\psi = |\psi\rangle\langle\psi|$.

3. Using steps 1 and 2, we compute: \begin{align} \mathrm{tr}(A|\psi\rangle\langle\psi|) &= \mathrm{tr}(A P_\psi) \\ &= \sum_i \langle i|AP_\psi|i\rangle\\ &= \sum_i \langle i|A (\langle\psi|i\rangle|\psi\rangle)\\ &= \sum_i \langle i|A|\psi\rangle\langle\psi|i\rangle \end{align} which is the desired result.

For simplicity, I'll restrict the discussion to finite-dimensional vector spaces. Recall that if $O$ is a linear operator on a vector space $V$, and if $\{|i\rangle\}$ is a basis for $V$, then the matrix elements $O_{ij}$ of $O$ with respect to this basis are defined by it's action on this basis as follows: \begin{align} O|i\rangle = \sum_jO_{ji}|j\rangle. \tag{$\star$} \end{align} The trace of the linear operator with respect to this basis is then defined as the sum of its diagonal entries; \begin{align} \mathrm{tr}(O) = \sum_i O_{ii}. \tag{$\star\star$} \end{align} Now it turns out that the trace is a basis-independent number, so we can simply refer to the trace of the the linear operator; it's just the trace with respect to any chosen basis.
Now, suppose that $V$ is equipped with an inner product, like in the case of Hilbert spaces, and let $\{|i\rangle\}$ be an orthonormal basis for $V$, then we can take the inner product of both sides of $(\star)$ with respect to an element $|k\rangle$ of the basis to obtain \begin{align} \langle k|O|i\rangle = \sum_j \langle k|O_{ji}|j\rangle = \sum_j O_{ji}\langle k|j\rangle = \sum_jO_{ji}\delta_{jk} = O_{ki} \end{align} In other words, $\langle k|O|j\rangle$ gives precisely the matrix element $O_{kj}$ of $O$ in the given basis. In particular, the diagonal entries are given by $\langle i|O|i\rangle$. Plugging this into $(\star\star)$, we get \begin{align} \mathrm{tr} (O) = \sum_i \langle i|O|i\rangle \end{align} as desired.
Right, my question is mainly why is the trace of an operator given by that thing you said, $\sum_i \langle i|O|i\rangle$. – Pedro Carvalho Mar 18 '14 at 21:58