# Does conditional gate collapse controller's superposition?

I've created a simple circuit in Q-Kit to understand conditional gates and outputted states on each step:

1. In the beginning there is clear 00 state, which is the input
2. The first qubit is passed through the Hadamard gate, it gets into superposition, 00 and 10 become equally possible
3. The first qubit CNOTs the second one, probability of 00 is unchanged, but 10 and 11 are swapped
4. The first qubit passes Hadamard again and probability of 00 is splited between 00 and 10, and 11 between 01 and 11 as if first qubit stepped into superposition from a fixed state

Shouldn't the result be equally distributed 00 and 01? The first qubit passes Hadamard twice, which should put it into superposition and back to initial 0. The CNOT gate does not affect controller qubit, so its existence shouldn't affect first qubit at all, but in fact it makes it act like it wasn't in superposition any more. Does usage of qubit as a controller collapse its superposition?

$$\begin{eqnarray*} \mid 0 0 \rangle &\to& \frac{1}{\sqrt{2}} \mid 0 0 \rangle + \frac{1}{\sqrt{2}} \mid 1 0 \rangle\\ &\to& \frac{1}{\sqrt{2}} \mid 0 0 \rangle + \frac{1}{\sqrt{2}} \mid 1 1 \rangle\\ &\to& \frac{1}{\sqrt{4}} \mid 0 0 \rangle + \frac{1}{\sqrt{4}} \mid 1 1 \rangle + \frac{1}{\sqrt{4}} \mid 1 0 \rangle + \frac{1}{\sqrt{4}} \mid 0 1 \rangle \end{eqnarray*}$$

If the second line was $(\frac{1}{\sqrt{2}} \mid 0 \rangle + \frac{1}{\sqrt{2}} \mid 1 \rangle) \otimes v$, then applying the $H$ again would take it to $\mid 0 \rangle \otimes v$, but it is not. They are entangled.

It seems like you're thinking the first qubit is unaffected by the CNOT, so the last two should commute.

$$\begin{eqnarray*} H_1 CNOT_{12} &=& \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 0 & 0 & 1\\ 0 & 1 & 1 & 0\\ 1 & 0 & 0 & -1\\ 0 & 1 & -1 & 0 \end{pmatrix}\\ CNOT_{12} H_1 &=& \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 0 & 1 & 0\\ 0 & 1 & 0 & 1\\ 0 & 1 & 0 & -1\\ 1 & 0 & -1 & 0 \end{pmatrix}\\ \end{eqnarray*}$$

It is in a superposition, the entire time. There was no collapse. It's a nonobvious noncommutation. If you had $Id \otimes U$, that would be something literally not affecting the first qubit and it would commute with $H_1$. But CNOT is not of that form.

You can think of it this way at the beginning you have 2 qubits. After applying the first $H$ you still have 2 qubits. Then after the CNOT, they are entangled so you have 1 qudit with $d=4$ because they have been combined. Then the last $H$ leaves it with $d=4$. At each gate, you do a worst case scenario of the entanglement structure.

No, using a controlled gate doesn't measure the control.

In a sense, the idea that controlled gates would be implemented via measurement is exactly backwards. It's measurement that is implemented in terms of controlled gates, not vice versa. A measurement is just an interaction (i.e a controlled gate) between the computer and the environment that's intractable to undo.

As a simpler analogy, consider the Z gate. The Z gate applies a -1 phase factor to the $|1\rangle$ state of a qubit. It sends $a|0\rangle + b|1\rangle$ to $a|0\rangle - b |1\rangle$. One could describe this effect in a conditional way: if the qubit is in the $|1\rangle$ state, then the Z gate phases the qubit by -1. But the "if" in that description does not mean that we had to measure the qubit and then decide whether or not to apply the -1 phase factor, it's just a slightly-misleading description.

The same idea applies to the CNOT. Yes, you can describe it in an if-then way. But you can also describe it as "apply a -1 phase factor to the $|1\rangle \otimes |-\rangle$ state". And the latter description makes it clear that measurement is not necessary.

1. In the beginning there is clear 00 state, which is the input
2. The first qubit is passed through the Hadamard gate, it gets into superposition, 00 and 10 become equally possible

Correct.

1. The first qubit CNOTs the second one, probability of 00 is unchanged, but 10 and 11 are swapped

To be precise, 10 becomes 11.

1. The first qubit passes Hadamard again and probability of 01 is splited between 01 and 11, and 11 between 01 and 11 as if first qubit stepped into superposition from a fixed state

Incorrect. There is no 01 here, only 00 and 11, and after applying Hadamard to the first qubit you have superposition of 4 states: 00, 10, 11 and 01, $$\frac{1}{\sqrt{2}}(|00\rangle+|11\rangle)\rightarrow\frac{1}{2}(|00\rangle+|10\rangle+|01\rangle-|11\rangle)$$