Quantum

Gates

Every gate is a rotation — and rotations stack.

The first time someone hands you a list of quantum gates — X, Y, Z, H, S, T, plus the rotation families Rx, Ry, Rz — it looks like a grab-bag. There are so many. Each one comes with a different matrix, a different effect, and a different name pulled from a different decade of physics history. It's tempting to just memorize the matrices and move on.

Don't. There is exactly one thing a single-qubit gate does: it rotates the Bloch sphere. That's it. Every named gate you'll ever meet is a particular rotation — either a fixed one (X, Y, Z, H, S, T) or a knob you can dial (Rx, Ry, Rz). Once that picture sticks, the grab-bag stops being a grab-bag.

On this page, we're going to use the Bloch sphere as the geometric anchor and watch every claim with our own eyes. Reach for the buttons, grab the sliders, drag the arrow. Everything here is driven by the same simulator that's running on every other essay in this site.

The discrete gates, geometrically

Start with |0⟩ — the arrow at the north pole. Press X. The arrow flips to the south pole: |1⟩. Press X again — back to the north. X is a half-turn (180°) about the horizontal X axis. Press Y from |0⟩: same endpoint as X, but the rotation axis is different. Press Z from |0⟩: nothing visible happens, because |0⟩ sits exactly on the Z axis and a rotation about an axis leaves points on that axis alone.

The Bloch sphere — your geometric scoreboard. Every gate below moves this arrow.

Try dragging the arrow tip. Apply a gate above and watch the arrow rotate.

Try this: reset, press H. The arrow lands on the equator pointing along +X. The Hadamard isn't a 180° flip about a single coordinate axis — it's a 180° flip about the diagonal axis halfway between X and Z. That's why it sends |0⟩ (north pole) and |+⟩ (equator, +X direction) into each other: they're swapped across that diagonal.

Try this: reset, drag the arrow to anywhere on the equator, then press Z. The arrow spins 180° around the vertical axis. Z doesn't change which pole you're closer to — that's why it leaves measurement probabilities in the computational basis untouched — but it absolutely is a rotation, and the equatorial states feel it.

Continuous rotations: the knobs underneath

The discrete gates are convenient names for a few useful angles. The rotation gates let you dial the angle yourself. Rx(θ) is a rotation by θ radians about the X axis of the Bloch sphere; Ry(θ) and Rz(θ) are the same idea for Y and Z. Sweep a slider and watch the arrow trace a smooth arc.

Two important things about these sliders, because they're going to drive the next section. First: they're keyboard-friendly — focus a slider and arrow keys nudge by one step (Page Up / Page Down jumps in larger increments). Second: each slider snapshots the state when you grab it, then restores that snapshot and re-applies the rotation on every input. Sweeping a slider back to 0 always returns you to the state you started from. Sliders don't compound.

That last fact matters: it means you can compare “press discrete gate X” against “sweep Ry to π” from the same starting point without one polluting the other. Which is exactly what we're about to do.

X equals Ry(π). Mostly.

Here is the punchline of the whole essay. The discrete X gate and the continuous Ry(π) rotation produce the same final state when applied to |0⟩. They differ only by a global phase — a unit complex scalar in front of the whole state vector — which is physically undetectable. Watch:

Try this (part 1): press Reset on the gate buttons. The arrow returns to the north pole. Now press X. The arrow flips to the south pole — you're at |1⟩.

Try this (part 2): press Reset again. Then grab the Ry(θ) slider and sweep it all the way to θ = π (about 3.142 rad — halfway across the track). The arrow swings smoothly down to the south pole. Same destination. Same state, give or take an invisible phase factor.

Now sweep Ry back to 0. The arrow returns to the north pole (because of the snapshot semantics we just discussed). The Ry slider didn't “commit” anything; it just let you dial through a one-parameter family of rotations and look at the result.

This is the bridge: every named discrete gate is a member of some continuous family. X = Rx(π) up to phase. Y = Ry(π) up to phase. Z = Rz(π) up to phase. The phase factor is what the formal definition picks up from the half-angle in the exponent — see the math-nerds box below — but you'll never measure it.

Stacking rotations

Once you accept that every gate is a rotation, an old theorem from 19th-century geometry takes over: any rotation in three dimensions can be written as three rotations about coordinate axes (Euler angles). For us that means every single-qubit gate — every 2×2 unitary, no matter how exotic — is a product of at most three rotations from the Rx/Ry/Rz families. Mathematica's collection of named gates is just a set of conveniently named recipes.

Try this: sweep Rx partway, release it (the rotation stays applied because we restored from the snapshot at that angle). Then grab Ry and sweep it. The second rotation snapshots the state you just made with Rx and rotates that. Stacking is exactly composition.

Want to keep stacking past two rotations, with the full sandbox composer? The button below opens the Quantum Sandbox loaded with a 1-qubit, two-step circuit: Rx(π/3) followed by Ry(π/4). Add a third step, a fourth, swap an axis, insert a discrete gate between them. The simulator answers in real time.

Open in sandbox — stack your own rotations →

Self-test

  1. Using only the sliders above, find an angle θ for Rx(θ) that takes |0⟩ to an equal-superposition state (50/50 along the equator in the Y direction). What value of θ is that, and why isn't it π?
  2. Rz(θ) applied to |0⟩ never moves the arrow off the north pole — sweep the Rz slider and confirm. Why? (Hint: rotation about an axis fixes points on that axis.) Then press H first and sweep Rz again. What changes?
The matrices, the half-angle, and Euler decomposition

A single-qubit gate is a unitary 2×2 matrix — an element of the unitary group U(2)U(2). Two unitaries that differ only by a unit complex scalar (eiϕe^{i\phi}) act identically on every measurable quantity, so we usually quotient by that global phase and work inside the special unitary group SU(2)SU(2) (determinant 1).

The three rotation generators are the Pauli matrices:

X=[0110],Y=[0ii0],Z=[1001]X = \begin{bmatrix}0 & 1\\1 & 0\end{bmatrix},\quad Y = \begin{bmatrix}0 & -i\\i & 0\end{bmatrix},\quad Z = \begin{bmatrix}1 & 0\\0 & -1\end{bmatrix}

and the continuous families exponentiate them:

Rx(θ)=eiθX/2=cos(θ/2)Iisin(θ/2)XR_x(\theta) = e^{-i\theta X / 2} = \cos(\theta/2)\, I - i \sin(\theta/2)\, X
Ry(θ)=cos(θ/2)Iisin(θ/2)YR_y(\theta) = \cos(\theta/2)\, I - i \sin(\theta/2)\, Y
Rz(θ)=cos(θ/2)Iisin(θ/2)ZR_z(\theta) = \cos(\theta/2)\, I - i \sin(\theta/2)\, Z

Notice the θ/2. It's the headline weirdness of this whole subject: a 360° rotation on the Bloch sphere (θ=2π\theta = 2\pi) returns R to I-I, not +I+I. You need θ=4π\theta = 4\pi for the identity. The reason: SU(2) is a double cover of the rotation group SO(3) — there are two distinct SU(2) elements sitting above every physical rotation of the sphere.

Plugging θ=π\theta = \pi into RyR_y:

Ry(π)=cos(π/2)Iisin(π/2)Y=iYR_y(\pi) = \cos(\pi/2)\, I - i \sin(\pi/2)\, Y = -i Y

so Ry(π)R_y(\pi) equals YY up to a global phase of i-i. The same trick gives Rx(π)=iXR_x(\pi) = -i X and Rz(π)=iZR_z(\pi) = -i Z. Up to phase, the named discrete gates are π-rotations of their corresponding continuous family — which is what the walkthrough above let you see.

The Euler decomposition theorem says it all in one line:

Every USU(2)=Rz(α)Ry(β)Rz(γ)\text{Every } U \in SU(2) = R_z(\alpha)\, R_y(\beta)\, R_z(\gamma)

for some triple (α,β,γ)(\alpha, \beta, \gamma). So the discrete gate zoo (H, S, T, and friends) is pedagogically useful but mathematically redundant: every single one is a fixed product of three rotations you've already met.