Interference and Deutsch's algorithm
Deutsch’s algorithm solves a problem nobody needs solved. It is worth learning anyway, because it is the smallest complete example of how a quantum algorithm gets its answer, and the same two ideas reappear in Shor’s and Grover’s algorithms.
It assumes you know the material in the Quantum Information track up to entanglement.
The problem
Section titled “The problem”Someone gives you a function that takes one bit and returns one bit. There are only four such functions:
| Kind | |||
|---|---|---|---|
| always 0 | 0 | 0 | constant |
| always 1 | 1 | 1 | constant |
| identity | 0 | 1 | balanced |
| negation | 1 | 0 | balanced |
You cannot see inside . You can only call it. The question is: is constant or balanced?
Classically you must call it twice. One value, say , is consistent with both a constant function and a balanced one. We count the cost of an algorithm here by the number of calls, or queries, it makes.
A quantum computer can answer with one query.
Functions as gates
Section titled “Functions as gates”Gates must be reversible, and a constant function is not, so we cannot use as a gate directly. The standard fix is a two-qubit gate that keeps the input and writes the output onto a second qubit:
where is addition modulo 2. This gate is called an oracle. For the identity function , the oracle flips the second qubit exactly when the first is 1. That is CNOT.
Phase kickback
Section titled “Phase kickback”Here is the first idea. Put the second qubit in the state before calling the oracle.
If , the second qubit is untouched. If , it is flipped, and flipping gives . Either way:
The second qubit ends as it began. The value of has turned into a sign on the first qubit’s state. This is called phase kickback.
For a single basis state that sign is a global phase and means nothing. For a superposition of and it becomes a relative phase, and a relative phase can be measured.
The top qubit starts in and the bottom in . Make the state , which written out is .
This puzzle needs JavaScript.
Hint
First make with one on each wire. Then apply the oracle for , which is CNOT.
Look at what the CNOT did. It was controlled by the top qubit, yet the bottom qubit did not change and the top one went from to . Which qubit is “the control” depends on the basis you look in.
The algorithm
Section titled “The algorithm”Now the second idea: interference. Start the first qubit in , so the oracle is queried on both inputs in superposition. After kickback the first qubit is in
- If is constant, the two signs are equal and this is .
- If is balanced, the two signs differ and this is .
A final turns into and into . Measure the first qubit: 0 means constant, 1 means balanced. The oracle was called once.
The Oracle gate is for : a CNOT from the top wire to the bottom wire, which you cannot turn around. Using it and , leave the top qubit in with certainty, showing that is balanced. The target is .
This puzzle needs JavaScript.
Try the constant functions in this sandbox. Build the same circuit, but replace the oracle: for the oracle does nothing, and for it is an on the bottom wire. The top qubit should come out as 0 both times.
Press Measure ×100 to see the outcome statistics for your circuit.
This puzzle needs JavaScript.
What actually happened
Section titled “What actually happened”It is tempting to say the quantum computer “evaluated on both inputs at once”. That is misleading. If you measured straight after the oracle you would learn about one input at most, the same as classically.
What the algorithm does is narrower and cleverer. It never learns or . It arranges for the amplitudes to interfere so that a joint property of the two values, whether they are equal, lands in a place where one measurement can read it.
After running Deutsch’s algorithm once, what do you know about ?
One measured bit cannot hold two bits of information. The algorithm trades knowledge of the individual values for knowledge of a global property.
This is the pattern for quantum algorithms generally. Prepare a superposition, let the problem imprint phases on it, then interfere the paths so that wrong answers cancel. Saving one query out of two is a small win. The next lesson scales the same circuit to qubits, where the saving over any classical algorithm that must be certain of its answer becomes exponential.
Remember it
Section titled “Remember it”What does Deutsch's algorithm decide, and with how many queries?
Whether is constant or balanced, with one query. Classically it takes two.
What is phase kickback?
With the target in , the oracle leaves the target alone and puts a phase on the query qubit: .
In Deutsch's algorithm, what does measuring 1 on the first qubit mean?
The function is balanced. Measuring 0 means it is constant.
Quantum algorithms do not work by "trying every answer at once". What do they rely on instead?
Interference: amplitudes for wrong answers cancel and amplitudes for right answers add.