The Hadamard gate

The Hadamard gate, H, makes equal superpositions. It turns ∣0⟩|{0}\rangle into ∣+⟩|{+}\rangle and ∣1⟩|{1}\rangle into ∣−⟩|{-}\rangle, and back again. Most quantum algorithms start with it, and it's the gate that switches between the z and x bases.

On the Bloch sphere, H turns the whole sphere 180° about the x+z diagonal.

A Bloch sphere: H turns the arrow 180° about the x+z diagonal, from where it starts (dashed) along the arc to where it ends.H axis|0⟩|1⟩|+⟩|−⟩|+i⟩|−i⟩
H turns ∣0⟩|{0}\rangle half a turn about the diagonal halfway between x and z, landing on ∣+⟩|{+}\rangle.

The matrix

H=[121212−12]H = {\def\arraystretch{1.5}\begin{bmatrix} \tfrac{1}{\sqrt{2}} & \tfrac{1}{\sqrt{2}} \\ \tfrac{1}{\sqrt{2}} & -\tfrac{1}{\sqrt{2}} \end{bmatrix}}

Column 0 is ∣+⟩|{+}\rangle and column 1 is ∣−⟩|{-}\rangle. On any state, H adds and subtracts the amplitudes:

H (α∣0⟩+β∣1⟩)=α+β2 ∣0⟩+α−β2 ∣1⟩H\,(\alpha|0\rangle + \beta|1\rangle) = \tfrac{\alpha + \beta}{\sqrt{2}}\,|0\rangle + \tfrac{\alpha - \beta}{\sqrt{2}}\,|1\rangle

As a rotation

H=i Rn^(180∘),n^=12(1,0,1)H = i\,R_{\hat n}(180^\circ), \quad \hat n = \tfrac{1}{\sqrt{2}}(1, 0, 1)

The factor ii in front is a global phase: it changes the matrix but not what any measurement sees, so H and Rn^(180∘)R_{\hat n}(180^\circ) turn the sphere the same way. See rotation gates.

What it does to the six key states

BeforeAfter HOn the sphere
∣0⟩|{0}\rangle∣+⟩|{+}\rangle+z → +x
∣1⟩|{1}\rangle∣−⟩|{-}\rangle−z → −x
∣+⟩|{+}\rangle∣0⟩|{0}\rangle+x → +z
∣−⟩|{-}\rangle∣1⟩|{1}\rangle−x → −z
∣+i⟩|{+i}\rangleeiπ/4∣−i⟩e^{i\pi/4}|{-i}\rangle+y → −y
∣−i⟩|{-i}\ranglee−iπ/4∣+i⟩e^{-i\pi/4}|{+i}\rangle−y → +y

A factor in front of a result, such as a minus sign or ii, is a global phase: the arrow lands on the named state all the same.

Switching bases

A half turn about the x–z diagonal swaps the x and z axes, and flips y. So H swaps ∣0⟩|{0}\rangle with ∣+⟩|{+}\rangle and ∣1⟩|{1}\rangle with ∣−⟩|{-}\rangle, and swaps ∣+i⟩|{+i}\rangle with ∣−i⟩|{-i}\rangle. That makes it a translator between the z basis and the x basis:

H Z H=X,H X H=ZH\,Z\,H = X, \qquad H\,X\,H = Z

Putting a gate between two Hadamards turns its axis: Z's axis, turned by H, becomes X's. It's also how hardware that only measures along z can measure along x: apply H first.

Try it

See also: Pauli-Z · The six key states · All gates