Linear algebra for quantum computing
Linear algebra for quantum computing: vectors, inner products, matrices (Hermitian/unitary), tensor products and spectral decomposition — the math that represents qubits and gates.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Two sentences: Linear algebra provides the language and rules to represent qubits, multi-qubit states and quantum gates. An engineer uses these tools to compute state vectors, probabilities, compose gates (tensor products) and check properties (unitarity, Hermiticity) needed for designing and simulating quantum circuits (see topics like Qubits, Single-qubit gates and Multi-qubit states). In parallel you build multi-qubit gates via tensor products; in sequence you compose gates by ordinary matrix multiplication.
Key ideas
Start from first principles and simple definitions. Bold each term when defined.
Vector: an ordered list of complex numbers written as a column; e.g. a 2-component vector (a, b)^T. Vectors here are usually state vectors for qubits and are dimensionless.
Inner product: for vectors |u> = (u1, u2, ... , un)^T and |v> = (v1, v2, ... , vn)^T, the inner product in the physics/Dirac convention is <u|v> = sum_i conjugate(u_i) v_i (= u† v), which is conjugate-linear in the first (bra) and linear in the second (ket). Some math texts use the opposite convention: <u,v> = sum_i u_i conjugate(v_i). (Be explicit which convention your university uses.) The inner product is linear in one argument and conjugate-linear in the other; its properties: positive-definite, conjugate symmetry, linearity.
Norm (length): the norm of |v> is ||v|| = sqrt(<v|v>). A normalized state has norm 1.
Orthonormal set / basis: a set of vectors { |e_i> } is orthonormal if <e_i|e_j> = 0 for i ≠ j and = 1 for i = j. A complete orthonormal basis spans the space.
Adjoint (conjugate transpose): For a matrix A, the adjoint A† is the complex conjugate transpose. If A = [a_ij], then A† = [conjugate(a_ji)].
Hermitian matrix: A matrix H is Hermitian if H† = H. Hermitian operators have real eigenvalues and orthonormal eigenvectors (spectral theorem).
Unitary matrix: A matrix U is unitary if U† U = U U† = I. Unitary operators preserve inner products and lengths. Eigenvalues of unitary matrices have magnitude 1.
Eigenvalue and eigenvector: v ≠ 0 is an eigenvector of matrix A with eigenvalue λ if A v = λ v.
Outer product: for column vectors |u> and |v>, the outer product |u><v| is a matrix whose (i,j) entry is u_i conjugate(v_j). Projectors are outer products of normalized vectors.
Spectral theorem (finite-dimensional): Any Hermitian matrix H can be written as H = sum_k λ_k |φ_k><φ_k| where λ_k are real eigenvalues and { |φ_k> } form an orthonormal basis. Assumptions: finite-dimensional complex vector space.
Tensor product (Kronecker product): If |a> is m-component and |b> is n-component, their tensor product |a> ⊗ |b> is an mn-component vector formed by multiplying each component of |a> by the whole vector |b>. Standard computational basis order for two qubits is |00>, |01>, |10>, |11>.
Important proofs universities ask for (step-by-step):
Unitary preserves inner products: assume U†U = I. For any |x>, |y> show <U x | U y> = <x | y>.
- Start: <U x | U y> = (U x)† (U y) = x† U† U y.
- Using U† U = I: x† I y = x† y = <x | y>. QED.
Eigenvalues of a unitary have magnitude 1: if U v = λ v, then take inner product v†U†U v = |λ|^2 v† v. But U†U = I so v† v = |λ|^2 v† v, hence |λ|^2 = 1 (since v ≠ 0), so |λ| = 1.
Hermitian ⇒ real eigenvalues: if H v = λ v, then v† H v = λ v† v, but also (v† H v)* = v† H v because H† = H, so λ must be real.
Construction of an orthonormal basis from linearly independent vectors: Gram–Schmidt algorithm (describe steps and give small example in Worked examples).
Diagrams to draw in answers (describe exactly):
- For Gram–Schmidt in R^2: draw x- and y-axes, draw vectors v1 and v2 from origin, draw perpendicular projection from v2 onto v1 (a line along v1) and label projection vector and residual u2. Label angles if needed.
- For tensor-product ordering: draw a 2×2 grid labelled rows=first qubit (0,1) and columns=second qubit (0,1); list basis states in row-major order: top-left |00>, top-right |01>, bottom-left |10>, bottom-right |11>.
Where I am unsure: the physics vs math convention for which slot is conjugate-linear (I have used the physics convention in examples above) — confirm your syllabus convention.
Formulas
<u|v> = sum_i conjugate(u_i) v_i — <u|v> is the inner product of vectors |u>, |v>; dimensionless; applies in finite-dimensional complex vector spaces. We use the physics/Dirac convention here: conjugate-linear in the first (bra) and linear in the second (ket).
||v|| = sqrt(<v|v>) — ||v|| is the norm (length) of |v>; dimensionless; applies to any vector in the space.
|ψ_norm> = |ψ> / ||ψ|| — normalization: divide vector by its norm; dimensionless; used to prepare probability-normalized quantum states.
Prob(measure i) = |<i|ψ>|^2 — probability of obtaining basis state |i> when measuring |ψ>; dimensionless, between 0 and 1; applies when measurement projectors are computational-basis projectors.
A† = conjugate(transpose(A)) — adjoint of matrix A; matrix; applies always for complex matrices.
H† = H — Hermitian condition; H has real eigenvalues; matrix; finite dimensions.
U† U = I — unitary condition; U preserves inner products and norm; matrix; finite dimensions.
A v = λ v — eigenvalue equation; λ may be complex in general; vector v non-zero.
A = sum_k λ_k |φ_k><φ_k| — spectral decomposition for Hermitian A (λ_k real); matrix; assumes finite-dimensional, diagonalizable Hermitian operator.
|a> ⊗ |b> = (a1 b1, a1 b2, ..., a1 bn, a2 b1, ... , am bn)^T — tensor product components in standard ordering; vector; applies to forming multi-qubit states.
|u><v| — outer product; matrix with entries u_i conjugate(v_j); used for projectors and matrix construction.
<U x | U y> = <x | y> — unitarity preserves inner products; follows from U†U = I.
Cauchy–Schwarz: |<u|v>| <= ||u|| ||v|| — inequality used in proofs; dimensionless; applies in inner-product spaces.
Worked examples
Normalise a complex 2-component state and find measurement probabilities. Problem: |ψ> = (1 + i, 2)^T. Normalize and give probability of measuring first component. Steps:
- Compute norm^2 = |1 + i|^2 + |2|^2 = (1^2 + 1^2) + 4 = 2 + 4 = 6.
- Norm = sqrt(6).
- Normalized state |ψ_norm> = (1 + i, 2)^T / sqrt(6).
- Probability of measuring first basis state = |(1 + i)/sqrt(6)|^2 = |1 + i|^2 / 6 = 2 / 6 = 1/3.
- Probability of second = 4/6 = 2/3. Final answer: |ψ_norm> = ((1+i)/√6, 2/√6)^T, probabilities 1/3 and 2/3.
Compute tensor product and interpret ordering. Problem: |ψ> = (1/√2, 1/√2)^T (this is |+>) and |φ> = (1,0)^T (this is |0>). Compute |ψ> ⊗ |φ> and write as superposition of computational basis. Steps:
- Using tensor rule: |ψ> ⊗ |φ> = (1/√2 * 1, 1/√2 * 0, 1/√2 * 1, 1/√2 * 0)^T = (1/√2, 0, 1/√2, 0)^T.
- Standard ordering corresponds to basis [|00>, |01>, |10>, |11>] so state = (|00> + |10>)/√2.
- Final: |ψ>⊗|φ> = (1/√2,0,1/√2,0)^T = (|00> + |10>)/√2.
Gram–Schmidt orthonormalization (small example). Problem: Given v1 = (1,1,0)^T and v2 = (1,0,1)^T in R^3 (viewed as complex vectors with real entries). Produce orthonormal e1, e2. Steps:
- u1 = v1 = (1,1,0). ||u1|| = sqrt(1+1+0) = sqrt(2). e1 = u1/√2 = (1,1,0)/√2.
- Compute projection: <e1|v2> = (1/√2)*(1 + 0 + 0) = 1/√2. proj = (1/√2) e1 = (1/2,1/2,0).
- u2 = v2 - proj = (1,0,1) - (1/2,1/2,0) = (1/2, -1/2, 1).
- ||u2||^2 = 1/4 + 1/4 + 1 = 3/2, so ||u2|| = sqrt(3/2).
- e2 = u2 / sqrt(3/2). Final orthonormal set: e1 = (1,1,0)/√2, e2 = (1/2, -1/2, 1)/√(3/2). (These satisfy <e_i|e_j> = δ_ij.)
Common mistakes
- Wrong ordering in tensor products (swap qubit order) — remember standard basis ordering is |00>, |01>, |10>, |11>.
- Not normalizing states before computing probabilities.
- Treating global phase as measurable — global phase does not change probabilities (only relative phase matters).
- Assuming all matrices are diagonalizable without verifying Hermiticity or normality.
For your exam
Question types you will see: definitions (define inner product, unitary, Hermitian), short notes (Gram–Schmidt, spectral theorem), derivations (prove unitary preserves inner product, eigenvalues of unitary have |λ|=1), numericals (normalize a complex state, tensor products), diagrams (projection in Gram–Schmidt, basis ordering grid), and small proofs (Cauchy–Schwarz or orthonormality of eigenvectors of Hermitian operator).
What a full-marks answer includes: clear statement of assumptions (finite-dimensional complex vector space), explicit definitions (bold or underlined in your notes), step-by-step derivation with intermediate algebra, annotated diagrams where asked, final boxed result and units or dimension comments (states are dimensionless).
Quick check
- If |ψ> = (3, 4)^T, what is ||ψ|| and the normalized state?
- If U is unitary and U|φ> = λ|φ>, what is |λ|?
- Write the tensor product (1,0)^T ⊗ (0,1)^T in computational basis ordering.
Answers: 1) ||ψ|| = 5, |ψ_norm> = (3/5, 4/5)^T. 2) |λ| = 1. 3) (1,0)^T ⊗ (0,1)^T = (0,1,0,0)^T which is |01>.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?