Home / Articles / Mathematics Research Frontiers
Mathematics Research Frontiers · 5 min read

Mathematics of Quantum Computing

Learn the linear algebra behind quantum computing: qubits, gates, measurement, entanglement and Grover's search, explained with fully worked examples.

Quantum computers are often described with mysterious words such as superposition and entanglement, but the mathematics behind them is clean, precise and surprisingly accessible. If you are comfortable with vectors, matrices and complex numbers, you already have most of the tools you need. In this article we build the core ideas step by step and work through real calculations that quantum programmers do every day.

Qubits as Vectors

A classical bit is either 0 or 1. A qubit is a unit vector in a two-dimensional complex vector space. We write the two basis states using Dirac's ket notation:

$$ |0\rangle = \begin{pmatrix} 1 \\ 0 \end{pmatrix}, \qquad |1\rangle = \begin{pmatrix} 0 \\ 1 \end{pmatrix}. $$

A general qubit state is

$$ |\psi\rangle = \alpha|0\rangle + \beta|1\rangle, \qquad |\alpha|^2 + |\beta|^2 = 1, $$

where \( \alpha \) and \( \beta \) are complex numbers called amplitudes. The condition \( |\alpha|^2 + |\beta|^2 = 1 \) is called normalisation.

Measurement and the Born Rule

When we measure a qubit in the standard basis, we get 0 with probability \( |\alpha|^2 \) and 1 with probability \( |\beta|^2 \). After measurement the state collapses to the observed basis state. For example, the state

$$ |\psi\rangle = \tfrac{1}{2}|0\rangle + \tfrac{\sqrt{3}}{2}|1\rangle $$

gives 0 with probability \( 1/4 = 25\% \) and 1 with probability \( 3/4 = 75\% \). Check: \( 1/4 + 3/4 = 1 \), so the state is properly normalised.

Quantum Gates as Unitary Matrices

Quantum operations must keep vectors at unit length, so they are represented by unitary matrices, which satisfy \( U^\dagger U = I \), where \( U^\dagger \) is the conjugate transpose. Some essential single-qubit gates are:

  • Pauli-X (NOT): \( X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} \), which swaps \( |0\rangle \) and \( |1\rangle \).
  • Pauli-Z: \( Z = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} \), which flips the sign of the \( |1\rangle \) amplitude.
  • Hadamard: \( H = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} \), which creates equal superpositions.

Worked Example 1: Interference with Two Hadamards

Step 1: Apply \( H \) to \( |0\rangle \).

$$ H|0\rangle = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}\begin{pmatrix} 1 \\ 0 \end{pmatrix} = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 \\ 1 \end{pmatrix} = \frac{|0\rangle + |1\rangle}{\sqrt{2}}. $$

Measuring now gives 0 or 1, each with probability \( (1/\sqrt{2})^2 = 1/2 \). It looks like a fair coin.

Step 2: Apply \( H \) again.

$$ H\left(\frac{1}{\sqrt{2}}\begin{pmatrix} 1 \\ 1 \end{pmatrix}\right) = \frac{1}{2}\begin{pmatrix} 1 + 1 \\ 1 - 1 \end{pmatrix} = \begin{pmatrix} 1 \\ 0 \end{pmatrix} = |0\rangle. $$

Step 3: Interpret. A truly random coin flipped twice would still be random. Here, the two paths leading to \( |1\rangle \) have amplitudes \( +\tfrac{1}{2} \) and \( -\tfrac{1}{2} \), which cancel, while the paths to \( |0\rangle \) add. This is interference, and every useful quantum algorithm is designed so that wrong answers cancel and right answers reinforce. We can also confirm \( H^2 = I \) directly by multiplying the matrices.

Many Qubits and the Tensor Product

Two qubits live in a four-dimensional space with basis \( |00\rangle, |01\rangle, |10\rangle, |11\rangle \). The joint state of independent qubits is the tensor (Kronecker) product. For instance,

$$ |0\rangle \otimes |1\rangle = \begin{pmatrix} 1 \\ 0 \end{pmatrix} \otimes \begin{pmatrix} 0 \\ 1 \end{pmatrix} = \begin{pmatrix} 0 \\ 1 \\ 0 \\ 0 \end{pmatrix} = |01\rangle. $$

With \( n \) qubits, the state vector has \( 2^n \) amplitudes. Fifty qubits already need about \( 10^{15} \) complex numbers, which is why classical simulation becomes impossible so quickly.

Worked Example 2: Creating a Bell State

The CNOT gate flips the second (target) qubit when the first (control) qubit is 1. In the basis order \( |00\rangle, |01\rangle, |10\rangle, |11\rangle \):

$$ \text{CNOT} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix}. $$

Step 1: Start in \( |00\rangle \) and apply \( H \) to the first qubit.

$$ (H|0\rangle) \otimes |0\rangle = \frac{|0\rangle + |1\rangle}{\sqrt{2}} \otimes |0\rangle = \frac{|00\rangle + |10\rangle}{\sqrt{2}}. $$

Step 2: Apply CNOT. The term \( |00\rangle \) is unchanged because the control is 0. The term \( |10\rangle \) becomes \( |11\rangle \).

$$ |\Phi^+\rangle = \frac{|00\rangle + |11\rangle}{\sqrt{2}}. $$

Step 3: Check for entanglement. If this were a product state \( (a|0\rangle + b|1\rangle)(c|0\rangle + d|1\rangle) \), we would need \( ac = 1/\sqrt{2} \), \( bd = 1/\sqrt{2} \), and \( ad = bc = 0 \). But \( ad = 0 \) forces \( a = 0 \) or \( d = 0 \), contradicting \( ac \neq 0 \) or \( bd \neq 0 \). So no factorisation exists: the qubits are entangled. Measuring them always gives matching results, 00 or 11, each with probability \( 1/2 \).

Grover's Search: Amplitudes at Work

Grover's algorithm finds a marked item among \( N \) unsorted items in about \( \frac{\pi}{4}\sqrt{N} \) steps, compared with about \( N/2 \) checks on average for a classical search. Each iteration has two parts: an oracle that flips the sign of the marked item's amplitude, and a diffusion step that reflects every amplitude about the mean, \( a \mapsto 2\bar{a} - a \).

Worked Example 3: Grover with Four Items

Take \( N = 4 \) items with item 3 marked (indexing 1 to 4).

  1. Uniform start: amplitudes \( \left(\tfrac{1}{2}, \tfrac{1}{2}, \tfrac{1}{2}, \tfrac{1}{2}\right) \).
  2. Oracle: flip item 3, giving \( \left(\tfrac{1}{2}, \tfrac{1}{2}, -\tfrac{1}{2}, \tfrac{1}{2}\right) \).
  3. Mean: \( \bar{a} = \tfrac{1}{4}\left(\tfrac{1}{2} + \tfrac{1}{2} - \tfrac{1}{2} + \tfrac{1}{2}\right) = \tfrac{1}{4} \).
  4. Reflect: unmarked items become \( 2\left(\tfrac{1}{4}\right) - \tfrac{1}{2} = 0 \); the marked item becomes \( 2\left(\tfrac{1}{4}\right) + \tfrac{1}{2} = 1 \).

After a single iteration, measurement returns the marked item with probability \( 1^2 = 1 \). A classical search would need up to three checks to be certain.

The Wider Mathematical Toolkit

  • Linear algebra: eigenvalues, unitary and Hermitian matrices, inner products.
  • Number theory and Fourier analysis: Shor's algorithm factors integers using the quantum Fourier transform to find periods.
  • Probability: every output is a sample from a distribution set by amplitudes.
  • Error correction: codes such as the surface code use group theory and topology to protect fragile qubits.

For students, the best preparation is a solid university course in linear algebra, especially eigenvectors and inner products, followed by practice simulating small circuits by hand and then in a Python framework such as Qiskit. Every result in this article can be checked with a few lines of matrix code.

Did You Know?

  • Paul Dirac introduced the bra-ket notation in 1939, decades before anyone built a qubit.
  • Peter Shor published his factoring algorithm in 1994; Lov Grover published his search algorithm in 1996.
  • Because amplitudes can be negative or complex, probabilities can cancel, something ordinary probability theory never allows.

Key Takeaways

  • A qubit is a unit vector \( \alpha|0\rangle + \beta|1\rangle \); measurement probabilities are \( |\alpha|^2 \) and \( |\beta|^2 \).
  • Gates are unitary matrices, and circuits are products of these matrices.
  • Multi-qubit states use tensor products and grow as \( 2^n \) amplitudes.
  • Entangled states, such as Bell states, cannot be written as products of single-qubit states.
  • Algorithms such as Grover's exploit interference to amplify correct answers.

Stuck on bra-ket notation, tensor products or a quantum computing assignment? Amathify's experts and PhD scholars provide clear step-by-step solutions via WhatsApp or the Ask a Question form.

Stuck on a problem or assignment?

Our experts and PhD scholars solve maths, physics and chemistry — step by step.

WhatsApp usAsk a question

Related articles