Gates are rotations

A quantum gate changes a qubit's state. For a single qubit, every gate does the same kind of thing to the Bloch sphere: it turns the whole sphere about an axis, by an angle. Learn a gate's axis and angle, and you know what it does to every state.

The turn is rigid, like turning a globe: every point moves together, the arrow with it, and points on the axis stay where they are.

A Bloch sphere: S turns the arrow 90° about z, from where it starts (dashed) along the arc to where it ends.|0⟩|1⟩|+⟩|−⟩|+i⟩|−i⟩
S turns the sphere 90° about z. Seen from above, the turn is counterclockwise, so ∣+⟩|{+}\rangle goes to ∣+i⟩|{+i}\rangle.

Gates are matrices

In the math, a gate is a 2×2 matrix UU of complex numbers, and applying it multiplies the state's column vector:

U[αβ]=[u00u01u10u11][αβ]=[u00 α+u01 βu10 α+u11 β]U\begin{bmatrix} \alpha \\ \beta \end{bmatrix} = \begin{bmatrix} u_{00} & u_{01} \\ u_{10} & u_{11} \end{bmatrix} \begin{bmatrix} \alpha \\ \beta \end{bmatrix} = \begin{bmatrix} u_{00}\,\alpha + u_{01}\,\beta \\ u_{10}\,\alpha + u_{11}\,\beta \end{bmatrix}

A handy way to read a matrix: column j is where ∣j⟩|j\rangle goes. The first column is U∣0⟩U|0\rangle, the second U∣1⟩U|1\rangle.

Gate matrices are unitary: they keep the total probability at 1, so the arrow stays on the sphere. That's exactly why each one is a rotation.

Every gate is a rotation

The gates on the app's gate bar, and the turn each one makes:

GateNameTurns the sphere
XXPauli-X180° about x
YYPauli-Y180° about y
ZZPauli-Z180° about z
HHHadamard180° about the x+z diagonal
SSS gate90° about z
TTT gate45° about z
S†S^\daggerS-dagger90° about −z
T†T^\daggerT-dagger45° about −z
Rx(θ), Ry(θ), Rz(θ)R_x(\theta),\ R_y(\theta),\ R_z(\theta)Rotation gatesθ about x, y or z

Angles follow the right-hand rule: point your right thumb along the axis, and your fingers curl the way the sphere turns. Put another way, looking down at the sphere from the axis's tip, the turn is counterclockwise.

The states a gate leaves alone

A gate's axis meets the sphere at two opposite points, and the states there are the ones the gate doesn't move: it can only multiply each of them by a factor, which is a global phase. X leaves ∣+⟩|{+}\rangle and ∣−⟩|{-}\rangle where they are; Z, S and T leave ∣0⟩|{0}\rangle and ∣1⟩|{1}\rangle. Unless a gate does nothing at all, every other state moves.

In matrix language, these two states are the gate's eigenvectors, and their factors are its eigenvalues. The angle between the two factors is the angle of the turn. For S:

S ∣0⟩=1⋅∣0⟩,S ∣1⟩=i ∣1⟩S\,|0\rangle = 1\cdot|0\rangle, \qquad S\,|1\rangle = i\,|1\rangle

The factors 11 and ii are 90° apart, and S is a 90° turn. For X, the factors on ∣+⟩|{+}\rangle and ∣−⟩|{-}\rangle are 11 and −1-1, 180° apart: a half turn.

Different matrices, same rotation

Two matrices that differ only by a factor in front, such as −1-1 or ii, make the same rotation: the factor is a global phase, which no measurement can detect. For example, Pauli-Z and the 180° rotation about z differ by a factor of ii:

Z=[100−1]=i[e−iπ/200eiπ/2]=i Rz(180∘)Z = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix} = i \begin{bmatrix} e^{-i\pi/2} & 0 \\ 0 & e^{i\pi/2} \end{bmatrix} = i\,R_z(180^\circ)

In general, a rotation by θ about the unit axis n^=(nx,ny,nz)\hat n = (n_x, n_y, n_z) is the matrix below, and every one-qubit gate is one of these times a phase eiγe^{i\gamma}:

Rn^(θ)=cos⁡θ2 I−isin⁡θ2 (nxX+nyY+nzZ)R_{\hat n}(\theta) = \cos\tfrac{\theta}{2}\, I - i\sin\tfrac{\theta}{2}\,(n_x X + n_y Y + n_z Z)

Order matters

Two gates in a row are two turns in a row, and turns about different axes don't commute: doing them in the other order usually lands somewhere else. Starting from ∣0⟩|{0}\rangle:

  • H, then S: ∣0⟩|{0}\rangle goes to ∣+i⟩|{+i}\rangle.
  • S, then H: ∣0⟩|{0}\rangle goes to ∣+⟩|{+}\rangle.

Written as matrices, "H, then S" is the product S HS\,H: the gate applied first stands nearest the state, on the right.

Undoing and combining

Every gate can be undone by turning back the same angle about the same axis. That reverse gate is written U†U^\dagger ("U dagger"): S† undoes S, and X, Y, Z and H, being half turns, undo themselves.

Any sequence of turns adds up to a single turn, so any sequence of gates is one gate. For example, H, then Z, then H is the same as X:

H Z H=XH\,Z\,H = X

The Gate Lab shows this for any sequence you build.

The gates, one by one

  • Pauli-X: the quantum NOT, a half turn about x.
  • Pauli-Y: a half turn about y.
  • Pauli-Z: the phase flip, a half turn about z.
  • Hadamard: a half turn about the diagonal between x and z.
  • S and T: quarter and eighth turns about z.
  • Rotation gates: any angle about x, y or z.