Interference makes wrong answers cancel out
Interference is what happens when two routes to the same outcome add up or cancel out. In a quantum program it is the main tool: gates are arranged so the wrong answers cancel and the right one is left.
It matters because it is the real reason a quantum algorithm can work at all. In this lesson you make an answer vanish with a sign, then check it in the lab.
By the end of this lesson
Note
I can show how gates make wrong answers cancel.
Key words
| Word | What it means | Example |
|---|---|---|
| Interference | two routes to one outcome adding up or cancelling | |
| Circuit | a list of gates applied one after another | H, Z, H |
| Sign | whether an amplitude is positive or negative | |
| Reinforce | to add up so the amplitude grows | |
| Cancel | to add up to zero | |
| Amplitude | a number whose square is a chance |
The cells students fill in are left blank in this preview.
Two routes to one outcome can cancel
An amplitude can be positive or negative. When a gate gives an outcome two routes, the amplitudes from the routes are added together.
Two positive amplitudes reinforce. A positive and a negative of the same size cancel. You add the amplitudes first and square afterwards. You never add chances.
Worked example: two circuits side by side
| Step | H, H | H, Z, H |
|---|---|---|
| Start | [1, 0] | [1, 0] |
| After the first H | [0.707, 0.707] | [0.707, 0.707] |
| After Z | not used | [0.707, -0.707] |
| After the last H | [1, 0] | [0, 1] |
| What you read | certainly 0 | certainly 1 |
The cells students fill in are left blank in this preview.
Why the answer 1 vanishes in H, H
In H, H the last H sends an outcome of 1 along two routes. One has 0.707 times 0.707, which is +0.5. The other has 0.707 times -0.707, which is -0.5.
They add to zero, so 1 never appears. In H, Z, H the sign in the middle swaps which outcome cancels.
Run the interference script
docker exec jupyter python3 steps/interfere.pyShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
A hidden sign still changes the result
Before the last H, the states [0.6, 0.8] and [0.6, -0.8] have the same chances. A measurement could not tell them apart.
After the last H they differ a lot. The sign decides which of the two routes reinforce and which cancel. That is why Z, which looks like it does nothing, is useful.
Worked example: the same chances, different results
| State before H | Chance of 0 before | Chance of 0 after | Chance of 1 after |
|---|---|---|---|
| [0.6, 0.8] | 0.36 | 0.98 | 0.02 |
| [0.6, -0.8] | 0.36 | 0.02 | 0.98 |
The cells students fill in are left blank in this preview.
H on [0.6, 0.8]
docker exec jupyter python3 -c "from qsim import *; print(probabilities(apply(H, np.array([0.6, 0.8], dtype=complex), 0)).round(3))"Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
H on [0.6, -0.8]
docker exec jupyter python3 -c "from qsim import *; print(probabilities(apply(H, np.array([0.6, -0.8], dtype=complex), 0)).round(3))"Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
A common mistake
Warning
Many people think two routes to an outcome can only make it more likely. That is true of chances, but amplitudes can be negative. Two routes can cancel, and then the outcome never appears. Add the amplitudes first, and square only the total.
Run a circuit in plain Python
R = 0.5 ** 0.5
H = [[R, R], [R, -R]]
Z = [[1, 0], [0, -1]]
def apply_gate(gate, state):
result = []
for row in gate:
total = 0
for i in range(len(state)):
total = total + row[i] * state[i]
result.append(total)
return result
state = [1, 0]
for gate in [H, Z, H]:
state = apply_gate(gate, state)
# A tiny error in the last digits is normal. Treat it as rounding.
print(state)
# Now delete Z from the list and run it again.