# Does the CX gate always leave the first qubit unchanged and swap the amplitudes of the second one?

I'm a self-learner of quantum computing and is at the very beginning. I do have some math and coding background though. I'm trying to understand how working with entangled qubits helps performing multiple computations at once, any my first confusion is with the description of the CX gate. It is said, that this is a "controlled not" gate, which swaps the amplitudes of the second qubit only if the first qubit is in the state of $$1$$. But,

1. this description seems strange to me, as to know in which state the first qubit is I guess we need to measure it,

2. the matrix transformation seems to always leave the first qubit unchanged and swap the amplitudes of the second one no matter what, indeed

$$\begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0\end{bmatrix} \cdot\begin{bmatrix}\phi_0\\\phi_1\\\psi_0\\\psi_1\end{bmatrix} = \begin{bmatrix}\phi_0\\\phi_1\\\psi_1\\\psi_0\end{bmatrix}$$

• Concerning the second question. Any controlled gate leaves control qubit(s) unchanged and acts only on target qubit(s). Apr 2, 2022 at 15:41
• @MartinVesely thanks, I understand the goal of the gate, I don’t understand how does it work
– Ilya
Apr 2, 2022 at 16:35

1. There is a difference between an agent's knowledge of the state of the system and the state of the system itself in quantum theory. If you would need to know the true state of the system in order to perform the computation then you would need to measure it, and therefore the state would never be in a superposition and only classical computation follows. Nevertheless, quantum theory allows for agents to act in a way that true knowledge of the state is not needed, but where for no matter which case the state would change accordingly. In the CNOT we don't know what is the true state of the system until we measure, but we do know the possibilities or paths that the quantum state might do, and this is something allowed (similarly in a double slit experiment you do not need to know the true path of the particle to know that if the evolution is according to quantum theory one will observe an interference pattern); the CNOT unitary changes those possibilities because it acts on the quantum states. This is very tricky about quantum theory and so it takes a while to get used to this way of reasoning, but importantly is that the dynamics crucially changes if we update $$\vert \psi \rangle$$ and in quantum theory we are allowed to make unitary changes in $$\vert \psi \rangle \to U\vert \psi \rangle$$ whithout learning about $$\vert \psi \rangle$$'s state in a particular moment.
2. If you note, for the state $$\vert 00 \rangle$$ the vector would read $$(1,0,0,0)$$ and if the state is $$\vert 01 \rangle$$ the vector would read $$(0,1,0,0)$$ therefore even if the matrix is acting, the matrix is changing zero vectors and therefore nothing happens. Your confusion comes from the assumption that those elements in the vector state are always different (or non-zero), but they are linked to the fact that the first qubit has decomposition with terms having $$\vert 10 \rangle$$, $$\vert 11 \rangle$$, therefore having a one in the first qubit; when this does not happen, third and fourth entries are equal to zero and the state is left unchanged. Let's see some examples. For the state $$\vert 11 \rangle$$ the vector would read $$(0,0,0,1)$$ and therefore one has $$(0,0,1,0)$$ which is $$\vert 10 \rangle$$ as wanted. It is also interesting to see the case in which we have a state of the form $$\vert+\rangle\vert0\rangle = \frac{1}{\sqrt{2}}(\vert 00 \rangle + \vert 10 \rangle) \stackrel{CNOT}{\to} \frac{1}{\sqrt{2}}(\vert 00 \rangle + \vert 11 \rangle)$$. Before the application the state was separable, we have used that matrices are linear operations and this made the state of the system entangled. This is probably one of the reasons why the CNOT gate is so important.
• Thanks a lot for the answer! The first point is more or less clear, w.r.t. the second one I still have some questions. First of all, you wrote if you note, for the state $\vert 00 \rangle$ the vector would read $(1,0,0,0)$. What is a state, and which vector are you talking about? To me the state of the first qubit is $(\phi_0, \phi_1)$ and that of the second is $(\psi_0,\psi_1)$, each of the 4 values from $\Bbb C$. Am I getting it wrong?
– Ilya
Apr 2, 2022 at 12:29
• I am sorry, but here is the point. Whenever we have two qubits associated to systems $\mathcal{H}_1$ and $\mathcal{H}_2$ we have that the space in which the joint system must be described is given by $\mathcal{H}_1 \otimes \mathcal{H}_2$. Therefore the correct way to express the vectors should be in $\mathbb{C}^2 \otimes \mathbb{C}^2 \simeq \mathbb{C}^4$ and this is way a four dimensional vector space (you used a 4-dimensional vector and that is why I thought you were confortable with this kind of mathematical description of quantum states and systems).
– R.W
Apr 2, 2022 at 12:33
• Therefore, I choose the canonical basis for the space $\mathbb{C}^4$ to be $\{\vert 00 \rangle, \vert 01 \rangle, \vert 10 \rangle, \vert 11 \rangle \}$. It is with respect to this basis that the matrix you presented is written. Hence, any quantum state that you consider to be acted by the CNOT would should write it with respect to this canonical basis. In these terms, we have that the vector representation is given as the vectors I have outlined. In summary, not all vectors of the large system $\mathbb{C}^4$ can simply be understood as the concatenation of the two qubit vectores you described
– R.W
Apr 2, 2022 at 12:36
• Ah ok, got it, you mean that $|00\rangle = (1,0,0,0)$ etc. are those possible states that we observe once we measure the system. Agree with all the things about how those vectors will be affected by the matrix then. Then, a second unclear sentence of yours: Your confusion comes from the assumption that those elements in the vector state are not equal to zero. Could you clarify this? Also, the part you've added after the edit is very interesting, but for now beyond my understanding (I don't know what separable is).
– Ilya
Apr 2, 2022 at 12:44
• When you made the change $(a,b,c,d) \to (a,b,d,c)$ you suppose that $(a,b,c,d) \neq (a,b,d,c)$ but this is only true if $d\neq c$ which is not necessary and the case $d=c=0$ is the most important example because it uses vectors from the canonical basis of $\mathbb{C}^4$. This is why you may think that it is transforming any state regardless of the first vector, but the fact is is that it is not: it only transforms when the first one has a $one$ which implies that $d$ and $c$ would not be zero.
– R.W
Apr 2, 2022 at 12:48