# CNOT gate application to separated qubits

In the case 1 in the picture, it is easy to perform matrix calculations concerning the circuit to obtain a final state.

In case 2 however, I am wondering what is a general procedure to calculate it with matrices? None of tensor products of gates seems right. A decomposition of the CNOT gate into two matrices and sandwiching the Hadamard with them seems to be the only option but it is impossible to do it.

Can you help me?

• I don't understand: Is the Hadamard also conditioned? Or is it just "in the middle"? In the latter case, why don't you just permute $|\psi_1\rangle$ and $|\psi_2\rangle$? Then it's the second. Apr 13, 2015 at 20:26

$G=(\mathbb{I} \otimes \mathbb{H} \otimes \mathbb{I})(C_{1,3})$
$C_{1,3}=\begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ \end{pmatrix}$
$|\psi_1\psi_2\psi_3\rangle \rightarrow \begin{pmatrix} |000 \rangle \\ |001 \rangle \\ |010 \rangle \\ |011 \rangle \\ |100 \rangle \\ |101 \rangle \\ |110 \rangle \\ |111 \rangle \\ \end{pmatrix}$
Notice the locations of the $\mathbb{X}$ (NOT operator) in the $C_{1,3}$. Essentialy this is a $\mathbb{CX}$ gate, on those qubits, and you can make it a $\mathbb{CU}$ gate ( $\mathbb{U}$ any unitary matrix ) by replacing $\mathbb{X}$ with $\mathbb{U}$ in the matrix.