|q⟩ Bad Qubits

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

Rotations RX, RY, RZ

The Bloch sphere is more than a picture — it is a map of every possible single-qubit state, and the rotation gates RXR_X, RYR_Y, RZR_Z are the tools you use to move freely across its surface.

The rotation matrices

Each rotation gate is parameterized by an angle θ\theta and rotates the Bloch vector by that angle around the named axis. Their matrices are exponentials of the Pauli operators:

RX(θ)=eiθX/2=cos ⁣θ2Iisin ⁣θ2X=(cosθ2isinθ2isinθ2cosθ2),R_X(\theta) = e^{-i\theta X/2} = \cos\!\tfrac{\theta}{2}\,I - i\sin\!\tfrac{\theta}{2}\,X = \begin{pmatrix} \cos\tfrac{\theta}{2} & -i\sin\tfrac{\theta}{2} \\ -i\sin\tfrac{\theta}{2} & \cos\tfrac{\theta}{2} \end{pmatrix}, RY(θ)=eiθY/2=cos ⁣θ2Iisin ⁣θ2Y=(cosθ2sinθ2sinθ2cosθ2),R_Y(\theta) = e^{-i\theta Y/2} = \cos\!\tfrac{\theta}{2}\,I - i\sin\!\tfrac{\theta}{2}\,Y = \begin{pmatrix} \cos\tfrac{\theta}{2} & -\sin\tfrac{\theta}{2} \\ \sin\tfrac{\theta}{2} & \cos\tfrac{\theta}{2} \end{pmatrix}, RZ(θ)=eiθZ/2=cos ⁣θ2Iisin ⁣θ2Z=(eiθ/200eiθ/2).R_Z(\theta) = e^{-i\theta Z/2} = \cos\!\tfrac{\theta}{2}\,I - i\sin\!\tfrac{\theta}{2}\,Z = \begin{pmatrix} e^{-i\theta/2} & 0 \\ 0 & e^{i\theta/2} \end{pmatrix}.

All three have the same pattern: rotating by θ=2π\theta = 2\pi returns the original state up to a global phase of 1-1 (unobservable), and rotating by θ=π\theta = \pi implements a Pauli gate up to global phase (e.g. RX(π)=iXR_X(\pi) = -iX).

A concrete example: RY(π/2) on |0⟩

Apply RY(π/2)R_Y(\pi/2) to 0=(10)|0\rangle = \binom{1}{0}:

RY ⁣(π2)0=(cosπ4sinπ4sinπ4cosπ4)(10)=12(11)=0+12=+.R_Y\!\left(\tfrac{\pi}{2}\right)|0\rangle = \begin{pmatrix} \cos\tfrac{\pi}{4} & -\sin\tfrac{\pi}{4} \\ \sin\tfrac{\pi}{4} & \cos\tfrac{\pi}{4} \end{pmatrix} \binom{1}{0} = \frac{1}{\sqrt{2}}\binom{1}{1} = \frac{|0\rangle + |1\rangle}{\sqrt{2}} = |+\rangle.

This is precisely the same state as H0H|0\rangle — no surprise, because HH is itself a rotation by π\pi around the diagonal X+ZX{+}Z axis.

How RX and RZ behave

RX(θ)R_X(\theta) rotates around the xx-axis. Starting from 0|0\rangle (north pole) it sweeps toward 1|1\rangle through a path that picks up imaginary components: at θ=π\theta = \pi you get i1-i|1\rangle, and at θ=π/2\theta = \pi/2 the qubit lands on the equator at the y-y pole of the Bloch sphere — the state is 12(0i1)\tfrac{1}{\sqrt{2}}(|0\rangle - i|1\rangle), which has a factor of i-i on the 1|1\rangle amplitude.

RZ(θ)R_Z(\theta) rotates around the zz-axis. Because 0|0\rangle sits on the north pole of the zz-axis, RZ(θ)0=eiθ/20R_Z(\theta)|0\rangle = e^{-i\theta/2}|0\rangle — a global phase only. The state +=12(0+1)|+\rangle = \tfrac{1}{\sqrt{2}}(|0\rangle+|1\rangle), however, is on the equator, so RZR_Z moves it visibly: RZ(θ)+=12(eiθ/20+eiθ/21)R_Z(\theta)|+\rangle = \tfrac{1}{\sqrt{2}}(e^{-i\theta/2}|0\rangle + e^{i\theta/2}|1\rangle).

Together RXR_X, RYR_Y, and RZR_Z (or any two of them plus a phase gate) are sufficient to express every single-qubit unitary — they form a universal single-qubit gate set.

Try it

Apply RY(π/2)R_Y(\pi/2) to qubit 0. After running, inspect the statevector: the two amplitudes should both be 0.707=12\approx 0.707 = \tfrac{1}{\sqrt{2}} (no imaginary parts).

Run your code to see the quantum state.

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