# Quantum computing: CNOT gate

A CNOT gate can be written as follow:
$$\begin{pmatrix}1 & 0 & 0 & 0 \\\ 0 & 1 & 0 & 0 \\\ 0 & 0 & 0 & 1 \\\ 0 & 0 & 1 & 0 \end{pmatrix}$$

So using the CNOT gate on $\psi = |0\rangle$ and $\phi = |1\rangle$ can be written as: $$\mathrm{CNOT}(\psi, \phi) =\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 \\\ 1 \end{pmatrix}$$

But the heck is that the control qubit ($\psi$) is on state $|0\rangle$, so the target qubit ($\phi$) should not be flipped.

I we do the maths, the result system = $\begin{pmatrix} 1 \\\ 0 \\\ 1 \\\ 0 \end{pmatrix}$

The target qubit is flipped even if the control qubit is $|0\rangle$, I think that I'm doing something wrong with the maths but I don't know what..

You're doing a direct sum instead of a tensor product of the two vectors; as such, your input state is wrong.

A direct sum operates by concatenating the two vectors: $$\psi \oplus \phi = \begin{pmatrix}\psi_1\\\psi_2\end{pmatrix} \oplus \begin{pmatrix}\phi_1\\\phi_2\end{pmatrix} = \begin{pmatrix} \begin{pmatrix}\psi_1\\\psi_2\end{pmatrix}\\ \begin{pmatrix}\phi_1\\\phi_2\end{pmatrix} \end{pmatrix} = \begin{pmatrix}\psi_1\\\psi_2\\\phi_1\\\phi_2\end{pmatrix} .$$ In a tensor product, on the other hand, you form a 'vector of vectors', whose entries are products of the components of the initial two vectors: $$\psi \otimes \phi = \begin{pmatrix}\psi_1\\\psi_2\end{pmatrix} \otimes \begin{pmatrix}\phi_1\\\phi_2\end{pmatrix} = \begin{pmatrix} \psi_1\begin{pmatrix}\phi_1\\\phi_2\end{pmatrix}\\ \psi_2\begin{pmatrix}\phi_1\\\phi_2\end{pmatrix} \end{pmatrix} = \begin{pmatrix}\psi_1\phi_1\\\psi_1\phi_2\\\psi_2\phi_1\\\psi_2\phi_2\end{pmatrix} .$$ You need to be doing the latter, not the former, so that you work in the computational basis, $$\left\{ |00\rangle = |0\rangle\otimes|0\rangle, |01\rangle = |0\rangle\otimes|1\rangle, |10\rangle = |1\rangle\otimes|0\rangle, |11\rangle = |1\rangle\otimes|1\rangle \right\}.$$ That means, in particular, that the state $$|\psi\rangle\otimes |\phi\rangle = |0\rangle \otimes |1\rangle = |01\rangle$$ gets represented by the vector $$\begin{pmatrix} 1\begin{pmatrix}0\\1\end{pmatrix}\\ 0\begin{pmatrix}0\\1\end{pmatrix} \end{pmatrix} = \begin{pmatrix} 0 \\ 1 \\ 0 \\ 0 \end{pmatrix},$$ which remains invariant under the CNOT matrix you've (correctly) given.

More generally, you seem to be having trouble interpreting vectors in a column format. So, to be clear: the amplitudes in each entry correspond to the probability amplitude that the system is in the corresponding basis state, so that e.g. the state $$\begin{pmatrix} \alpha \\ \beta \\ \gamma \\ \delta \end{pmatrix} \leftrightarrow \alpha |00\rangle + \beta |01\rangle + \gamma |10\rangle + \delta |11\rangle$$ has a probability $$|\beta|^2$$ to be in the state $$|01\rangle = |0\rangle\otimes|1\rangle$$, and so on.

• Right, But let's say: CNOT(|1>, |1>) = CNOT * (|1> tensor |1>) = CNOT * [0, 0, 0, 1] = [0, 0, 0, 0]. My target qubit is correctly flipped but my control qubit is now |00> but the control qubit is not supposed to change Feb 26, 2018 at 22:02
• That's... an interesting mix of misconceptions. First of all, the CNOT matrix you've (correctly) laid out is unitary and non-singular (it can be trivially seen to have nonzero determinant) so it cannot possibly take a nonzero vector to zero. If you actually do the matrix multiplication with care, you get $\mathrm{CNOT}(0,0,0,1) = (0,0,1,0)$, which corresponds to the basis vector $|10\rangle$ (the third basis vector in the canonical computational-basis ordering), that is, the control qubit remains in $|1\rangle$ but the target qubit is flipped. Feb 27, 2018 at 11:04
• As to how you can think that "the control qubit is now |00>" ─ that's a two-qubit state, so the statement makes no sense at all. If you think that that "00" is the first two zeroes of (0,0,0,0), then you're doing two very wrong things: (i) you're splitting the vector as $((0,0),(0,0))$ in the style of a direct sum instead of a tensor product, and (ii) you seem to be identifying the vector $(0,0)$ with the vector $|0\rangle$, and that's not the case: the zero state vector (with zero norm) is distinct from the state vector that indicates a 100% probability that the first qubit reads zero. Feb 27, 2018 at 11:10
• Yeah sorry I learn quantum computing from my own so i have a lot of gaps and misconceptions ^^.. So, to sum up: For instance, CNOT(|1>, |0>) = [0, 0, 0, 1] which is the 2 qubit system state |11>, meaning that the two qubits of the system are of state |1>. CNOT(|0>, |1>) = [0, 1, 0, 0] which is the state |01>, nothing has changed (excluding entanglement). Am I wrong ? Feb 27, 2018 at 18:02
• Both of those calculations are correct. Feb 27, 2018 at 18:02

For the CNOT gate matrix as you've written it, the basis for the state space is $\{|00\rangle,|01\rangle,|10\rangle,|11\rangle\}$. As such, the input state you started with was actually $|00\rangle + |11\rangle$, and you ended, as you should, with $|00\rangle+|10\rangle$. If you wanted to start with the state $|01\rangle$, you should have input $(0,1,0,0)^T$. Then your output would be $(0,1,0,0)^T$, so the CNOT gate takes $|01\rangle$ to $|01\rangle$, as expected.

In the matrix form of the CNOT gate, the first qubit is assumed to be the control and the second one the target. Therefore, in the vector you provided, $|{C}\rangle = |1\rangle$ and $|T\rangle = |0\rangle$, resulting in $|{C}\rangle = |1\rangle$ and $|T\rangle = |1\rangle$.

• So what does the state $(1,0,0,0)^T$ correspond to, if what you say is true? Feb 26, 2018 at 15:40