The Hadamard Gate
The Hadamard gate creates equal superpositions and switches between the computational and diagonal bases; it is central to nearly every algorithm.
The superposition maker
The Hadamard gate H is the single most used single-qubit gate. It maps the computational basis to equal superpositions and back, making it the standard way to put qubits into and out of superposition.
Hadamard (times 1/sqrt2)
Its action
- H|0> = (|0> + |1>)/sqrt(2) = |+>
- H|1> = (|0> - |1>)/sqrt(2) = |->
- H|+> = |0> and H|-> = |1>
H is its own inverse: applying it twice returns the original state, because H^2 = I. This self-inverse property is a clean demonstration of interference — the second application makes unwanted amplitude paths cancel.
Basis change
H swaps the computational (Z) basis and the diagonal (X) basis. Sandwiching a Z-basis measurement between Hadamards effectively measures in the X basis. This is how algorithms read out relative phase information that is invisible in the computational basis.
Building superposition over many inputs
Applying H to each of n qubits in |0> produces an equal superposition of all 2^n computational basis states — the standard opening move of algorithms that rely on quantum parallelism. From there, structured gates and interference shape the amplitudes toward the answer.
python
import numpy as np
H = np.array([[1,1],[1,-1]])/np.sqrt(2)
print(np.round(H@np.array([1,0]),3)) # |+> = [0.707 0.707]
Hn = H
for _ in range(2): Hn = np.kron(Hn, H) # H on 3 qubits
print(np.round((Hn@np.eye(8)[:,0]),3)) # equal superposition of 8 states