Skip to the content
Kets & Gates homeOpen the app

Math toolkit

Matrices acting on states

Gates are matrices; circuit order vs matrix order

about 5 min

Practise this in the app

In the app every question checks your answer and explains a wrong one.

Matrix times vector

A single-qubit gate is a 2×22\times 2 matrix. Applying it to a state means multiplying the state’s column vector (every ket, such as ∣0⟩\ket0, stands for one: see kets as vectors). Each output entry is a row of the matrix dotted with the input.

[abcd][αβ]=[aα+bβcα+dβ]\begin{bmatrix}a & b\\ c & d\end{bmatrix}\begin{bmatrix}\alpha\\ \beta\end{bmatrix} = \begin{bmatrix}a\alpha + b\beta\\ c\alpha + d\beta\end{bmatrix}

A shortcut: the first column is what the gate does to ∣0⟩\ket0, and the second column is what it does to ∣1⟩\ket1.

Worked example

Hadamard on |1⟩

  1. H=12[111−1]H = \tfrac{1}{\sqrt2}\begin{bmatrix}1 & 1\\ 1 & -1\end{bmatrix} and ∣1⟩=[01]\ket1 = \begin{bmatrix}0\\1\end{bmatrix}.

  2. Top entry: 12(1⋅0+1⋅1)=12\tfrac{1}{\sqrt2}(1\cdot 0 + 1\cdot 1) = \tfrac{1}{\sqrt2}. Bottom entry: 12(1⋅0+(−1)⋅1)=−12\tfrac{1}{\sqrt2}(1\cdot 0 + (-1)\cdot 1) = -\tfrac{1}{\sqrt2}.

  3. So H∣1⟩=12(∣0⟩−∣1⟩)H\ket1 = \tfrac{1}{\sqrt2}(\ket0 - \ket1), the state called ∣−⟩\ket{-}.

Check yourself

Apply X=[0110]X = \begin{bmatrix}0 & 1\\ 1 & 0\end{bmatrix} to 35∣0⟩+45∣1⟩\tfrac{3}{5}\ket0 + \tfrac{4}{5}\ket1.

Hints
  1. Dot the top row (0,1)(0, 1) with the input. What do you get?
  2. XX swaps the two entries.
Show the answer

Answer: 45∣0⟩+35∣1⟩\frac{4}{5}|0\rangle + \frac{3}{5}|1\rangle

The top row picks out β\beta, the bottom row picks out α\alpha.

Order, and the dagger

In a circuit, time runs left to right: first AA, then BB. As matrices that is BA∣ψ⟩BA\ket\psi, because the matrix nearest the ket acts first. The adjoint U†U^\dagger is the conjugate transpose. A matrix is unitary when U†U=IU^\dagger U = I; every quantum gate is unitary, so every gate can be undone by applying U†U^\dagger.

Check yourself

A circuit applies HH and then ZZ to a qubit. Which expression gives the final state?

  1. AZH∣ψ⟩ZH\ket\psi
  2. BHZ∣ψ⟩HZ\ket\psi
  3. CH∣ψ⟩+Z∣ψ⟩H\ket\psi + Z\ket\psi
Show the answer

Answer: A. ZH∣ψ⟩ZH\ket\psi

Read the circuit left to right and write the matrices right to left: Z(H∣ψ⟩)Z(H\ket\psi).

Why not the others

  • B. That applies ZZ first. The matrix closest to the ket acts first, so circuit order is reversed in the formula.
  • C. Gates in sequence compose by multiplication, not addition.

Check yourself

Which of these matrices could be a quantum gate?

  1. A[100−1]\begin{bmatrix}1 & 0\\ 0 & -1\end{bmatrix}
  2. B[1000]\begin{bmatrix}1 & 0\\ 0 & 0\end{bmatrix}
  3. C12[1111]\tfrac{1}{\sqrt2}\begin{bmatrix}1 & 1\\ 1 & 1\end{bmatrix}
  4. D[1101]\begin{bmatrix}1 & 1\\ 0 & 1\end{bmatrix}
Hints
  1. Look at the columns: what does each matrix do to ∣0⟩\ket0 and to ∣1⟩\ket1?
  2. A gate needs both images to be unit vectors, and orthogonal to each other.
Show the answer

Answer: A. [100−1]\begin{bmatrix}1 & 0\\ 0 & -1\end{bmatrix}

ZZ sends ∣0⟩→∣0⟩\ket0 \to \ket0 and ∣1⟩→−∣1⟩\ket1 \to -\ket1: two unit columns that are orthogonal, so Z†Z=IZ^\dagger Z = I.

Why not the others

  • B. This keeps ∣0⟩\ket0 and sends ∣1⟩\ket1 to the zero vector, which is not a state. Its second column has length 0, not 1, so it is not unitary. It describes the measurement outcome 0, not a gate.
  • C. Each column has length 1, but both columns are the same: ∣0⟩\ket0 and ∣1⟩\ket1 land on the same state, and ∣−⟩=12(∣0⟩−∣1⟩)\ket- = \tfrac{1}{\sqrt2}(\ket0 - \ket1) is sent to zero. A gate must keep orthogonal states orthogonal so it can be undone.
  • D. Its second column, the image of ∣1⟩\ket1, is (1,1)(1, 1), with length 2\sqrt2. A gate must keep every state normalized, so each column must have length 1.

Go further

Free resources for when you want more than this refresher covers.

Lessons that use it

Practise this in the appAll refreshers