3.1.6 Controlled-NOT operation
and operations together can be used to change individual bits and to reorder them in a different order. However, they don’t cause the bits to interact with one another. What we would like is another more sophisticated operation that can change the value of one bit depending on the value of another. The simplest and most important such operation is or the controlled-NOT operation. It flips the target bit if the control bit is set to .
When the first bit is the control and the second bit is the target, we will write this operation as . In this case:
This amounts to exchanging the strings and while leaving the other two strings alone.
Another way of thinking about is as an addition: it adds the two bits (modulo ) and stores the result in the second bit. This can be summarized very concisely as follows:
for any , where “” denotes addition modulo and we use a comma to separate the values of the two bits. The laws for addition modulo 2 are as follows:
Sometimes “” is also called XOR or the exclusive OR operation, since the result is when exactly one out of the two bits are . As usual, we can extend from deterministic to probabilistic bits by linearity.
We will also be interested in controlled-NOT operations where the second bit is the control and the first is the target. In analogy, we will denote this operation by .
Exercise 3.4 ( Swapping control and target ).
-
1.
Write down a formula similar to Eq. 3.20 for .
-
2.
How can be implemented using and ?
In Quirky, you can build a controlled-NOT operation by the following two-step process. First, drag the box onto one of the wires – this marks the wire as the control bit. Next, drag the box onto the corresponding location on the other wire, marking it as the target bit. A connection will emerge to indicate that you have successfully created a controlled-NOT operation. For example, if we choose the bottom bit as the control and the top bit as the target, we obtain the following result:
Remembering that the bottom (!) bit is the first bit and the top bit is the second bit, we see that this corresponds to the operation. Here is a more complicated example, where we first apply and then :
Homework 3.2 ( from s ).
Problem: It is almost midnight but Bob is still tinkering with his prototype probabilistic bit computer that he wants to present at school the next day. He is so preoccupied with calibrating the randomness generator that he forgot to feed his parrot Ziggy. To attract Bob’s attention, Ziggy knocks off Bob’s coffee cup and spills the coffee all over his custom-made keyboard for activating different operations. Bob is horrified since the SWAP key is no longer working! Luckily, the CNOT key still works. Question: How can Bob implement the operation using only controlled-NOT operations? (If you want to prove that two operations are the same, you only have to show this for the basis states because of extension by linearity.)
Hint: You should use three CNOT operations.
Hack.
This can be done by three controlled-NOT operations, namely:
We can check that this works by checking that indeed these ’s send to , for all :
where we used the fact that , for any , see Eq. 3.21. This construction is actually very similar to the XOR swap algorithm that one can run on a classical computer. This is a perfect example where knowing how to program a classical computer can help you develop quantum algorithms!