# Partial Trace over a complicated looking state

In the Quantum Operations section in Nielsen and Chuang, (page 358 in the 2002 edition), they have the following equation: $$\varepsilon(\rho) = tr_{env} [U(\rho \otimes \rho_{env})U^\dagger]$$

They show an example where

$$\rho_{env} = |0\rangle \langle0|$$ $$U = CNOT$$

And they claim the final solution is: $$P_0\rho P_0 + P_1\rho P_1$$ where $$P_0$$ is $$|0\rangle \langle0|$$ and P1 is $$|1\rangle \langle 1|$$.

These are my steps so far to get this, but I don't know how to trace out environment after this:

Let $$\rho$$ be $$|\psi \rangle \langle \psi |$$

So, $$\rho \otimes \rho_{env} = |\psi 0\rangle \langle \psi 0|$$

After applying the unitary,

$$|00 \rangle \langle 00| \psi 0 \rangle \langle \psi 0 | 00 \rangle \langle 00 |$$

$$+ |00 \rangle \langle 00| \psi 0 \rangle \langle \psi 0 | 10 \rangle \langle 11 |$$

$$+ |11 \rangle \langle 10| \psi 0 \rangle \langle \psi 0 | 00 \rangle \langle 00 |$$

$$+ |11 \rangle \langle 10| \psi 0 \rangle \langle \psi 0 | 10 \rangle \langle 11 |$$

I don't know how to trace out environment for the above state.

Also, I realize that I have considered only a pure state, if anyone can show it for a general state that would be great.

Let's start with a general state $$\rho\otimes\rho_0=\sum_{x,y\in\{0,1\}}\langle x|\rho|y\rangle|x\rangle\langle y|\otimes |0\rangle\langle 0|.$$ If we apply the controlled-not, we have $$\rightarrow\rho_{\text{final}}=\sum_{x,y\in\{0,1\}}\langle x|\rho|y\rangle|x\rangle\langle y|\otimes |x\rangle\langle y|.$$
Now we want to take the partial trace over the second subsystem. This means calculating $$\sum_k(\mathbb{I}\otimes\langle k|)\rho_{\text{final}}(\mathbb{I}\otimes|k\rangle)=\sum_k\sum_{x,y\in\{0,1\}}\langle x|\rho|y\rangle|x\rangle\langle y|\times \langle k|x\rangle\langle y|k\rangle.$$ If we perform the sums over $$x$$ and $$y$$, we find that $$x=y=k$$, so $$=\sum_k\langle k|\rho|k\rangle|k\rangle\langle k|,$$ which is entirely equivalent to removing all the off-diagonal elements of $$\rho$$.