|q⟩ Bad Qubits

beginner · Programming · Single-Qubit Gates II: H, S, T & Phase

Hadamard Twice Is Identity

The Hadamard gate HH is special: applying it twice returns every state exactly to where it started. In matrix terms, H2=IH^2 = I, where II is the 2×22 \times 2 identity. This makes HH its own inverse — mathematicians call such an operator Hermitian and unitary at the same time, or equivalently, involutory.

Why HH = I

Recall the Hadamard matrix:

H=12(1111).H = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}.

Multiplying HH by itself:

H2=12(1111)12(1111)=12(11+1111+1(1)11+(1)111+(1)(1))=12(2002)=(1001)=I.H^2 = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} \cdot \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} = \frac{1}{2}\begin{pmatrix} 1\cdot1+1\cdot1 & 1\cdot1+1\cdot(-1) \\ 1\cdot1+(-1)\cdot1 & 1\cdot1+(-1)\cdot(-1) \end{pmatrix} = \frac{1}{2}\begin{pmatrix} 2 & 0 \\ 0 & 2 \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} = I.

So the claim follows directly from the matrix multiplication. On the Bloch sphere you can picture HH as a 180° rotation about the axis halfway between xx and zz. Rotating by 180° and then rotating by 180° again brings every point back to its starting position — that is why two applications cancel.

Trace through an example

Start in 0|0\rangle. After the first Hadamard:

H0=12(0+1)=+.H|0\rangle = \tfrac{1}{\sqrt{2}}\big(|0\rangle + |1\rangle\big) = |+\rangle.

After the second Hadamard, apply HH to each term:

H+=12(H0+H1)=12 ⁣(0+12+012)=12(20)=0.H|+\rangle = \tfrac{1}{\sqrt{2}}\big(H|0\rangle + H|1\rangle\big) = \tfrac{1}{\sqrt{2}}\!\left(\tfrac{|0\rangle+|1\rangle}{\sqrt{2}} + \tfrac{|0\rangle-|1\rangle}{\sqrt{2}}\right) = \tfrac{1}{2}\big(2|0\rangle\big) = |0\rangle.

The 1|1\rangle terms cancel perfectly — this is destructive interference, and it is the same mechanism that powers algorithms like Deutsch–Jozsa.

Try it

Build the two-Hadamard circuit and let the grader verify the full unitary. A circuit that applies HH only once — or applies no gates at all — will fail, because its unitary is not the identity.

Run your code to see the quantum state.

Sign in on the full site to ask questions and join the discussion.