The HHL Algorithm (Introduction)
Suppose you need to solve a linear system with a billion variables. Classical elimination costs time cubic in the system size. Even the best iterative methods scale poorly. This happens when the matrix is large, sparse, and well-conditioned but stubborn. Linear systems of this scale appear everywhere. Finite-element simulations, machine learning regressions, differential-equation solvers, and circuit analysis all reduce to . The HHL algorithm, named for Harrow, Hassidim, and Lloyd, attacks this problem quantum-mechanically. It does not output the vector as a list of numbers. Instead it prepares a quantum state whose amplitudes encode . This uses resources that scale logarithmically in the system dimension under the right conditions. This exponential-looking speedup made HHL a founding result. It suggested quantum computers could accelerate core numerical linear algebra, not just factoring or search. The catch, and the reason this article calls itself an "introduction," is this: HHL solves a different problem than the one you usually want. Reading out the full vector classically would erase any speedup. That readout requires exponentially many measurements. HHL is useful precisely when you want an amplitude-encoded expectation value, like . It is not useful for extracting the raw coordinates of . Understanding this distinction is the single most important conceptual hurdle in the whole algorithm. This article builds HHL from its two main ingredients. These are Quantum Phase Estimation and spectral decomposition of Hermitian Matrices. It walks through the circuit step by step, and proves why it is correct. It analyzes its complexity honestly. It also catalogs the readout caveats that separate textbook enthusiasm from practical deployment.
- HHL encodes the solution of as amplitudes of a quantum state , not as classical numbers.
- It uses quantum phase estimation to extract eigenvalues of , then a controlled rotation to invert them.
- Runtime scales like under sparsity and conditioning assumptions, versus polynomial-in- classically.
- The exponential speedup applies only to reading out expectation values, not the full vector .
- must be Hermitian (or made Hermitian by a standard embedding trick) and efficiently simulable.
- Condition number and sparsity dominate the cost; ill-conditioned systems erase the advantage.
HHL turns matrix inversion into phase estimation followed by a controlled rotation that maps each eigenvalue to an amplitude proportional to , producing a normalized quantum state proportional to — usable directly only when you need scalar summaries of , not itself.
The idea
The goal is to solve where is an Hermitian matrix and . Encode as a quantum state on qubits, normalized so . The target is the state
Since is Hermitian it has a spectral decomposition with real eigenvalues and orthonormal eigenvectors . Writing in this eigenbasis as , the formal inverse acts eigenvalue-wise:
HHL's central trick is to implement this eigenvalue-wise inversion using Quantum Phase Estimation to read into an ancilla register, a controlled rotation conditioned on that ancilla to multiply the amplitude by something proportional to , and then uncomputation of the ancilla so the eigenvalue information is discarded while its effect on the amplitude survives. This is a coherent, reversible way of applying a non-unitary operator ( is not unitary in general) inside a unitary quantum circuit, using post-selection on an ancilla flag. If is not Hermitian, a standard embedding restores Hermiticity: define
which is Hermitian, and solve with ; the lower half of the solution recovers up to sign convention. This means Hermiticity is not really a restriction — it costs only a qubit and a reindexing.
How it works
HHL uses three registers: a clock register of qubits for phase estimation, a single ancilla qubit for the rotation, and the -qubit input register holding and eventually . The algorithm assumes access to two black-box subroutines: a way to prepare , and a way to implement for controllable time — Hamiltonian simulation of . Both are assumed efficient; this assumption is itself a major caveat discussed below.
Step 1 — State preparation. Prepare the input register in state . In the eigenbasis of this is , though the algorithm never needs to know the or explicitly.
Step 2 — Phase estimation. Apply quantum phase estimation using the unitary for a fixed simulation time . Since is an eigenvector of with eigenvalue , it is an eigenvector of with eigenvalue . Phase estimation writes an approximation of into the clock register, entangling it with :
Step 3 — Controlled rotation. Introduce the ancilla qubit initialized to , and apply a controlled rotation conditioned on the clock register value :
where is a normalization constant chosen smaller than the smallest eigenvalue magnitude to keep the square root real. This is implementable by a sequence of controlled rotations, one per possible clock value, each computing the needed angle classically ahead of time.
Step 4 — Uncompute phase estimation. Apply the inverse of the phase estimation circuit. Because the clock register was only used to control the rotation, and the rotation did not alter which eigenvector branch we are in, inverse phase estimation disentangles the clock register back to (up to phase-estimation approximation error), leaving
Step 5 — Measure the ancilla. Measure the ancilla qubit. Conditioned on outcome , which occurs with probability , the input register collapses (up to normalization) to
which is exactly up to normalization. This is the crux: postselecting on the ancilla is what implements the non-unitary inversion inside an otherwise unitary circuit. ``` Algorithm HHL(A, b, t): Input: A : N x N Hermitian matrix, N = 2^n, sparsity s, condition number kappa b : classical description sufficient to prepare state |b> on n qubits t : number of clock qubits for phase estimation (precision control) Output: Quantum state |x> proportional to A^{-1}|b> (NOT a classical vector) 1. Allocate registers: clock <- t qubits, initialized |0...0> anc <- 1 qubit, initialized |0> input <- n qubits, initialized |0...0> 2. Prepare input register: input <- |b> // via a state-preparation oracle 3. Phase estimation of U = exp(i A t0): clock, input <- PhaseEstimation(U, input, clock) // entangles clock with eigenbasis of A: // sum_j beta_j |u_j> |lambda_tilde_j> 4. Controlled rotation on ancilla, conditioned on clock register value L: for each computational basis value L of clock register: theta(L) <- 2 * arcsin( C / lambda_from(L) ) // precomputed classically apply controlled-Ry(theta(L)) on anc, controlled by clock == L 5. Uncompute phase estimation: clock, input <- InversePhaseEstimation(U, input, clock) // clock returns (approximately) to |0...0> 6. Measure anc in computational basis: if outcome == 1: input register now holds state proportional to A^{-1}|b> = |x> ACCEPT else: discard and retry from step 2 // postselection failure 7. Return input register (as a quantum state, to be consumed by a subsequent expectation-value estimation circuit, not read out directly) ```
Complexity & correctness
Correctness argument. The proof rests on linearity and the eigenbasis decomposition. Because is Hermitian, forms an orthonormal basis, so every step of the circuit can be analyzed eigenvector-by-eigenvector and then summed by linearity of the unitary operations. Phase estimation is exact in the limit of infinite clock qubits: it maps exactly when is exactly representable in bits, and approximately otherwise, with error analyzed in the Quantum Phase Estimation article. The controlled rotation is a deterministic, coherent function of the clock register value, so it commutes correctly with the entangled superposition — each branch receives its own correctly computed angle . Uncomputing phase estimation is valid because the rotation did not touch the clock or input registers, only entangled a new ancilla with the already-existing clock value; inverting the exact same unitary used to create the clock entanglement returns the clock to in each branch, leaving the eigenvector label undisturbed. Finally, projecting the ancilla onto selects exactly the amplitude component from each branch, which is by construction the action of in the eigenbasis. No step requires knowing the eigenvalues or eigenvectors classically; they only ever appear encoded in superposition.
Success probability. The probability of measuring ancilla is
Choosing where is the condition number keeps the rotation argument valid for the smallest eigenvalue, but it also makes in the worst case. Amplitude amplification, using the same reasoning as Grover's Algorithm, boosts this to repetitions instead of by amplifying the amplitude linearly instead of relying on repeated sampling of the squared probability.
Time complexity derivation. Three costs stack up. 1. Hamiltonian simulation. Implementing for an -sparse Hermitian matrix costs using standard sparse Hamiltonian simulation techniques (product formulas or more advanced methods), where is the simulation error tolerance. 2. Phase estimation precision. To resolve eigenvalues to relative precision sufficient for the controlled rotation to be accurate, the clock register needs qubits, and phase estimation must run for evolution time to distinguish eigenvalues spanning the range down to . 3. Amplitude amplification. Boosting success probability from to costs a multiplicative factor of in repetitions of the whole circuit. Multiplying these factors, the total runtime is
in the original 2009 analysis (later refinements using improved Hamiltonian simulation and variable-time amplitude amplification reduce the dependence toward linear, and the dependence toward logarithmic, but the qualitative shape — polylog in , polynomial in and — persists). The key point is the scaling: for classical general-purpose Gaussian elimination, cost is ; even fast sparse conjugate-gradient methods cost . HHL trades polynomial dependence on for polynomial dependence on and , which is a genuine exponential speedup in when and are modest.
Space complexity. The circuit uses qubits: for the input register, for the clock, and one ancilla. This is exponentially smaller than the classical numbers needed to write down explicitly — which is exactly why HHL cannot simply hand you without destroying the speedup.
Honest tradeoffs.
- The speedup is conditional on being efficiently simulable — dense, unstructured matrices with no exploitable sparsity or structure do not admit efficient Hamiltonian simulation, and the whole algorithm stalls at the first step.
- The speedup degrades quadratically (pre-amplification) or linearly (post-amplification) in the condition number ; for ill-conditioned systems ( growing with ), the advantage can vanish entirely.
- State preparation of is assumed efficient; if is an arbitrary classical vector with no succinct description, preparing can itself cost , erasing the speedup before the algorithm even starts.
- Reading out fully costs via state tomography, again erasing the advantage — usable output is restricted to expectation values for some observable , or sampling-based summary statistics.
Worked example
Take a small, fully traceable instance. Let
is Hermitian (real symmetric) with eigenvalues and eigenvectors:
Condition number — a friendly, well-conditioned case, chosen deliberately non-symmetric in its input so the eigen-decomposition step is non-trivial. Expand in the eigenbasis:
| Step | Quantity | Value |
|---|---|---|
| Eigenvalues found by QPE | ||
| Amplitude in eigenbasis | ||
| After controlled rotation, unnormalized coefficient of | ||
| Post-measurement state (unnormalized) in eigenbasis | — | |
| Normalize | — | divide by |
| Final | — |
Convert back to the computational basis:
Check against classical inversion: , so
which normalizes to exactly — matching the HHL output state. This confirms the algorithm reproduces the correctly normalized solution direction; the overall scale (the classical prefactor) is discarded, because quantum states are normalized by construction. Any application of HHL must separately extract this scale (e.g. via the ancilla acceptance probability , which is proportional to ) if the magnitude of matters and not just its direction.
Common pitfalls & traps
| Pitfall | Why it happens | Consequence |
|---|---|---|
| Expecting classical output | Confusing "solved the linear system" with "printed the vector" | Full readout costs , erasing the exponential speedup |
| Ignoring condition number scaling | Treating as a constant | Runtime blows up on ill-conditioned systems; algorithm becomes worse than classical |
| Forgetting the rotation constraint | Choosing larger than | argument exceeds 1, rotation undefined/non-unitary in that branch |
| Assuming arbitrary is simulable | Overlooking the sparsity/structure requirement for Hamiltonian simulation | Step 2 becomes classically as expensive as solving the system directly |
| Assuming -state prep is free | Treating preparation as a black box with no cost | Hidden cost dominates, negating claimed speedup |
| Skipping postselection accounting | Not tracking | Underestimates total number of circuit repetitions needed |
Pioneers & history
Origins · 1 minSeth Lloyd and how this was discovered
Lloyd's earlier work on efficient quantum simulation of local Hamiltonians — showing that a quantum computer could simulate physical systems exponentially faster than classical methods — supplied the Hamiltonian-simulation subroutine that HHL depends on for implementing . This connection between simulation and linear algebra was the conceptual bridge that made HHL possible.
Where this matters
HHL is foundational to the broader research program of quantum linear algebra, which underlies many proposed quantum machine learning algorithms: quantum support vector machines, quantum principal component analysis, and quantum recommendation systems all use HHL-style matrix inversion as a subroutine, extracting an expectation value or classification decision rather than the raw solution vector. It also motivates ongoing research into Hamiltonian simulation methods, since HHL's practical runtime is bottlenecked by how efficiently can be implemented for the matrices that arise in applications — a topic tightly linked to Quantum Simulation more broadly. In finance and engineering, HHL-inspired algorithms have been proposed for solving discretized partial differential equations (e.g. in computational fluid dynamics) where the matrix comes from a sparse finite-difference stencil with modest condition number, precisely the regime where the algorithm's assumptions are most plausible. Equally important is HHL's role as a cautionary case study: the 2018 "dequantization" results, showing certain claimed speedups can be matched classically under comparable sampling assumptions, taught the field to scrutinize input/output models as carefully as the quantum circuit itself — a methodological lesson that now shapes how every new quantum algorithm, including those built on Quantum Phase Estimation, is evaluated for genuine advantage.
Ask the tutor: How does amplitude amplification concretely boost HHL's success probability from to ?
Does HHL actually give an exponential speedup over classical linear solvers?
Yes, but conditionally. HHL's circuit depth scales as , versus for classical conjugate-gradient methods — an exponential improvement in the dimension . But this comparison is only fair when you want an expectation value from , since classical methods output the full vector while HHL outputs only a quantum state. If you need the entire classical vector, tomographic readout costs on the quantum side too, eliminating the advantage. The speedup is real but narrowly scoped to summary-statistic use cases, not general-purpose solving.
What happens if A is not Hermitian?
You embed into a larger Hermitian matrix using the standard trick , and solve with . The resulting solution's lower block recovers . This costs only one extra qubit to double the register size, so non-Hermiticity is a minor technical inconvenience rather than a fundamental obstruction, though it does double the effective dimension used in the phase estimation and simulation steps.
Why is the condition number κ so important to HHL's cost?
The controlled rotation step needs the constant to satisfy so that every stays within the valid range. Setting this small makes the success probability of the ancilla measurement scale as in the worst case, since small eigenvalues get amplitude that is close to the maximum allowed value only near itself, and small elsewhere. Amplitude amplification reduces this penalty to repetitions, but the dependence never disappears — ill-conditioned matrices remain fundamentally expensive.
What does "amplitude-encoded" mean, and why does it matter for readout?
A quantum state stores complex numbers in the amplitudes of qubits, but quantum mechanics only allows you to extract information about those amplitudes through measurement statistics, not direct readout. Measuring collapses the state and yields one sample from a probability distribution given by , so extracting every amplitude to precision requires roughly measurements via state tomography. This is why HHL's speedup applies only when the downstream task needs a single scalar (an expectation value), which can be estimated with far fewer measurements than full tomography.
Can HHL be simulated efficiently on a classical computer, defeating its purpose?
In special cases, yes — this is the "dequantization" phenomenon. If is low-rank, or if there is efficient classical sampling access to its rows and columns (an -norm sampling oracle), classical randomized linear algebra can approximate the same expectation values in time polynomial in the rank and polylogarithmic in , matching HHL's asymptotic profile. For general sparse, high-rank, well-conditioned matrices without such sampling access, no known classical dequantization applies, and the quantum algorithm's advantage is believed to persist, though this remains an active area of complexity-theoretic study.
Does HHL require a fault-tolerant quantum computer to run in practice?
Effectively yes, for problem sizes where a classical solver would struggle. Phase estimation needs coherent evolution under for times scaling with , and this evolution must be implemented with error well below to avoid corrupting the eigenvalue estimate. On near-term noisy devices without error correction, this level of coherent control is far beyond current capability for anything but toy-sized matrices, which is why HHL remains primarily a theoretical benchmark and a component of algorithmic proposals rather than a deployed production algorithm today.
How does HHL relate to Quantum Phase Estimation and eigen-decomposition?
HHL is best understood as an application layer built entirely on top of two known primitives. Quantum Phase Estimation extracts eigenvalues of a Hermitian operator into an ancillary register in superposition, and the spectral theorem for Hermitian Matrices guarantees that any input vector decomposes cleanly into eigenvector components that can be manipulated independently and then recombined by linearity. HHL contributes the controlled-rotation trick that turns "we know the eigenvalue" into "we've multiplied the corresponding amplitude by ," which is the one genuinely new ingredient beyond phase estimation itself.