Skip to content

A gate name specifies a unitary only after basis, tensor order, angle, and phase conventions have been fixed. This library records exact representatives for calculation. Single-Qubit Gates, Multi-Qubit Gates, and Controlled Operations explain their actions and synthesis.

Use column vectors in the basis (∣0⟩,∣1⟩)(\lvert0\rangle,\lvert1\rangle); in a matrix product the rightmost factor acts first. Angles are in radians. These are the conventional representatives used by Nielsen and Chuang.

Gate Exact matrix Useful relation
Identity I=(1001)I=\begin{pmatrix}1&0\\0&1\end{pmatrix} I2=II^2=I
Pauli X X=(0110)X=\begin{pmatrix}0&1\\1&0\end{pmatrix} X2=IX^2=I
Pauli Y Y=(0−ii0)Y=\begin{pmatrix}0&-i\\i&0\end{pmatrix} Y=iXZY=iXZ
Pauli Z Z=(100−1)Z=\begin{pmatrix}1&0\\0&-1\end{pmatrix} Z2=IZ^2=I
Hadamard H=12(111−1)H=\frac1{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix} H2=IH^2=I
Phase S S=diag⁡(1,i)S=\operatorname{diag}(1,i) S2=ZS^2=Z
Phase T T=diag⁡(1,eiπ/4)T=\operatorname{diag}(1,e^{i\pi/4}) T2=ST^2=S
General phase P(ϕ)=diag⁡(1,eiϕ)P(\phi)=\operatorname{diag}(1,e^{i\phi}) P(ϕ)†=P(−ϕ)P(\phi)^\dagger=P(-\phi)

For j=x,y,zj=x,y,z, define Rj(θ)=e−iθσj/2R_j(\theta)=e^{-i\theta\sigma_j/2}. Writing c=cos⁡(θ/2)c=\cos(\theta/2) and s=sin⁡(θ/2)s=\sin(\theta/2) gives

Rx(θ)=(c−is−isc),R_x(\theta)=\begin{pmatrix}c&-is\\-is&c\end{pmatrix}, Ry(θ)=(c−ssc),R_y(\theta)=\begin{pmatrix}c&-s\\s&c\end{pmatrix}, Rz(θ)=diag⁡(e−iθ/2,eiθ/2).R_z(\theta)=\operatorname{diag}(e^{-i\theta/2},e^{i\theta/2}).

Thus P(ϕ)=eiϕ/2Rz(ϕ)P(\phi)=e^{i\phi/2}R_z(\phi) and Rj(π)=−iσjR_j(\pi)=-i\sigma_j. The phase factor disappears from an isolated unitary channel, but may become a relative phase when that unitary is controlled. In particular, Rj(2π)=−IR_j(2\pi)=-I is not exact matrix equality to II.

Use the two-qubit basis (∣00⟩,∣01⟩,∣10⟩,∣11⟩)(\lvert00\rangle,\lvert01\rangle,\lvert10\rangle,\lvert11\rangle), with the first bit the left tensor factor. Here a,b,c∈{0,1}a,b,c\in\{0,1\} and ⊕\oplus denotes addition modulo two.

Gate Action and qualification
CNOT, first qubit controls second ∣a,b⟩↦∣a,b⊕a⟩\lvert a,b\rangle\mapsto\lvert a,b\oplus a\rangle
Reverse control direction is a different matrix.
CZ ∣a,b⟩↦(−1)ab∣a,b⟩\lvert a,b\rangle\mapsto(-1)^{ab}\lvert a,b\rangle
Symmetric under exchange of the qubits.
Controlled phase CP⁡(ϕ)=diag⁡(1,1,1,eiϕ)\operatorname{CP}(\phi)=\operatorname{diag}(1,1,1,e^{i\phi})
Equal to CZ at ϕ=π\phi=\pi.
SWAP ∣a,b⟩↦∣b,a⟩\lvert a,b\rangle\mapsto\lvert b,a\rangle
Exchanges tensor factors without entangling product inputs.
iSWAP ∣01⟩↦i∣10⟩\lvert01\rangle\mapsto i\lvert10\rangle, ∣10⟩↦i∣01⟩\lvert10\rangle\mapsto i\lvert01\rangle
Leaves ∣00⟩\lvert00\rangle and ∣11⟩\lvert11\rangle fixed; differs from SWAP by conditional phases.
Toffoli ∣a,b,c⟩↦∣a,b,c⊕ab⟩\lvert a,b,c\rangle\mapsto\lvert a,b,c\oplus ab\rangle
Two controls and one target.
Fredkin ∣0,b,c⟩↦∣0,b,c⟩\lvert0,b,c\rangle\mapsto\lvert0,b,c\rangle, ∣1,b,c⟩↦∣1,c,b⟩\lvert1,b,c\rangle\mapsto\lvert1,c,b\rangle
Controlled SWAP.

More generally,

C(U)=∣0⟩⟨0∣⊗I+∣1⟩⟨1∣⊗U.C(U)=\lvert0\rangle\langle0\rvert\otimes I +\lvert1\rangle\langle1\rvert\otimes U.

The tensor order in this equation defines which subsystem is the control. A software bit-order convention must be translated to this order before comparing arrays.

A native gate is an operation directly supported by a control implementation. Common mathematical families include RZZ(θ)=e−iθZ⊗Z/2R_{ZZ}(\theta)=e^{-i\theta Z\otimes Z/2}, RXX(θ)=e−iθX⊗X/2R_{XX}(\theta)=e^{-i\theta X\otimes X/2}, and exchange-type rotations. Their calibrated phase offsets, signs, and local rotations are part of the definition; the family name alone does not specify the implemented gate. See Gate Decomposition and Pulse-Level Control.

For a useful diagnostic, compare C(X)C(X) with C(Rx(π))C(R_x(\pi)) on ∣+0⟩\lvert+0\rangle. The former yields (∣00⟩+∣11⟩)/2(\lvert00\rangle+\lvert11\rangle)/\sqrt2, whereas the latter yields (∣00⟩−i∣11⟩)/2(\lvert00\rangle-i\lvert11\rangle)/\sqrt2. These differ by a relative phase. Multiplying the control by P(π/2)P(\pi/2) after the latter restores the former output. This is why dropping a one-qubit global phase before adding a control changes a circuit.

  • Nielsen, Michael A., and Isaac L. Chuang, Quantum Computation and Quantum Information, 10th anniversary edition, Cambridge University Press, 2010, doi:10.1017/CBO9780511976667 — conventional gates, controlled operations, and universal circuit constructions.