What may a gate do to a state?
A gate is something we do to a qubit between preparation and measurement: a laser or microwave pulse, a precisely timed interaction. Whatever the hardware, the mathematical description has to respect two requirements.
- Linearity. If a gate maps to and to , it must map to . This is a postulate of quantum mechanics (closed systems evolve linearly), and it is what lets the interference of the first lesson happen path by path. A linear map on is a matrix .
- States stay states. Every unit vector must be mapped to a unit vector, or the Born probabilities would stop adding to one.
These two requirements force to be unitary: , where is the conjugate transpose.
Proof. For every unit vector we need . Let . Then for every unit , hence (by scaling) for every vector. is Hermitian, so it has an orthonormal eigenbasis with real eigenvalues ; choosing to be an eigenvector gives for every , hence . Conversely, if then : unitaries preserve all inner products, not only norms.
A unitary matrix is invertible with , which is itself unitary.
So every gate can be undone by applying its adjoint. Classical logic is
different: an AND gate maps both inputs 01 and 10 to output 0, so it cannot
be reversed. Quantum gates never lose information in this way. The only
irreversible step in a circuit is measurement, as the next lesson shows.
The standard single-qubit gates
The gates you will meet everywhere are, in the computational basis:
| Gate | Matrix | Action on basis states |
|---|---|---|
| (bit flip, NOT) | ||
| , | ||
| (phase flip) | ||
| , | ||
Useful relations, each a one-line matrix multiplication: , , , , , and . The Paulis are both unitary and Hermitian, so each is its own inverse; and are not Hermitian, and their inverses are and .
Rotation gates
Since for each Pauli , the exponential series splits into even and odd terms:
More generally, for a real unit vector the matrix also squares to , and . For example
Comparing with shows : the two differ only by a global phase, so they are the same physical operation on a single qubit. (The phase becomes relevant when a gate is controlled by another qubit, a point we return to in the algorithms lesson.)
Gates are rotations of the Bloch sphere
Here is the geometric fact that makes single-qubit gates easy to visualise.
Theorem. For a single qubit, rotates every Bloch vector by angle about the axis (right-hand rule). Every unitary equals for some phase , axis and angle , so every single-qubit gate acts on the Bloch sphere as a rotation. (See Nielsen and Chuang, Section 4.2 and Exercise 4.6.)
The case can be checked by hand. Apply to the Bloch form:
Up to the global phase , is unchanged and increases by : a rotation by about . A relative phase gate is a turn around the vertical axis. The exercise checks the general statement numerically by computing the matrix that a gate applies to Bloch vectors.
Reading familiar gates as rotations:
- : half a turn about , which swaps the poles.
- : half a turn about , which swaps and .
- and : quarter and eighth turns about .
- with , because . Half a turn about the axis halfway between and exchanges those two axes and reverses ; that is why maps and .
Composition and order
A circuit is read left to right, in time order. Matrices act on the column vector from the left, so the circuit "first , then " is the matrix product . Getting this backwards is the most common error in hand calculations.
Both wires start in . On wire , . On wire , , because only puts a phase on , which does not have. Two different states; in Bloch terms, rotating to the axis and then a quarter turn about ends on the axis, while a quarter turn about does nothing to the north pole. Rotations about different axes do not commute, and neither do the gates.
Sometimes two orders differ only by a global phase, which is physically the same gate: while . On a single qubit these two products do the same thing. You should always ask whether a difference is a global phase before concluding that two circuits disagree.
Universality: the ZYZ decomposition
How many different kinds of gate does a single-qubit processor need? Very few.
Theorem (ZYZ decomposition). For every unitary there are real numbers such that
(Nielsen and Chuang, Theorem 4.1.) So rotations about just two fixed axes, and , reach every single-qubit gate. The angles are easy to find. Multiplying out the three rotations gives
which has determinant 1. So fixes (up to adding , which is absorbed by the other angles). Dividing by leaves a matrix of the form above: the moduli of its entries give , and the phases of the left column give and . When or only one of these combinations is determined, and any split works.
Worked example: the Hadamard gate
For , , so and . The moduli of the entries are all , so and . The top-left entry has phase , so ; the bottom-left entry gives modulo , i.e. . Hence , :
In words: a half turn about , then a quarter turn about . Follow : the half turn about leaves the north pole fixed, and the quarter turn about tips it down to the axis, which is . Check numerically:
import numpy as np
def rz(a): return np.diag([np.exp(-1j * a / 2), np.exp(1j * a / 2)])
def ry(a): return np.array([[np.cos(a / 2), -np.sin(a / 2)], [np.sin(a / 2), np.cos(a / 2)]])
H = np.array([[1, 1], [1, -1]]) / np.sqrt(2)
print(np.allclose(np.exp(1j * np.pi / 2) * ry(np.pi / 2) @ rz(np.pi), H)) # True
T = np.diag([1, np.exp(1j * np.pi / 4)])
print(np.allclose(H @ T @ H, np.exp(1j * np.pi / 8) * rz(-np.pi / 2) @ ry(np.pi / 4) @ rz(np.pi / 2))) # True
The second line shows another decomposition you will reproduce in the exercise: , a gate "seen in the basis", has .
What universality does and does not mean
The ZYZ theorem is an exact statement with continuous angles. Real devices offer a native gate set, and compilers translate every requested gate into it. Two further facts, stated here without proof, complete the picture. First, any single-qubit unitary can be approximated to any accuracy by finite sequences drawn from the discrete set (the Solovay–Kitaev theorem; see Nielsen and Chuang, Section 4.5 and Appendix 3). Second, single-qubit gates together with one entangling two-qubit gate such as CNOT can build any unitary on any number of qubits (Barenco et al., 1995). Universality says nothing about efficiency: most -qubit unitaries need a number of gates that grows exponentially in .
Common mistakes
- Multiplying in circuit order. "First , then " is , not .
- Forgetting the half-angle. has entries but rotates the Bloch sphere by the full .
- Treating a global phase as a different gate. and , or and , differ only by a global phase on a single qubit.
- Assuming is a rotation about . is a half turn about the axis ; also takes to , but it takes to , whereas takes back to .
- Reading universality as efficiency. That every gate can be built says nothing about how many gates it takes.
Summary
- Linearity plus norm preservation means gates are unitary, , and therefore reversible with inverse .
- ; every single-qubit gate is a rotation of the Bloch sphere up to global phase.
- Order matters: circuits are read left to right, matrices multiply right to left.
- Every single-qubit unitary is .
In the exercise you build rotation gates, compute the Bloch rotation of any gate and implement the ZYZ decomposition. Next, Measurement and probability explains the one operation that is not unitary.