|q⟩ Bad Qubits

beginner · Programming · Rotation Gates & Universal Single-Qubit Ops

Building H from Rotations

The Hadamard gate HH looks like a special object in most introductions, defined by its matrix and left at that. But it is also a perfectly ordinary rotation — one that can be expressed as a short sequence of RYR_Y and RZR_Z gates. Understanding this connection deepens your intuition for the Bloch sphere and is the first step toward decomposing arbitrary single-qubit unitaries.

H as a Bloch-sphere rotation

On the Bloch sphere every single-qubit gate is a rotation. The Hadamard gate corresponds to a rotation by π\pi around the axis n^=12(x^+z^)\hat{n} = \tfrac{1}{\sqrt{2}}(\hat{x} + \hat{z}), the diagonal between the xx- and zz-axes. Applying it once maps north pole to equator and back, which is why H2=IH^2 = I.

Decomposing H into RY and RZ

Any rotation around a tilted axis can be decomposed into a sequence of axis-aligned rotations. One compact decomposition of HH is:

H=eiϕRY ⁣(π2)RZ(π),H = e^{i\phi}\, R_Y\!\left(\tfrac{\pi}{2}\right)\, R_Z(\pi),

where eiϕe^{i\phi} is an unobservable global phase.

We can verify this by multiplying the matrices. The two rotation matrices are

RY ⁣(π2)=(cosπ4sinπ4sinπ4cosπ4)=12(1111),RZ(π)=(eiπ/200eiπ/2)=(i00i).R_Y\!\left(\tfrac{\pi}{2}\right) = \begin{pmatrix} \cos\tfrac{\pi}{4} & -\sin\tfrac{\pi}{4} \\[4pt] \sin\tfrac{\pi}{4} & \cos\tfrac{\pi}{4} \end{pmatrix} = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & -1 \\ 1 & 1 \end{pmatrix}, \qquad R_Z(\pi) = \begin{pmatrix} e^{-i\pi/2} & 0 \\ 0 & e^{i\pi/2} \end{pmatrix} = \begin{pmatrix} -i & 0 \\ 0 & i \end{pmatrix}.

Their product (applied right-to-left, RZR_Z first then RYR_Y) is

RY ⁣(π2)RZ(π)=12(1111)(i00i)=12(iiii)=i2(1111)=iH.R_Y\!\left(\tfrac{\pi}{2}\right) R_Z(\pi) = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & -1 \\ 1 & 1 \end{pmatrix} \begin{pmatrix} -i & 0 \\ 0 & i \end{pmatrix} = \frac{1}{\sqrt{2}}\begin{pmatrix} -i & -i \\ -i & i \end{pmatrix} = \frac{-i}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} = -i\,H.

The scalar factor i-i is a global phase — it has no effect on any measurement outcome or on the action of the gate as a unitary operation. Up to that phase, the two-gate sequence is exactly HH.

Why this matters

No real quantum processor ships a native Hadamard gate; hardware exposes a small set of rotation primitives. Compilers translate higher-level gates — including HH — into sequences of native rotations. The decomposition above is exactly the kind of identity a quantum compiler uses when targeting a backend whose native single-qubit gate is, say, RZR_Z and RYR_Y (or RZR_Z and X\sqrt{X}).

Try it

Implement HH using only rotation gates. The grader checks the full unitary matrix up to global phase — doing nothing will fail because the identity differs from HH.

Run your code to see the quantum state.

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