Categories: Quantum information.

Quantum gate

In quantum computing, quantum gates are the equivalent of classical binary logic gates such as NOT\mathrm{NOT}, AND\mathrm{AND}, etc. Because of the continuous nature of qubits, the number of possible quantum gates is uncountably infinite, so we only consider the most important examples here.

One-qubit gates

As an example, consider the following most general single-qubit state ψ\ket{\psi}:

ψ=α0+β1=[αβ]\begin{aligned} \ket{\psi} = \alpha \ket{0} + \beta \ket{1} = \begin{bmatrix} \alpha \\ \beta \end{bmatrix} \end{aligned}

Arguably the most famous and most fundamental quantum gates are the Pauli matrices:

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

They have the following effect on ψ\ket{\psi}. Note that XX is equivalent to the classical NOT\mathrm{NOT} gate (and is often given that name), and ZZ is sometimes called the phase-flip gate:

Xψ=[βα]Yψ=[iβiα]Zψ=[αβ]\begin{aligned} X \ket{\psi} = \begin{bmatrix} \beta \\ \alpha \end{bmatrix} \qquad Y \ket{\psi} = \begin{bmatrix} -i \beta \\ i \alpha \end{bmatrix} \qquad Z \ket{\psi} = \begin{bmatrix} \alpha \\ -\beta \end{bmatrix} \end{aligned}

In fact, ZZ is a specific case of the phase shift gate RϕR_\phi, which modifies the qubit’s phase without changing its amplitudes. For an angle ϕ\phi, it is given by:

Rϕ=[100eiϕ]\begin{aligned} \boxed{ R_\phi = \begin{bmatrix} 1 & 0 \\ 0 & e^{i \phi} \end{bmatrix} } \end{aligned}

For ϕ=π\phi = \pi, we recover the Pauli-ZZ gate. In general, the action of RϕR_\phi is as follows:

Rϕψ=[αeiϕβ]\begin{aligned} R_\phi \ket{\psi} = \begin{bmatrix} \alpha \\ e^{i \phi} \beta \end{bmatrix} \end{aligned}

Two common special cases of RϕR_\phi are ϕ=π/2\phi = \pi/2 and ϕ=π/4\phi = \pi/4, respectively called SS and TT:

S=Rπ/2=[100i]T=Rπ/4=12[2001+i]\begin{aligned} \boxed{ S = R_{\pi/2} = \begin{bmatrix} 1 & 0 \\ 0 & i \end{bmatrix} } \qquad \quad \boxed{ T = R_{\pi/4} = \frac{1}{\sqrt{2}} \begin{bmatrix} \sqrt{2} & 0 \\ 0 & 1 + i \end{bmatrix} } \end{aligned}

Finally, we have the Hadamard gate HH, which is defined as follows:

H=12[1111]\begin{aligned} \boxed{ H = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix} } \end{aligned}

Its action consists of rotating the qubit by π\pi around the axis (X+Z)/2(X + Z) / \sqrt{2} of the Bloch sphere:

Hψ=12[α+βαβ]\begin{aligned} H \ket{\psi} = \frac{1}{\sqrt{2}} \begin{bmatrix} \alpha + \beta \\ \alpha - \beta \end{bmatrix} \end{aligned}

Notably, it maps the eigenstates of XX and ZZ to each other, and is its own inverse (i.e. unitary):

H0=+H1=H+=0H=1\begin{aligned} H \ket{0} = \ket{+} \qquad H \ket{1} = \ket{-} \qquad H \ket{+} = \ket{0} \qquad H \ket{-} = \ket{1} \end{aligned}

The Clifford gates are a set including XX, YY, ZZ, HH and SS, or more generally any gates that rotate by multiples of π/2\pi/2 around the Bloch sphere. This set is not universal, meaning that if we start from 0\ket{0}, we can only reach 0\ket{0}, 1\ket{1}, +\ket{+}, \ket{-}, +i\ket{+i} i\ket{-i} using these gates.

If we add any non-Clifford gate, for example TT, then we can reach any point on the Bloch sphere, which means that the set is universal.

However, there is a problem: a qubit has an uncountable infinity of states, but a quantum circuit consists of a countably infinite sequence of gates, at most. Therefore, technically, we can never reach the whole Bloch sphere, but we can come up with circuits that approximate a target state to some degree ε\varepsilon. This is the definition of universality: any state can be approximated.

Two-qubit gates

As an example, let us consider the following two pure one-qubit states ψ1\ket{\psi_1} and ψ2\ket{\psi_2}:

ψ1=α10+β11=[α1β1]ψ2=α20+β21=[α2β2]\begin{aligned} \ket{\psi_1} = \alpha_1 \ket{0} + \beta_1 \ket{1} = \begin{bmatrix} \alpha_1 \\ \beta_1 \end{bmatrix} \qquad \quad \ket{\psi_2} = \alpha_2 \ket{0} + \beta_2 \ket{1} = \begin{bmatrix} \alpha_2 \\ \beta_2 \end{bmatrix} \end{aligned}

The composite state of both qubits, assuming they are pure, is then their tensor product \otimes:

ψ1ψ2=ψ1ψ2=α1α200+α1β201+β1α210+β1β211=c0000+c0101+c1010+c1111\begin{aligned} \ket{\psi_1 \psi_2} = \ket{\psi_1} \otimes \ket{\psi_2} &= \alpha_1 \alpha_2 \ket{00} + \alpha_1 \beta_2 \ket{01} + \beta_1 \alpha_2 \ket{10} + \beta_1 \beta_2 \ket{11} \\ &= c_{00} \ket{00} + c_{01} \ket{01} + c_{10} \ket{10} + c_{11} \ket{11} \end{aligned}

Note that a two-qubit system may be entangled, in which case the coefficients c00c_{00} etc. cannot be written as products, i.e. ψ2\ket{\psi_2} cannot be expressed separately from ψ1\ket{\psi_1}, and vice versa. In other words, the action of a two-qubit gate can be expressed in the basis of 00\ket{00}, 01\ket{01}, 10\ket{10} and 11\ket{11}, but not always in the basis of 01\ket{0}_1, 11\ket{1}_1, 02\ket{0}_2 and 12\ket{1}_2.

With this noted, the first two-qubit gate is SWAP\mathrm{SWAP}, which simply swaps ψ1\ket{\psi_1} and ψ2\ket{\psi_2}:

SWAP gate diagram

SWAP=[1000001001000001]\begin{aligned} \boxed{ \mathrm{SWAP} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} } \end{aligned}

This matrix is given in the basis of 00\ket{00}, 01\ket{01}, 10\ket{10} and 11\ket{11}. Note that SWAP\mathrm{SWAP} cannot generate entanglement, so if its input is separable, its output is too. In any case, its effect is clear:

SWAPψ1ψ2=c0000+c1001+c0110+c1111\begin{aligned} \mathrm{SWAP} \ket{\psi_1 \psi_2} &= c_{00} \ket{00} + c_{10} \ket{01} + c_{01} \ket{10} + c_{11} \ket{11} \end{aligned}

Next, there is the controlled NOT gate CNOT\mathrm{CNOT}, which “flips” (applies XX to) ψ2\ket{\psi_2} if ψ1\ket{\psi_1} is true:

CNOT gate diagram

CNOT=[1000010000010010]\begin{aligned} \boxed{ \mathrm{CNOT} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{bmatrix} } \end{aligned}

That is, it swaps the last two coefficients c10c_{10} and c11c_{11} in the composite state vector:

CNOTψ1ψ2=c0000+c0101+c1110+c1011\begin{aligned} \mathrm{CNOT} \ket{\psi_1 \psi_2} &= c_{00} \ket{00} + c_{01} \ket{01} + c_{11} \ket{10} + c_{10} \ket{11} \end{aligned}

More generally, from every one-qubit gate UU, we can define a two-qubit controlled U gate CU\mathrm{CU}, which applies UU to ψ2\ket{\psi_2} if ψ1\ket{\psi_1} is true:

CU gate diagram

CU=[1000010000u00u0100u10u11]\begin{aligned} \boxed{ \mathrm{CU} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & u_{00} & u_{01} \\ 0 & 0 & u_{10} & u_{11} \end{bmatrix} } \end{aligned}

Where the lower-right 2x2 block is simply UU. The general action of this gate is given by:

CUψ1ψ2=c0000+c0101+(c10u00+c11u01)10+(c10u10+c11u11)11\begin{aligned} \mathrm{CU} \ket{\psi_1 \psi_2} &= c_{00} \ket{00} + c_{01} \ket{01} + (c_{10} u_{00} + c_{11} u_{01}) \ket{10} + (c_{10} u_{10} + c_{11} u_{11}) \ket{11} \end{aligned}

A set of gates is universal if all possible mappings from nn to nn qubits can be approximated using only these gates. A minimal universal set is {CNOT,T,S}\{\mathrm{CNOT}, T, S\}, and there exist many others.


  1. J.S. Neergaard-Nielsen, Quantum information: lectures notes, 2021, unpublished.
  2. S. Aaronson, Introduction to quantum information science: lecture notes, 2018, unpublished.