My understanding is that the control qubit in a controlled-not gate remains unchanged after the controlled-not operation is performed on a target-qubit (so the Pauli-X gate is performed only on the target-qubit, and nothing is done to the control qubit). Such that, if the control-qubit is measured later, it would have the same value as though it had never acted as a control-qubit.

That understanding seems to be supported by most of the materials available, and by, for instance, the first few minutes of this video: http://www.youtube.com/watch?v=rLF-oHaXLtE

However, I find two quantum computer simulators which produce results contrary to my assumption, wherein the control-qubit appears to be modified by the CNOT gate in certain circumstances.

There is a nifty quantum computer simulator here that I suggest you use to see what I'm talking about. It runs in your browser and doesn't need Java or Flash (it's HTML5): http://www.davyw.com/quantum/

Here is the setup code: On the webpage, select the [Workspace] Menu, then select [Import JSON] and paste in the following code to set up the example circuit:


The results of psuedo-measurement return |00> and |11>, however, shouldn't the first qubit always be 0 when measured, even if it is in fact a control-qubit, since the control-qubit remains unchanged regardless of what the target qubit's value is? The second hadamard gate should just reverse the first hadamard gate, meaning whatever value that qubit was initialized with (|0>) should be be the same upon measurement (|0>) -- which is what happens when the CNOT gate is not present.

Why are these programs flipping the first qubit, the control-qubit, in some cases?

The second quantum computing simulation program that does the same is: QCAD 2.0 (qcad.sourceforge.jp).

Note: In the webpage simulator linked, you may remove the CNOT gate by right clicking on it, and you will observe that running the simulator (by pressing [ENTER]) produces 0 for all possible measurements of the first qubit as expected, but with a CNOT in place and the first qubit as the control-qubit, placed mid-way on the circuit between the hadamards, the first qubit sometimes measures 1 according to this simulator (press [ENTER] to see the adjusted measurements).


1 Answer 1


I have checked out http://www.davyw.com/quantum/
Everything I've seen seems OK to me. What you need to be careful with is the order of the qubits.
The control qubit is not always the first qubit!
The control qubit is the one with the black dot, but the order of the qubits is still top to bottom. So, CNOT transforms |00> and |01> into themselves if the black dot is on the top wire, while mapping |10> to |11> and vice versa. In the case of the black dot being on the bottom wire, |00> and |10> remain intact while |01> and |11> map to each other.

The circuit under consideration is

I think that the reason of your confusion might be that you actually have to look at what happens to the bottom cubit in order to calculate what happens to the top one. For example, applying $R_2=\mathrm{diag} (1;i)$ matrix to the bottom cubit is represented by the tensor product $I\otimes R_2$ which is equivalent to the 4x4 matrix $$ \begin{bmatrix}R_{2}\\ & R_{2} \end{bmatrix}. $$ Applying the Hadamard gate to both qubits is represented by $H\otimes H$, or the 4x4 matrix $$ \begin{bmatrix}H & H\\ H & -H \end{bmatrix}. $$ Therefore, R2 together with the two Hadamard gates gives $(H\otimes H)(I\otimes R_2)(H\otimes H)=I\otimes HR_2H$ which, again, is represented by the 4x4 matrix $$ \begin{bmatrix}HR_{2}H\\ & HR_{2}H \end{bmatrix}. $$ So, in this case the first cubit indeed doesn't change its state. At the same time, the CNOT gate cannot be represented by a tensor product of two matrices. In other words, it causes quantum entanglement, hence you have to follow both wires in order to find out what happens to either one of the qubits. The easiest way to do that is to perform a direct calculation of the matrix products.

Not being able to replace CNOT with a tensor product, we have to write that our circuit is represented by the product

$$\begin{bmatrix}H & H\\ H & -H \end{bmatrix}\begin{bmatrix}R_{2}\\ & R_{2} \end{bmatrix}\begin{bmatrix}I\\ & X \end{bmatrix}\begin{bmatrix}H & H\\ H & -H \end{bmatrix}=\frac{1}{2}\begin{bmatrix}1+i & & & 1-i\\ 1-i & & & 1+i\\ & 1-i & 1+i\\ & 1+i & 1-i \end{bmatrix},$$ where the basis vectors are chosen from top to bottom as follows: |00>, |01>, |10>, |11>. Without the CNOT gate it evaluates to $$ \begin{bmatrix}HR_{2}H\\ & HR_{2}H \end{bmatrix}=\frac{1}{2}\begin{bmatrix}1+i & 1-i\\ 1-i & 1+i\\ & & 1+i & 1-i\\ & & 1-i & 1+i \end{bmatrix}. $$ Hence, an input of |00> leads to $$ \frac{1}{2}\begin{bmatrix}1+i & & & 1-i\\ 1-i & & & 1+i\\ & 1-i & 1+i\\ & 1+i & 1-i \end{bmatrix}\begin{bmatrix}1\\ 0\\ 0\\ 0 \end{bmatrix}=\frac{1}{2}\begin{bmatrix}1+i\\ 0\\ 0\\ 1-i \end{bmatrix}=\frac{1}{2}\left((1+i)\left|00\right\rangle +(1-i)\left|11\right\rangle \right) $$ for the full circuit and $$ \frac{1}{2}\begin{bmatrix}1+i & 1-i\\ 1-i & 1+i\\ & & 1+i & 1-i\\ & & 1-i & 1+i \end{bmatrix}\begin{bmatrix}1\\ 0\\ 0\\ 0 \end{bmatrix}=\frac{1}{2}\begin{bmatrix}1+i\\ 1-i\\ 0\\ 0 \end{bmatrix}=\frac{1}{2}\left((1+i)\left|00\right\rangle +(1-i)\left|01\right\rangle \right) $$ for the circuit without the CNOT. Which coincides with what the simulator says.

  • $\begingroup$ Did you use the example circuit I gave, copying and pasting it? The first qubit is clearly the control-qubit, after a hadamard. The input register should always be |00>, or 0, 0, top-to-bottom, for my example. When running the circuit with |00> as inputs, the simulator will output |00> AND |11> as outputs, each with 50% probability. That should be wrong however, as the first qubit (the "top" qubit which corresponds to the "first" qubit in the outputs) only has two hadamards and its initial/prepared value is 0, so its output should be 0, ie the outputs should be |00> and |01>, do you see? $\endgroup$ Commented Jan 13, 2014 at 21:52
  • $\begingroup$ @justwondering see my edit. $\endgroup$ Commented Jan 14, 2014 at 6:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.