Gate
What is the Hadamard gate?
The Hadamard gate, written H, is the gate that makes an even split. Given a qubit that is certainly 0, it returns a qubit that reads 0 or 1 with equal chance. Given one that is certainly 1, it also returns an even split, but with a minus sign on one amplitude. Applied twice, it brings you back to the start.
It is the most used gate in quantum computing, and it is the first one most people learn.
The rule
Write the qubit as (a, b). H makes the new amplitude for 0 from the sum a + b, and the new amplitude for 1 from the difference a − b. It then divides both by √2, about 1.41, so that the squares still add to 1.
| Start | After H | Chances of 0 and 1 |
|---|---|---|
| |0⟩, which is (1, 0) | (0.71, 0.71), called |+⟩ | ½ and ½ |
| |1⟩, which is (0, 1) | (0.71, −0.71), called |−⟩ | ½ and ½ |
| |+⟩ | (1, 0), which is |0⟩ | 1 and 0 |
| |−⟩ | (0, 1), which is |1⟩ | 0 and 1 |
Each 0.71 is short for 1 ÷ √2, so the sums come out exact. As a table of numbers, H has rows (1, 1) and (1, −1), all divided by √2. It also equals the X gate plus the Z gate, divided by √2.
Why applying H twice undoes it
Start at |0⟩. After one H the amplitudes are 0.71 and 0.71. Apply H again. The new amplitude for 0 is (0.71 + 0.71) ÷ 1.41 = 1. The new amplitude for 1 is (0.71 − 0.71) ÷ 1.41 = 0. The qubit reads 0 every time.
Two routes lead to a reading of 1, and they arrive with opposite signs, so they cancel. That cancelling is interference, and a coin cannot do it. A coin tossed twice stays random. The note The sign is what cancels does the same sum route by route.
A second worked sum
Take a = 0.6 and b = 0.8, so the chances are 0.36 and 0.64. After H the amplitudes are (0.6 + 0.8) ÷ 1.41 = 0.99 and (0.6 − 0.8) ÷ 1.41 = −0.14. The chances are 0.98 and 0.02. The qubit now reads 0 about 98 times in 100, although it began as a 36 percent chance. H has not randomised it. It has changed which arrangement of the qubit you are reading.
H switches between two ways of reading
The pair |0⟩ and |1⟩ is one way to read a qubit. The pair |+⟩ and |−⟩ is another. H converts between them. If you want to know whether a qubit is |+⟩ or |−⟩, apply H and then read. A |+⟩ gives 0 every time and a |−⟩ gives 1 every time.
This is also why H, then Z, then H acts as X, and why H, then X, then H acts as Z. H swaps the two arrangements, so a sign flip in one looks like a bit flip in the other. On the Bloch sphere, H swaps the top with the right-hand end and the bottom with the left-hand end.
H on many qubits
Put H on each of n qubits that start at 0. All 2 to the power n readings then get the same amplitude, 1 ÷ √(2 to the power n). For two qubits that is 0.5 each, with chance 0.25. For three it is about 0.35, with chance 0.125. For ten it is about 0.03, with chance about 0.001.
That even start is the first step of Grover's search and of many other algorithms. The rest of the circuit then makes the wrong readings cancel and the right ones grow. The even start alone is not the answer. Reading it just gives a random n-bit string.
H and entanglement
H on one qubit, followed by a CNOT, makes a Bell state. From 00, H gives 0.71 on 00 and 0.71 on 10, and CNOT moves the second number to 11. The pair reads 00 or 11, each half the time. See What is quantum entanglement? for the check.
Where to go next
The quantum gates cheat sheet puts H beside the other gates. Quantum gates explained works through each one. Try H yourself on the qubit page.
Questions people ask
What does the Hadamard gate do?
It turns |0⟩ into |+⟩, an even split, and |1⟩ into |−⟩. Its rule is to add and subtract the two amplitudes and divide both by the square root of 2.
What is the matrix for the Hadamard gate?
It is 1 over the square root of 2 times the table with rows (1, 1) and (1, −1). Equivalently it is the X gate plus the Z gate, divided by the square root of 2.
What happens if you apply H twice?
You get back to where you started. H undoes itself because the extra routes to the other outcome cancel.
Why is the Hadamard gate used so much?
It makes even superpositions from plain states, and it switches between the 0 and 1 arrangement and the plus and minus arrangement, so it appears at the start and end of many circuits.
What does H do to many qubits at once?
H on each of n qubits that start at 0 gives all 2 to the power n readings the same amplitude, 1 divided by the square root of 2 to the power n.