|q⟩ Bad Qubits

beginner · Programming · The Bloch Sphere

Hadamard as a Rotation

Every single-qubit gate is a rotation of the Bloch sphere. The Pauli gates XX, YY, and ZZ rotate 180° about the xx-, yy-, and zz-axes respectively. The Hadamard gate HH fits the same pattern — but its rotation axis is the diagonal direction halfway between +x+x and +z+z.

The rotation axis

The normalised axis is n^=12(1,0,1)\hat{n} = \frac{1}{\sqrt{2}}(1, 0, 1), pointing equally along +x+x and +z+z. A rotation by angle θ\theta about n^\hat{n} is described by

Rn^(θ)=cos ⁣θ2Iisin ⁣θ2(n^σ),R_{\hat{n}}(\theta) = \cos\!\frac{\theta}{2}\, I - i\sin\!\frac{\theta}{2}\,(\hat{n} \cdot \vec{\sigma}),

where σ=(X,Y,Z)\vec{\sigma} = (X, Y, Z) is the vector of Pauli matrices. For HH, the angle is θ=π\theta = \pi (180°), so cos(π/2)=0\cos(\pi/2) = 0 and sin(π/2)=1\sin(\pi/2) = 1, which gives

H=i(n^σ)=iX+Z2=i12(1111).H = -i\,(\hat{n} \cdot \vec{\sigma}) = -i \cdot \frac{X + Z}{\sqrt{2}} = -i \cdot \frac{1}{\sqrt{2}}\begin{pmatrix}1 & 1 \\ 1 & -1\end{pmatrix}.

The prefactor i-i is a global phase and has no observable effect, so we conventionally write

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

What the rotation does geometrically

Because HH rotates 180° about the axis n^\hat{n}, it swaps any two points that are mirror images of each other across n^\hat{n}. In particular:

This explains a key identity: applying HH twice returns every state to itself (H2=IH^2 = I), because two 180° rotations about the same axis cancel.

The Z–X basis swap

One elegant consequence of the Hadamard rotation axis is that HH exchanges the ZZ eigenstates with the XX eigenstates:

H0=+,H1=,H+=0,H=1.H|0\rangle = |{+}\rangle, \quad H|1\rangle = |{-}\rangle, \quad H|{+}\rangle = |0\rangle, \quad H|{-}\rangle = |1\rangle.

Conjugation by HH therefore converts a ZZ measurement into an XX measurement and vice versa. This is not coincidence — it follows directly from the rotation axis being exactly midway between the two axes, so the 180° rotation swaps them.

Try it

Implement the Hadamard gate. The grader compares the full unitary matrix, so an empty circuit will not pass — you must place the correct rotation.

Run your code to see the quantum state.

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