# How to apply Controlled-NOT gate?

look at the figure below it is about an example to multiply two qubits by 3 Controlled gate to get the SWAP operation .. I'm trying to follow this step-by-step but I couldn't know how this is evaluated?

I tried by matrix representation to understand the concept but I couldn't .. as following:

$$\begin{pmatrix} ac & ad \\ bc & bd \end{pmatrix}$$ Then After apply first Controlled-NOT we get $$\begin{pmatrix} ac & ad \\ bd & bc \end{pmatrix}$$ Then After apply Second Controlled-NOT we get $$\begin{pmatrix} ac & bc \\ bd & ad \end{pmatrix}$$ Then After apply Third Controlled-NOT we get $$\begin{pmatrix} ac & bc \\ ad & bd \end{pmatrix}$$

I tried to follow how this was managed but I couldn't. Because I didn't find any thing that I can multiply to get the previous matrices.. (in some point I thought Pauli matrix X gate would manage that but it doesn't)

I tried to use the Controlled-NOT 4-by-4-matrix as shown in below

so I tried to multiply this matrix to 4-by-1 matrix (the representation of two qubits in matrix such as $$\begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 0& 1\\ 0 & 0 & 1& 0 \end{pmatrix} \cdot \begin{pmatrix}ac \\ac \\bc \\bd \end{pmatrix} = \begin{pmatrix}ac \\ad \\bd \\bc \end{pmatrix}$$

Now, taking the result and multiply by Controlled-NOT again, we get $$\begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 0& 1\\ 0 & 0 & 1& 0 \end{pmatrix} \cdot \begin{pmatrix}ac \\ad \\bd \\bc \end{pmatrix} = \begin{pmatrix}ac \\ad \\bc \\bd \end{pmatrix}$$ it seems that I did nothing, since the result is the same as the initial one .. so, can you convince me by algebraic (matrix method) that by using Controlled-NOT, then I can get the result as the shown in the figure above ..

Thank you ..

Reference: the figure is taken from this paper

The following calculations are in the basis of $(|00\rangle,|01\rangle,|10\rangle,|11\rangle$)

CNOT1 - when the first qubit is control -
$CNOT1|00\rangle = |00\rangle$
$CNOT1|01\rangle = |01\rangle$
$CNOT1|10\rangle = |11\rangle$
$CNOT1|11\rangle = |10\rangle$

thus it's matrix representation is $$CNOT1 = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 0& 1\\ 0 & 0 & 1& 0 \end{pmatrix}$$

CNOT2 - when the second qubit is control -
$CNOT2|00\rangle = |00\rangle$
$CNOT2|01\rangle = |11\rangle$
$CNOT2|10\rangle = |10\rangle$
$CNOT2|11\rangle = |01\rangle$

thus it's matrix representation is - $$CNOT2 = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 0 & 0 & 1\\ 0 & 0 & 1& 0\\ 0 & 1 & 0 & 0 \end{pmatrix}$$

thus -
$$CNOT1 \cdot CNOT2 \cdot CNOT1 = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 0& 1\\ 0 & 0 & 1 & 0 \end{pmatrix} \cdot \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 0 & 0 & 1\\ 0 & 0 & 1& 0\\ 0 & 1 & 0 & 0 \end{pmatrix} \cdot \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 0& 1\\ 0 & 0 & 1 & 0 \end{pmatrix} = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 1 & 0& 0\\ 0 & 0 & 0 & 1 \end{pmatrix} =SWAP$$

• Might want to consider \begin{align} CNOT1... &= matrices \\ & = result \\ &= ? \end{align} so we can read your equations – Kyle Kanos Jun 22 '15 at 0:39
• @Alexander Thank you so much ..Aha, the key point is that when we perform Controlled-NOT get in the 2nd time, we make the second qubit as control qubit, and in the 3rd time, we make the first qubit as control qubit, etc. And since SWAP operations needs 3 CNOT gates, then we do it as following CNOT1*CNOT2*CNOT1. OK, thank you again .. – YOUSEFY Jun 22 '15 at 1:56