Static site. Every demo computes in your browser, and nothing you type is sent anywhere.
25%
Turn a photon’s polarization, measure it with a polarizer, and watch two paths cancel.
|ψ> = a0|0> + a1|1> photon at θ: a0 = cos θ, a1 = sin θ P(0) = a0² = cos²θ a0² + a1² = 1
A qubit has two amplitudes
A classical bit is either 0 or 1. A qubit uses two reference states, labeled 0 and 1. It can be in a superposition of 0 and 1. The lecture's example is a photon: horizontal polarization is 0, and vertical polarization is 1. A photon polarized at angle θ has a horizontal part cos θ and a vertical part sin θ. These weights are the amplitudes: a0 for |0> and a1 for |1>. In general an amplitude is a complex number, and its squared magnitude gives the probability. On this page the amplitudes are real numbers, so a0² + a1² = 1, and a qubit is a point on the unit circle.
polarization angle θ, in degrees
45
090180270
the state
0.707|0> + 0.707|1>
a0: horizontal part
0.707
a1: vertical part
0.707
P(0) = cos²θ
50.0%
P(1) = sin²θ
50.0%
Try 45 and 315 degrees. Both give 50% and 50%. The states differ only in the sign of a1. The third step shows that this sign changes what happens next.
Angles θ and θ + 180° are the same polarization. Both amplitudes change sign, and no measurement can tell the two apart.
A measurement gives one result
Measuring the qubit returns 0 or 1 at random, with the probabilities above. For a photon, the measurement is an ideal polarizer with a horizontal axis. It either passes or blocks each photon. At angle θ to the axis, the chance of passing (result 0) is cos²θ. A photon that passes is now polarized along the axis. In the same way, after any measurement the qubit is in the state it reported; the amplitudes are gone. One measurement therefore cannot tell you a0 and a1. Only many fresh copies show the probabilities.
Interference: amplitudes can cancel
Waves can add up or cancel: crest plus crest adds, and crest plus trough cancels. Quantum states have amplitudes that can also add up or cancel, because an amplitude can be negative.
The Hadamard gate H turns |0> into an equal superposition, and |1> into the same superposition with a minus sign on |1>. A random coin flip also gives 50% and 50%. Apply each one twice and compare.
a coin flipped twice, starting from heads (0)
Probabilities multiply along a path and add at the end.
0 → 0 → 0: 1/2 x 1/2 = 1/4
0 → 1 → 0: 1/2 x 1/2 = 1/4
0 → 0 → 1: 1/2 x 1/2 = 1/4
0 → 1 → 1: 1/2 x 1/2 = 1/4
P(0) = 1/4 + 1/4 = 1/2 P(1) = 1/2
Still random.
H applied twice, starting from |0>
Amplitudes multiply along a path and add at the end.
|0> → |0> → |0>: +1/2
|0> → |1> → |0>: +1/2
|0> → |0> → |1>: +1/2
|0> → |1> → |1>: −1/2
amplitude of |0> = +1/2 + 1/2 = 1
amplitude of |1> = +1/2 − 1/2 = 0
Always 0.
The two paths to |1> have opposite signs, so they cancel. This is interference. Probabilities are never negative, so the coin cannot do this.
apply H to the state from the first step
The state before and after one Hadamard gate, with the probability of measuring 0 in each.
State
P(0)
Before H (45°)
0.707|0> + 0.707|1>
50.0%
After H (0°)
1.000|0> + 0.000|1>
100.0%
Start at 45° (|+>): H gives |0> with certainty.
A quantum algorithm controls interference so measurements reveal useful information. Paths to wrong answers cancel, and paths to the right answer add up before the measurement. Shor's algorithm does this with a period; Grover's does it with a test that marks one answer.
Many qubits: many amplitudes, few bits out
Two qubits have four outcomes (00, 01, 10, 11), and the state has an amplitude for each. n qubits carry amplitudes for all 2^n outcomes at once. A measurement still returns only n bits. A classical computer that simulates them must store every amplitude. Move the slider.
number of qubits n
3
13060
amplitudes, 2^n
8
memory to simulate
128 bytes
bits one measurement returns
3
outcomes
2^3
Memory assumes 16 bytes per amplitude (two 64-bit numbers, because real quantum states use complex amplitudes). The 2^3 amplitudes are more than the 3 bits a measurement gives back. A quantum computer is not a machine that reads out every answer at once.
Shor's algorithm for a 2048-bit RSA modulus needs thousands of qubits. No classical computer can store that many amplitudes, which is why the attack needs a real quantum computer.