|q⟩ Bad Qubits

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

Any Single-Qubit Unitary

Every 2×22\times 2 unitary matrix with determinant +1+1 belongs to the group SU(2)SU(2), and a fundamental theorem of linear algebra tells us that every such matrix can be written as a product of three rotations. This is the Euler angle decomposition, and it means the three rotation gates RXR_X, RYR_Y, and RZR_Z you have already met are, collectively, enough to build any single-qubit gate.

The ZYZ decomposition

One standard form writes an arbitrary single-qubit unitary as

U=eiαRZ(β)RY(γ)RZ(δ),U = e^{i\alpha}\,R_Z(\beta)\,R_Y(\gamma)\,R_Z(\delta),

where α\alpha, β\beta, γ\gamma, and δ\delta are real angles. The overall factor eiαe^{i\alpha} is a global phase — physically unobservable and irrelevant to any measurement outcome or gate comparison. Stripping it away, every single-qubit gate is a ZYZ rotation sequence with three free parameters.

Finding the angles

Given a target unitary U=(abcd)U = \begin{pmatrix} a & b \\ c & d \end{pmatrix}, the decomposition angles can be read off from the matrix entries. For the Hadamard gate

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

the ZYZ angles work out to β=0\beta = 0, γ=π/2\gamma = \pi/2, δ=π\delta = \pi:

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

Since RZ(0)=IR_Z(0) = I (the identity), the effective sequence is just RY(π/2)RZ(π)R_Y(\pi/2)\,R_Z(\pi). You can verify this by multiplying the two 2×22\times 2 matrices and comparing with HH up to the global phase eiπ/2=ie^{-i\pi/2} = -i. This confirms that HH is not a "magic" primitive — it is simply a particular rotation sequence.

Why this matters

Quantum hardware exposes a fixed native gate set. A compiler must translate every gate in your circuit into sequences of native operations. The Euler decomposition is the engine that powers single-qubit compilation: given any unitary your algorithm needs, the compiler solves for the three angles and emits the corresponding rotation sequence. Understanding the decomposition helps you reason about gate counts and recognize when two circuits are equivalent.

Try it

Implement the Hadamard gate using only RZR_Z and RYR_Y — no c.h() allowed. Use the ZYZ decomposition: δ=π\delta = \pi and γ=π/2\gamma = \pi/2 (the β=0\beta = 0 term is the identity and can be omitted). The grader checks the entire unitary matrix up to global phase, so an empty circuit will not pass.

Run your code to see the quantum state.

After running, the Bloch sphere view should show the same action as a Hadamard: the north pole 0|0\rangle maps to the +|+\rangle state on the equator, confirming the decomposition is correct.

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