Linear Algebra for Quantum Computing
An interactive refresher covering the essential linear algebra you need. Work through each section, try the interactive tools, and test yourself with quizzes.
1 Complex Numbers
The number system underlying all of quantum mechanics.
A complex number has the form $z = a + bi$, where $a, b \in \mathbb{R}$ and $i = \sqrt{-1}$. We call $a = \text{Re}(z)$ the real part and $b = \text{Im}(z)$ the imaginary part.
- Addition: $(a+bi)+(c+di) = (a+c) + (b+d)i$
- Multiplication: $(a+bi)(c+di) = (ac-bd) + (ad+bc)i$
- Complex conjugate: $\bar{z} = z^* = a - bi$
- Modulus: $|z| = \sqrt{a^2+b^2} = \sqrt{z\bar{z}}$
- Euler form: $z = re^{i\theta}$ where $r=|z|$ and $\theta = \text{arg}(z)$
Quantum states are vectors with complex amplitudes. A qubit state $|\psi\rangle = \alpha|0\rangle + \beta|1\rangle$ has $\alpha, \beta \in \mathbb{C}$ with $|\alpha|^2 + |\beta|^2 = 1$. The phases of these complex numbers encode information that leads to interference — the heart of quantum computation.
Worked Example: Multiplying complex numbers
Problem: Compute $(1+2i)(3-i)$.
Step 1: Expand using FOIL:
$(1)(3) + (1)(-i) + (2i)(3) + (2i)(-i)$
$= 3 - i + 6i - 2i^2$
Step 2: Replace $i^2 = -1$:
$= 3 - i + 6i + 2 = 5 + 5i$
2 Vectors & Dirac Notation
The language of quantum states.
A vector in $\mathbb{C}^n$ is an ordered $n$-tuple of complex numbers. In quantum computing, we primarily work in $\mathbb{C}^2$ (single qubit) and $\mathbb{C}^{2^n}$ ($n$ qubits).
| Name | Symbol | Meaning |
|---|---|---|
| Ket | $|\psi\rangle$ | Column vector (state) |
| Bra | $\langle\psi|$ | Conjugate transpose (row vector) |
| Bracket | $\langle\phi|\psi\rangle$ | Inner product (scalar) |
| Outer product | $|\psi\rangle\langle\phi|$ | Matrix (operator) |
The computational basis for a single qubit is:
Any single-qubit state can be written as $|\psi\rangle = \alpha|0\rangle + \beta|1\rangle$ — a superposition.
Important Basis States
Worked Example: Writing a state in Dirac notation
Problem: Express $\begin{pmatrix} \frac{1}{\sqrt{3}} \\ \frac{i\sqrt{2}}{\sqrt{3}} \end{pmatrix}$ in Dirac notation.
Solution:
$|\psi\rangle = \frac{1}{\sqrt{3}}|0\rangle + \frac{i\sqrt{2}}{\sqrt{3}}|1\rangle$
Verify normalization: $|\alpha|^2 + |\beta|^2 = \frac{1}{3} + \frac{2}{3} = 1$ ✔
The normalization constraint $\langle\psi|\psi\rangle = 1$ reflects the fact that measurement probabilities must sum to 1. The probability of measuring outcome $|k\rangle$ is $|\langle k|\psi\rangle|^2$.
3 Inner Products
Measuring angles, lengths, and probabilities.
The inner product of two vectors $|u\rangle, |v\rangle \in \mathbb{C}^n$ is:
- Conjugate symmetry: $\langle u|v\rangle = \overline{\langle v|u\rangle}$
- Linearity in 2nd argument: $\langle u|\alpha v + \beta w\rangle = \alpha\langle u|v\rangle + \beta\langle u|w\rangle$
- Positive definite: $\langle v|v\rangle \geq 0$, with equality iff $|v\rangle = \mathbf{0}$
- Norm: $\||v\rangle\| = \sqrt{\langle v|v\rangle}$
Two vectors are orthogonal if $\langle u|v\rangle = 0$. A set of vectors is orthonormal if each pair is orthogonal and each vector has norm 1.
Linear Independence & Bases
A set of vectors $\{|v_1\rangle, \ldots, |v_n\rangle\}$ is linearly independent if no vector can be written as a combination of the others. Formally: $\sum_i c_i |v_i\rangle = 0$ implies all $c_i = 0$.
- A basis for $\mathbb{C}^n$ is a set of $n$ linearly independent vectors
- Any vector can be uniquely written as a linear combination of basis vectors
- An orthonormal basis (ONB) makes computations easy: coefficients are just inner products $c_k = \langle e_k|\psi\rangle$
Every measurement corresponds to choosing an orthonormal basis. The computational basis $\{|0\rangle, |1\rangle\}$ is orthonormal ($\langle 0|1\rangle = 0$, $\langle 0|0\rangle = \langle 1|1\rangle = 1$), and the X-basis $\{|+\rangle, |-\rangle\}$ is another. Changing your measurement basis is equivalent to changing which question you ask the qubit! The inner product $\langle\phi|\psi\rangle$ gives the transition amplitude from $|\psi\rangle$ to $|\phi\rangle$, and $|\langle\phi|\psi\rangle|^2$ is the probability of finding the system in state $|\phi\rangle$.
Worked Example: Inner product computation
Problem: Compute $\langle u|v\rangle$ where $|u\rangle = \begin{pmatrix} 1 \\ i \end{pmatrix}$ and $|v\rangle = \begin{pmatrix} 2 \\ 1+i \end{pmatrix}$.
Step 1: Form $\langle u| = \begin{pmatrix} \bar{1} & \overline{i} \end{pmatrix} = \begin{pmatrix} 1 & -i \end{pmatrix}$
Step 2: Compute: $\langle u|v\rangle = (1)(2) + (-i)(1+i) = 2 + (-i - i^2) = 2 + (-i + 1) = 3 - i$
4 Matrices
Operators that transform quantum states.
A matrix $A \in \mathbb{C}^{m \times n}$ is a rectangular array of complex numbers. Matrices act on vectors via multiplication: $A|v\rangle$ produces a new vector.
- Transpose: $(A^T)_{ij} = A_{ji}$ — flip rows and columns
- Complex conjugate: $(\bar{A})_{ij} = \overline{A_{ij}}$
- Conjugate transpose (adjoint): $A^\dagger = \overline{A^T}$ — crucial in QC!
- Matrix product: $(AB)_{ij} = \sum_k A_{ik}B_{kj}$
- Trace: $\text{tr}(A) = \sum_i A_{ii}$
- Determinant (2×2): $\det\begin{pmatrix}a&b\\c&d\end{pmatrix} = ad-bc$
Matrix multiplication is not commutative: in general $AB \neq BA$. This is physically significant in quantum mechanics — the order in which you apply gates matters!
The 2×2 Identity and Pauli Matrices
These form a basis for all 2×2 matrices and correspond to fundamental single-qubit gates.
Worked Example: Applying a gate to a qubit
Problem: Apply the Hadamard gate $H = \frac{1}{\sqrt{2}}\begin{pmatrix}1&1\\1&-1\end{pmatrix}$ to $|0\rangle$.
Solution:
$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} = |+\rangle$
The Hadamard gate creates an equal superposition from a basis state!
5 Eigenvalues & Eigenvectors
The states that survive a transformation (up to scaling).
A non-zero vector $|v\rangle$ is an eigenvector of matrix $A$ with eigenvalue $\lambda$ if:
The matrix scales $|v\rangle$ without changing its direction.
Solve the characteristic equation:
$$\det(A - \lambda I) = 0$$For $A = \begin{pmatrix}a&b\\c&d\end{pmatrix}$, this gives:
$$\lambda^2 - (a+d)\lambda + (ad-bc) = 0$$Then find eigenvectors by solving $(A-\lambda I)|v\rangle = 0$ for each $\lambda$.
Observable quantities in quantum mechanics correspond to Hermitian matrices, and their eigenvalues are the possible measurement outcomes. After measurement, the system collapses to the corresponding eigenvector. For example, the eigenvalues of $Z$ are $+1$ and $-1$, with eigenvectors $|0\rangle$ and $|1\rangle$.
Worked Example: Eigenvalues of the Pauli Z matrix
Problem: Find the eigenvalues and eigenvectors of $Z = \begin{pmatrix}1&0\\0&-1\end{pmatrix}$.
Step 1 — Characteristic equation:
$\det(Z - \lambda I) = (1-\lambda)(-1-\lambda) = 0$
$\Rightarrow \lambda_1 = 1, \quad \lambda_2 = -1$
Step 2 — Eigenvectors:
For $\lambda_1=1$: $(Z-I)|v\rangle=0 \Rightarrow \begin{pmatrix}0&0\\0&-2\end{pmatrix}\begin{pmatrix}a\\b\end{pmatrix}=0 \Rightarrow b=0 \Rightarrow |v_1\rangle = |0\rangle$
For $\lambda_2=-1$: $(Z+I)|v\rangle=0 \Rightarrow \begin{pmatrix}2&0\\0&0\end{pmatrix}\begin{pmatrix}a\\b\end{pmatrix}=0 \Rightarrow a=0 \Rightarrow |v_2\rangle = |1\rangle$
6 Tensor Products
Combining quantum systems.
The tensor product (or Kronecker product) $\otimes$ is how we build multi-qubit state spaces from single-qubit ones. If $|u\rangle \in \mathbb{C}^m$ and $|v\rangle \in \mathbb{C}^n$, then $|u\rangle \otimes |v\rangle \in \mathbb{C}^{mn}$.
For vectors:
$$\begin{pmatrix}a_1\\a_2\end{pmatrix} \otimes \begin{pmatrix}b_1\\b_2\end{pmatrix} = \begin{pmatrix}a_1 b_1\\a_1 b_2\\a_2 b_1\\a_2 b_2\end{pmatrix}$$For matrices, $A \otimes B$ replaces each entry $a_{ij}$ with the block $a_{ij}B$.
Shorthand: $|0\rangle \otimes |1\rangle = |0\rangle|1\rangle = |01\rangle$.
Entanglement
A state that cannot be written as a tensor product of individual qubit states is called entangled. The most famous example:
You cannot find $|a\rangle, |b\rangle$ such that $|a\rangle \otimes |b\rangle = |\Phi^+\rangle$. This is a uniquely quantum phenomenon!
Worked Example: Tensor product of two qubits
Problem: Compute $|+\rangle \otimes |0\rangle$.
Solution:
$|+\rangle \otimes |0\rangle = \frac{1}{\sqrt{2}}\begin{pmatrix}1\\1\end{pmatrix} \otimes \begin{pmatrix}1\\0\end{pmatrix} = \frac{1}{\sqrt{2}}\begin{pmatrix}1 \cdot 1\\1 \cdot 0\\1 \cdot 1\\1 \cdot 0\end{pmatrix} = \frac{1}{\sqrt{2}}\begin{pmatrix}1\\0\\1\\0\end{pmatrix}$
In Dirac notation: $\frac{1}{\sqrt{2}}(|00\rangle + |10\rangle)$.
7 Special Matrices
The matrices with physical meaning.
| Type | Condition | Quantum Role |
|---|---|---|
| Hermitian | $A = A^\dagger$ | Observables (measurements) |
| Unitary | $UU^\dagger = U^\dagger U = I$ | Quantum gates |
| Normal | $AA^\dagger = A^\dagger A$ | Diagonalizable |
| Projection | $P^2 = P = P^\dagger$ | Measurement projectors |
Hermitian Matrices
A matrix $A$ is Hermitian if $A = A^\dagger$. Key properties:
- All eigenvalues are real
- Eigenvectors for distinct eigenvalues are orthogonal
- Can always be diagonalized: $A = \sum_i \lambda_i |v_i\rangle\langle v_i|$ (spectral decomposition)
Unitary Matrices
A matrix $U$ is unitary if $UU^\dagger = I$. Key properties:
- Preserves inner products: $\langle U\phi|U\psi\rangle = \langle\phi|\psi\rangle$
- Preserves norms: $\|U|v\rangle\| = \||v\rangle\|$
- All eigenvalues have $|\lambda| = 1$ (lie on the unit circle)
All quantum gates are unitary — this guarantees that valid quantum states remain valid after a gate is applied ($|\alpha|^2+|\beta|^2$ stays 1). Quantum evolution is reversible: applying $U^\dagger$ undoes $U$.
Worked Example: Verifying unitarity of the Hadamard gate
Problem: Verify that $H = \frac{1}{\sqrt{2}}\begin{pmatrix}1&1\\1&-1\end{pmatrix}$ is unitary.
Step 1: Since $H$ is real and symmetric, $H^\dagger = H^T = H$.
Step 2: Compute $HH^\dagger = HH$:
$HH = \frac{1}{2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}\begin{pmatrix}1&1\\1&-1\end{pmatrix} = \frac{1}{2}\begin{pmatrix}2&0\\0&2\end{pmatrix} = \begin{pmatrix}1&0\\0&1\end{pmatrix} = I$ ✔
Therefore $H$ is unitary (and also Hermitian since $H = H^\dagger$).
8 Putting It All Together
A complete quantum computing example using everything you've learned.
Let's trace through a simple quantum circuit that demonstrates superposition and measurement.
Step 1 — Initialize: Start with $|0\rangle = \begin{pmatrix}1\\0\end{pmatrix}$
Step 2 — Apply Hadamard:
$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} = |+\rangle$
Step 3 — Apply Phase gate: $S = \begin{pmatrix}1&0\\0&i\end{pmatrix}$
$S|+\rangle = \begin{pmatrix}1&0\\0&i\end{pmatrix}\frac{1}{\sqrt{2}}\begin{pmatrix}1\\1\end{pmatrix} = \frac{1}{\sqrt{2}}\begin{pmatrix}1\\i\end{pmatrix}$
Step 4 — Measure in Z-basis:
$P(|0\rangle) = \left|\frac{1}{\sqrt{2}}\right|^2 = \frac{1}{2}, \qquad P(|1\rangle) = \left|\frac{i}{\sqrt{2}}\right|^2 = \frac{1}{2}$
Equal probabilities — the phase $i$ doesn't affect Z-measurement probabilities!
Step through a quantum circuit one gate at a time. Watch how the state vector transforms at each step.
Linear Algebra Checklist for Quantum Computing
You're ready to dive into quantum computing if you can:
- Multiply complex numbers and find conjugates/moduli
- Perform matrix-vector multiplication
- Compute inner products and check orthogonality
- Find eigenvalues and eigenvectors of 2×2 matrices
- Compute tensor products of small vectors/matrices
- Verify whether a matrix is unitary or Hermitian
- Read and write in Dirac bra-ket notation