Quantum Academy is now open. Enroll in live online training – see the schedule.
Skip to content
Browse courses

The Math of Quantum Computing, and How Much of It You Need

Quantum Computing

Quantum Academy6 min read

For the math of quantum computing, four pieces are enough to follow a circuit gate by gate: complex numbers, vectors, matrix multiplication and probability. Dirac notation, the bracket shorthand for vectors used in papers and course material, adds symbols for those same objects rather than new mathematics.

IBM’s Basics of Quantum Information course, the first of four presented by John Watrous, starts from the same set: states as vectors with complex entries, operations as unitary matrices, and measurements that extract classical information.

Complex numbers and phase

A complex number has the form a + bi, where i² = −1. Plotted with a on the horizontal axis and b on the vertical, it’s a point with a size, its distance from zero, and an angle, called its phase. In papers, a number of size r and phase θ is written re^(iθ), so e^(iπ) = −1 is a half-turn and e^(iπ/2) = i is a quarter-turn.

Each possible measurement result has a complex number attached, its amplitude. The probability of a result is its amplitude’s size squared, a rule called the Born rule.

When two steps of a computation lead to the same result, their amplitudes add before anything is squared. Take two contributions of size 1/2:

  • Same phase: 1/2 + 1/2 = 1, probability 1.
  • Phases 90° apart: 1/2 + i/2 has size about 0.707, probability 1/2.
  • Phases 180° apart: 1/2 − 1/2 = 0, probability 0.

With ordinary probabilities, 1/4 + 1/4 = 1/2 every time. In general, |a + b|² = |a|² + |b|² + 2|a||b|cos θ, where θ is the angle between a and b. The last term, called interference, is the reason amplitudes can cancel. Algorithm designers choose gates so that wrong answers’ amplitudes cancel, which works only for problems with particular mathematical structure, so quantum speedups are specific rather than general.

State vectors and gates as matrices

A state vector has one amplitude for each possible result. For one qubit that’s a column of two complex numbers (a, b), with |a|² + |b|² = 1. The vectors for results 0 and 1 are |0⟩ = (1, 0), read “ket zero”, and |1⟩ = (0, 1).

A gate is an operation on qubits. A single-qubit gate is a 2×2 matrix. You apply it by multiplying: each entry of the result is one row of the matrix times the state vector, with matching entries multiplied and the products summed.

The X gate, the quantum counterpart of NOT, has rows (0, 1) and (1, 0). Apply it to |0⟩ = (1, 0):

  • first entry: 0 × 1 + 1 × 0 = 0
  • second entry: 1 × 1 + 0 × 0 = 1

So X|0⟩ = (0, 1) = |1⟩. The Hadamard gate, H, is 1/√2 times the matrix with rows (1, 1) and (1, −1), so H|0⟩ = (1/√2, 1/√2): each result has amplitude about 0.707 and probability 1/2.

Matrix products are written right to left, the reverse of a circuit diagram, so “X, then H” is HX: HX|0⟩ = H|1⟩ = (1/√2, −1/√2), with the same odds as H|0⟩ and a minus sign on the second amplitude.

Gate matrices are unitary: a gate U times its conjugate transpose U† (“U dagger”), which swaps rows with columns and replaces each i with −i, gives the identity matrix, which changes nothing. So the probabilities still add up to 1 after every gate, and U† undoes U.

Two qubits and the tensor product

Two qubits have four possible results, 00, 01, 10 and 11, so their state vector has four entries and their gates are 4×4 matrices. You build the longer vector with the tensor product, ⊗, multiplying the whole second vector by each entry of the first: (a, b) ⊗ (c, d) = (ac, ad, bc, bd). So |0⟩ ⊗ |0⟩ = (1, 0, 0, 0), written |00⟩.

The same rule applies to matrices. H on the first qubit and nothing on the second is H ⊗ I, where I is the 2×2 identity matrix, and (H ⊗ I)|00⟩ = (1/√2, 0, 1/√2, 0).

The controlled-NOT gate, CNOT, flips the second qubit when the first is 1. With entries in the order 00, 01, 10, 11, its rows are (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 0, 1) and (0, 0, 1, 0), so it swaps the last two amplitudes: (1/√2, 0, 1/√2, 0) becomes (1/√2, 0, 0, 1/√2).

That’s the Bell pair, which the programs in Four Quantum Frameworks, One Bell Pair prepare with the same two gates. Measuring it gives 00 or 11, each with probability 1/2. It isn’t the tensor product of two single-qubit vectors: in (ac, ad, bc, bd), a zero second entry needs a = 0 or d = 0, which would make the first or the last entry zero instead of 1/√2. A state that isn’t such a product is called entangled.

Reading Dirac notation

Paul Dirac proposed the notation, and the names bra and ket, in a three-page paper published in 1939.

  • |ψ⟩, “ket psi”, is a column vector named ψ. Greek letters such as ψ (psi) and φ (phi) are the usual names for a general state.
  • ⟨φ|, “bra phi”, is the conjugate transpose of |φ⟩: a row, with each i replaced by −i.
  • ⟨φ|ψ⟩ is the inner product, the row times the column, a single complex number. If |φ⟩ is one of the results a measurement distinguishes, |⟨φ|ψ⟩|² is the probability of getting it. An inner product of 0 means the two states can always be told apart.
  • |φ⟩⟨ψ| is the outer product, a column times a row, which gives a matrix, as in X = |0⟩⟨1| + |1⟩⟨0|.
  • |00⟩ is shorthand for |0⟩ ⊗ |0⟩, also written |0⟩|0⟩.

The bra’s conjugate is required for complex states. Take |ψ⟩ = (1/√2, i/√2). Its bra is (1/√2, −i/√2), and ⟨ψ|ψ⟩ = 1/2 + (−i)(i)/2 = 1/2 + 1/2 = 1, the total probability. Without the conjugate you’d get 1/2 + i²/2 = 0, as if a valid state had length zero.

Authors often write the Bell pair as |00⟩ + |11⟩, leaving out the 1/√2 “up to normalization”: the squared sizes must add up to 1, so two terms of equal size get 1/√2 each. They also drop an overall factor such as −1 or i, “up to a global phase”, since multiplying every amplitude by it changes no probability.

Check the qubit order before you compare software with a textbook. In Qiskit, qubit 0 is the rightmost bit of a result such as 01. So in Qiskit’s CNOT documentation the gate with control qubit 0 has rows (1, 0, 0, 0), (0, 0, 0, 1), (0, 0, 1, 0) and (0, 1, 0, 0): the matrix above, with its entries reordered.

What to learn later

You can leave three topics until your work requires them.

  • Density matrices. A density matrix describes a state that isn’t known exactly, such as a qubit after noise, or one half of an entangled pair when you ignore the other. IBM’s series covers Shor’s and Grover’s algorithms in its second course and introduces density matrices in its third, General Formulation of Quantum Information.
  • The full Hilbert-space formalism. A vector space with an inner product is a Hilbert space if it also satisfies a completeness condition, which affects only infinite-dimensional spaces, such as the states of a particle that can be anywhere along a line. For n qubits it’s the 2ⁿ-entry complex vectors used above.
  • Group theory. A group is a set of operations that can be combined and undone. You’ll need group theory for the hidden subgroup problem, the generalization that covers Shor’s algorithms for factoring and discrete logarithms, and for stabilizer codes in error correction. In Nielsen and Chuang’s textbook, Quantum Computation and Quantum Information (2010 edition), it’s Appendix 2.

Our Certified Quantum Technology Professional (CQTP) Training covers evaluating quantum computing technologies for enterprise and government use, including hardware modalities, algorithms, cloud platforms, integration challenges and organizational readiness; Quantum Computing Fundamentals covers qubits, gates and algorithms at a conceptual and practical level.

Check it in NumPy

You can check every number above in NumPy. np.kron gives tensor products, @ multiplies matrices, and np.vdot conjugates its first argument, so np.vdot(a, b) computes ⟨a|b⟩. Plain np.dot doesn’t conjugate, and it returns 0 for the ⟨ψ|ψ⟩ example.

import numpy as np

s = 1 / np.sqrt(2)
H = s * np.array([[1, 1], [1, -1]])
I = np.eye(2)
CNOT = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]])

ket00 = np.kron([1, 0], [1, 0])
bell = CNOT @ np.kron(H, I) @ ket00
print(bell)                 # expect 0.707, 0, 0, 0.707
print(np.vdot(bell, bell))  # expect 1, up to rounding

Then change one gate and predict the four new amplitudes on paper before you run it.