Skip to content

Single-qubit gates

You have already used XX, ZZ and HH as buttons. This lesson says what a gate is, so that you can work out what any circuit does.

A state is a column vector of two amplitudes. A gate is a 2×22\times2 matrix, and applying the gate means multiplying the vector by the matrix.

The three gates you have met are

X=(0110),Z=(100−1),H=12(111−1).X = \begin{pmatrix}0&1\\1&0\end{pmatrix}, \qquad Z = \begin{pmatrix}1&0\\0&-1\end{pmatrix}, \qquad H = \frac{1}{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}.

For example, XX acting on a general state swaps the two amplitudes:

X(αβ)=(0110)(αβ)=(βα).X\begin{pmatrix}\alpha\\ \beta\end{pmatrix} = \begin{pmatrix}0&1\\1&0\end{pmatrix}\begin{pmatrix}\alpha\\ \beta\end{pmatrix} = \begin{pmatrix}\beta\\ \alpha\end{pmatrix}.

A useful shortcut: the first column of a gate’s matrix is what it does to ∣0⟩\ket{0}, and the second column is what it does to ∣1⟩\ket{1}. Reading the columns of HH gives H∣0⟩=∣+⟩H\ket{0} = \ket{+} and H∣1⟩=∣−⟩H\ket{1} = \ket{-}, as before.

Because gates are matrices, they are linear. Once you know what a gate does to ∣0⟩\ket{0} and ∣1⟩\ket{1}, you know what it does to every state:

U(α∣0⟩+β∣1⟩)=α U∣0⟩+β U∣1⟩.U\bigl(\alpha\ket{0} + \beta\ket{1}\bigr) = \alpha\,U\ket{0} + \beta\,U\ket{1}.

A gate must turn valid states into valid states, so it has to preserve normalisation. The matrices that do this are exactly the unitary matrices, those satisfying

U†U=I,U^\dagger U = I,

where U†U^\dagger is the conjugate transpose of UU: flip the matrix across its diagonal and take the complex conjugate of each entry.

One consequence is that every gate can be undone, because U†U^\dagger is its inverse. Quantum computation is reversible, right up to the moment you measure.

Check

Which of these matrices is not a valid quantum gate?

Putting gates one after another multiplies their matrices. In the last lesson you found that HH, then ZZ, then HH takes ∣0⟩\ket{0} to ∣1⟩\ket{1}. In fact the three together are exactly the gate XX, on every input:

HZH=X.HZH = X.

The puzzles below are of a new kind. It is no longer enough to produce the right state from ∣0⟩\ket{0}. Your circuit has to behave like the target gate on every input, and the table shows what it does to each basis state.

PuzzleBuild Z

Using only HH and XX, build a circuit that acts as ZZ.

This puzzle needs JavaScript.

Hint

Start from HZH=XHZH = X and multiply by HH on the left and on the right. Remember that HH=IHH = I.

The pair of identities HZH=XHZH = X and HXH=ZHXH = Z says that HH translates between the two gates. It is worth remembering.

ZZ multiplies the amplitude of ∣1⟩\ket{1} by −1-1. Two more gates do the same kind of thing with a different factor:

S=(100i),T=(100eiπ/4).S = \begin{pmatrix}1&0\\0&i\end{pmatrix}, \qquad T = \begin{pmatrix}1&0\\0&e^{i\pi/4}\end{pmatrix}.

Since i2=−1i^2 = -1, applying SS twice gives ZZ. Likewise T2=ST^2 = S.

PuzzleUndo S

Every gate has an inverse. Build the inverse of SS, the gate that sends ∣1⟩\ket{1} to −i∣1⟩-i\ket{1}, using only SS itself.

This puzzle needs JavaScript.

Hint

What is i4i^4?

There is a fourth gate in the same family as XX and ZZ:

Y=(0−ii0).Y = \begin{pmatrix}0&-i\\i&0\end{pmatrix}.

Try to build it.

PuzzleBuild Y

Using only XX and ZZ, build a circuit that acts as YY. Then compare the two columns of the table closely.

This puzzle needs JavaScript.

Your circuit was accepted even though its outputs differ from the target’s by a factor of ii or −i-i. That is deliberate.

Multiplying a whole state by a number of magnitude one, such as ii or −1-1 or eiφe^{i\varphi}, is called changing its global phase. It has no observable effect. The Born rule only uses squared magnitudes, and a later gate carries the same factor through unchanged, so no experiment can detect it. The states ∣ψ⟩\ket{\psi} and i∣ψ⟩i\ket{\psi} are physically the same state.

Compare this with the relative phase from the last lesson. In ∣−⟩=12(∣0⟩−∣1⟩)\ket{-} = \tfrac{1}{\sqrt2}(\ket{0} - \ket{1}) the minus sign multiplies only one term, and that can be detected. The rule is:

  • a phase on the whole state is unobservable,
  • a phase on part of the state is real physics.

Exercise. Show that HH is unitary, and that it is its own inverse.

Solution

HH is real and symmetric, so H†=HH^\dagger = H. Then

H†H=H2=12(111−1)(111−1)=12(2002)=I.H^\dagger H = H^2 = \frac12\begin{pmatrix}1&1\\1&-1\end{pmatrix}\begin{pmatrix}1&1\\1&-1\end{pmatrix} = \frac12\begin{pmatrix}2&0\\0&2\end{pmatrix} = I.

So HH is unitary, and since H2=IH^2 = I it undoes itself.

RecallAnswer from memory, then check
LessonFinish this lesson