Appendix B: Gate Reference
Matrices use the convention $|0\rangle = \binom{1}{0}$. Multi-qubit matrices are written in Qiskit's little-endian ordering — qubit 0 is the rightmost bit of a basis label, and Cirq reverses this (Appendix E).
Single-qubit gates
Pauli gates
$$X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} \quad Y = \begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix} \quad Z = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}$$
$X$ is the bit flip, $Z$ the phase flip, $Y = iXZ$ both. All are self-inverse and Hermitian.
⚠️ $X$ is invisible in the $X$ basis. $X|+\rangle = |+\rangle$. Chapter 25 §25.3 lost an afternoon to this — a phase-flip code test measured 0.0000 error everywhere because the decoded logical error was an $X$ acting on $|+\rangle$.
Hadamard
$$H = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}$$
Maps $Z \leftrightarrow X$. Self-inverse. Creates equal superposition from a basis state.
Phase gates
$$S = \begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix} \quad T = \begin{pmatrix} 1 & 0 \\ 0 & e^{i\pi/4} \end{pmatrix} \quad P(\lambda) = \begin{pmatrix} 1 & 0 \\ 0 & e^{i\lambda} \end{pmatrix}$$
$S = P(\pi/2)$, $T = P(\pi/4)$, $Z = P(\pi)$.
★ The T gate is the expensive one. Clifford gates ($H$, $S$, CNOT, Paulis) are efficiently simulable classically (Gottesman–Knill) and cheap to make fault-tolerant. T gates are neither. Chapter 15 measured a circuit going from 450 physical qubits with zero T gates to 2,882 with one — a 6.4× cliff from a single gate.
Rotations
$$R_x(\theta) = \begin{pmatrix} \cos\frac{\theta}{2} & -i\sin\frac{\theta}{2} \\ -i\sin\frac{\theta}{2} & \cos\frac{\theta}{2}\end{pmatrix} \quad R_y(\theta) = \begin{pmatrix} \cos\frac{\theta}{2} & -\sin\frac{\theta}{2} \\ \sin\frac{\theta}{2} & \cos\frac{\theta}{2}\end{pmatrix}$$
$$R_z(\theta) = \begin{pmatrix} e^{-i\theta/2} & 0 \\ 0 & e^{i\theta/2}\end{pmatrix}$$
★ $R_z$ costs zero nanoseconds on superconducting hardware. It is a virtual Z: implemented by shifting the phase of subsequent pulses rather than by playing one. Chapter 31 measured
rzat 0.0 ns againstsxat 32–64 ns.
$$U(\theta,\phi,\lambda) = \begin{pmatrix} \cos\frac{\theta}{2} & -e^{i\lambda}\sin\frac{\theta}{2} \\ e^{i\phi}\sin\frac{\theta}{2} & e^{i(\phi+\lambda)}\cos\frac{\theta}{2}\end{pmatrix}$$
The general single-qubit unitary, up to global phase. Every single-qubit gate is a $U$.
The sx gate
$$\sqrt{X} = \frac{1}{2}\begin{pmatrix} 1+i & 1-i \\ 1-i & 1+i \end{pmatrix}$$
IBM's native single-qubit gate. Physical circuits are $R_z$–$\sqrt{X}$–$R_z$–$\sqrt{X}$–$R_z$ sequences, so only the $\sqrt{X}$ pulses take time.
Two-qubit gates
CNOT
$$\mathrm{CX} = \begin{pmatrix} 1&0&0&0 \\ 0&1&0&0 \\ 0&0&0&1 \\ 0&0&1&0 \end{pmatrix}$$
The standard entangler. $H^{\otimes 2}\,\mathrm{CX}\,H^{\otimes 2}$ reverses control and target — the identity every transpiler uses when the coupling map runs the wrong way.
CZ
$$\mathrm{CZ} = \mathrm{diag}(1, 1, 1, -1)$$
Symmetric in its arguments. IBM's native two-qubit gate on newer devices; Chapter 39 measured it at 68–184 ns.
ECR
The echoed cross-resonance gate, native on some IBM devices. Chapter 39 measured 341–882 ns — substantially slower than CZ, which is why device choice changes circuit duration.
SWAP
$$\mathrm{SWAP} = \begin{pmatrix} 1&0&0&0 \\ 0&0&1&0 \\ 0&1&0&0 \\ 0&0&0&1 \end{pmatrix}$$
Three CNOTs. The transpiler inserts these for connectivity, and they dominate routing overhead — Chapter 39 measured a 14-qubit circuit spanning 49 to 112 two-qubit gates across transpiler seeds.
Mølmer–Sørensen
The native trapped-ion entangler, acting on any pair (all-to-all connectivity). Chapter 17 covers it; Chapter 39 measured the 28× per-shot price that connectivity comes with.
Controlled rotations
$\mathrm{CR}_z(\theta)$, $\mathrm{CP}(\lambda)$ — the QFT's building blocks. The small-angle ones are what the approximate QFT discards (Chapter 22: cutoff 3 kept 97% fidelity for 36% of the rotations).
Three-qubit gates
Toffoli (CCX)
Flips the target when both controls are $|1\rangle$. Not native anywhere — decomposes into 6 CNOTs and 7 T gates, which is why Chapter 19's oracle costs are dominated by multi-controlled logic.
Fredkin (CSWAP)
Controlled swap. Also synthesized.
Cost summary
| Gate | Native? | Typical duration | Fault-tolerant cost |
|---|---|---|---|
| $R_z$ | yes (virtual) | 0 ns | free |
| $\sqrt{X}$, $X$ | yes | 32–64 ns | cheap (Clifford) |
| $H$, $S$, CNOT, CZ | yes / cheap | 68–184 ns (CZ) | cheap (Clifford) |
| $T$ | no | synthesized | expensive — magic state distillation |
| Toffoli | no | 6 CNOT + 7 T | expensive |
| arbitrary $R_z(\theta)$ | virtual, but... | 0 ns physically | expensive fault-tolerantly (Solovay–Kitaev) |
★ The last row is the trap. An arbitrary $R_z$ is free on NISQ hardware and expensive under error correction, where it must be synthesized from Clifford+T. A circuit optimized for today's devices is not optimized for tomorrow's.
See also: Appendix A (Qiskit calls), Appendix D (the linear algebra), Appendix F (OpenQASM names).