HHL Linear Systems Algorithm
The HHL algorithm is the moment quantum computing stopped being about counting oracle queries and started making a claim on the everyday work of numerical science: solving . Almost every simulation, every regression, every discretized differential equation bottoms out in a linear system, and classically the cost of solving one grows at least linearly with the number of unknowns — touch every entry of the answer and you have already paid . Harrow, Hassidim, and Lloyd's 2009 construction refuses to pay that. It never writes the solution down. Instead it encodes the entire -component vector into the amplitudes of an qubit state , and it manufactures that state in time polylogarithmic in . A million-dimensional system lives in twenty qubits; a billion-dimensional one in thirty. The engine is spectral. Written in its own eigenbasis, , and solving means nothing more than dividing each component of by its eigenvalue . A classical machine does those divisions one at a time; HHL does all at once. Quantum phase estimation on the unitary tags every eigenvector with its eigenvalue in an ancillary register, a single controlled rotation writes an amplitude proportional to , and running phase estimation backwards erases the scratch work — leaving a state proportional to . The whole matrix inversion happens in superposition, in one pass. Three caveats keep the claim honest, and understanding them is understanding HHL. The output is a quantum state, so reading all amplitudes by tomography costs and erases the speedup — the win is real only for a summary property . The runtime carries the condition number and the sparsity , so ill-conditioned or dense systems bleed the advantage away. And the whole edifice assumes coherent oracle access to and efficient preparation of . Far from weakening the result, these conditions are what make it precise: HHL draws the exact boundary of where quantum computers deliver exponential advantage in linear algebra.
- HHL prepares a quantum state whose amplitudes are the (normalized) entries of the solution to , for an Hermitian, -sparse, well-conditioned matrix .
- The original runtime is — exponentially faster in the dimension than the of classical conjugate gradient.
- The mechanism is quantum phase estimation on , which loads each eigenvalue into an ancilla, followed by a controlled rotation that writes an amplitude , then uncomputation.
- The speedup is genuine only for extracting a global property ; full read-out by tomography costs and destroys the advantage.
- The condition number enters because the inversion succeeds with probability ; amplitude amplification softens repetitions to .
- Later work (Ambainis; Childs–Kothari–Somma) cut the dependence to , and HHL is now the seed of the whole field of quantum linear algebra.
- Key idea: phase estimation on transfers each eigenvalue of into an ancilla register, a controlled rotation writes an amplitude , and uncomputing the register leaves a state proportional to — the entire spectral inversion carried out in superposition.
Phase estimation on transfers each eigenvalue of into an ancilla register; a controlled rotation then writes an amplitude , so that uncomputing the eigenvalue register leaves a state proportional to . The entire spectral inversion is done in superposition.
Where this lives today
HHL is small enough to demonstrate and deep enough to seed a field. Its 2×2 and larger instances have been run on photonic processors (Cai and collaborators, 2013), on NMR, and on superconducting devices, each showing the full choreography — state preparation, phase estimation, controlled rotation, uncomputation — in one compact circuit, precisely because a working run is a proof of concept for coherent linear algebra. But the living importance is in what HHL became. It is the archetype of the quantum linear systems problem, now understood through block-encoding and the quantum singular value transformation, where solving , simulating Hamiltonians, and estimating spectra are all read off from one unifying framework that traces directly back to the HHL rotation . HHL-style subroutines drive quantum solvers for linear differential equations (Berry; Childs–Liu–Ostrander), quantum algorithms for least squares and finite-element analysis, and proposed speedups in machine learning — support-vector machines, Gaussian processes, recommendation systems. That last frontier is where the caveats bite hardest: Ewin Tang's dequantization program produced classical sampling algorithms matching several HHL-based proposals, turning the "fine print" into an active research boundary that continually re-tests where quantum advantage in linear algebra genuinely lives. The open problem — for which practically important, well-conditioned, sparse systems the input can be loaded and the output extracted without erasing the speedup — is as central now as it was in 2009.
The physical picture
Picture the matrix in its own eigenbasis, where it is simply a list of multipliers: the eigenvector gets scaled by . Solving is then the most elementary act imaginable — take the input , and divide each spectral component by its eigenvalue to get . The classical difficulty is that the eigenbasis is hidden: you would have to diagonalize first, an chore. HHL's sleight of hand is that it never diagonalizes anything. Quantum phase estimation, run on the unitary that Hamiltonian simulation builds from , acts diagonally on each automatically — it writes the eigenvalue into a clock register without anyone ever computing an eigenvector. Every eigen-branch is processed in parallel because they all ride the same superposition.
The controlled rotation is the algorithm's one genuinely clever move. Conditioned on the clock register holding , a single ancilla qubit is rotated by , depositing amplitude exactly on its branch. A large eigenvalue gives a small amplitude, a small eigenvalue a large one — precisely the scaling that inverts . Post-selecting that flag ancilla on keeps only the inverted branch, but the probability of landing there is , and the smallest eigenvalue forces . That single constraint is the taproot of every in the cost. The payoff is the exponential compression of dimension into qubits — and its flip side, the reason you can never cheaply read the answer back out, is drawn in the second figure.
The core equations
The problem is the most familiar one in computational science, with three structural assumptions attached. is Hermitian so that phase estimation is well-defined; sparse so that can be simulated in polylogarithmic time; and well-conditioned so the inversion does not blow up.
where: — Hermitian, -sparse matrix with condition number ; — right-hand side, loaded as ; — solution, delivered as ; — condition number. Reading: a non-Hermitian is first embedded in a Hermitian dilation, so Hermiticity costs nothing in generality. Everything happens in the eigenbasis of , even though it is never computed. The spectral theorem hands us a real spectrum and an orthonormal eigenbasis, and the input decomposes along it.
where: — -th real eigenvalue of ; — orthonormal eigenvector; — overlap of with . Reading: HHL processes each branch independently and in parallel, which is why the target below is a term-by-term division. Inverting is nothing but dividing each spectral coefficient by its eigenvalue — the operation the controlled rotation will realize physically.
where: — the inverse eigenvalue, the multiplier that turns into along the -th axis. Reading: the whole algorithm is a physical device for writing the amplitudes without ever isolating a single . Phase estimation of the simulated unitary is the eigenvalue-reading engine: because , it writes a binary estimate of into a clock register entangled with .
where: — unitary from Hamiltonian simulation of ; — -qubit register storing to bits; — evolution time fixed so , setting the eigenvalue resolution. Reading: bits of clock give eigenvalue precision , and resolving needs qubits. The controlled rotation performs . A flag ancilla is rotated by an angle read off the clock, so its amplitude comes out inversely proportional to the eigenvalue.
where: — normalization constant obeying so that ; — flag whose post-selection keeps the inverted branch. Reading: , so the flag amplitude is exactly proportional to ; the cap is the sole reason the success probability is small. Uncomputing the clock and post-selecting the flag on leaves the input register holding the solution, up to phase-estimation error.
where: — normalized solution state after uncomputation and post-selection. Reading: the surviving amplitudes are up to the global constant , which is exactly renormalized. The flag reads with probability set by the branch weights, which is where enters and where amplitude amplification buys it back.
where: — probability of measuring the flag in ; — number of amplitude-amplification rounds. Reading: naive repetition costs runs, but amplifying the flagged branch reduces this quadratically to — the linear-in- factor of modern HHL. Assembling Hamiltonian simulation, phase estimation, and amplification gives the runtime, together with its later improvement and the honest classical comparison.
where: — row sparsity; — target precision; — soft-O suppressing log factors; — conjugate gradient on a sparse positive-definite system. Reading: the decisive change is ; the useful output is a global property , since anything requiring all amplitudes reinstates the classical cost.
The goal is to track the complete quantum state — clock, input, and flag registers together — from the initial product through phase estimation, the controlled rotation, uncomputation, and post-selection, and to prove that what survives is proportional to . Working entirely in the eigenbasis of makes every step a diagonal action on the branches, so the argument is exact rather than schematic, and it exposes exactly where phase-estimation error enters.
Step 1. Expand the input in the eigenbasis and set all ancillas to zero: the state is . Why: any vector expands in the orthonormal eigenbasis, and writing it this way lets us follow each eigen-branch separately, since every gate below acts diagonally on .
Step 2. Apply phase estimation of to the clock and input registers, giving . Why: , so QPE writes the eigenphase into the clock; this is the only place the matrix enters the amplitudes, and it enters as an eigenvalue label, not as a stored eigenvector.
Step 3. Adjoin the flag and apply the controlled rotation conditioned on the clock, producing . Why: the flag amplitude on is now , inversely proportional to the eigenvalue — the physical realization of the term-by-term division in equation (3).
Step 4. Run phase estimation in reverse to disentangle and reset the clock to , leaving . Why: the clock has done its job of controlling the rotation; uncomputing it un-entangles the eigenvalue register so the final state is a clean product of input and flag, at the cost of the small error incurred when .
Step 5. Measure the flag and condition on the outcome , projecting onto . Why: post-selection keeps only the inverted-amplitude branch and renormalizes it; the surviving amplitudes are , precisely the spectral coefficients of .
Step 6. Identify the result: in the ideal limit the state is . Why: dividing every eigen-coefficient of by its eigenvalue and renormalizing is the definition of the normalized solution, so the circuit has solved in the amplitude encoding. *In the ideal limit the derivation reduces to exact inversion; on the 2×2 example it returns .*
Go deeper · Derivation B · 1 minThe inversion rotation and the role of the constant C
The goal is to show precisely how a single controlled single-qubit rotation implements , and why the normalization constant cannot be chosen freely but is pinned to by the smallest eigenvalue. This is the hinge between the mechanism and the cost: the same constraint that makes the rotation valid is the one that caps the success probability, so understanding it is understanding where the overhead is born.
Step 1. Apply with to a flag qubit in , giving . Why: the rotation maps to a real superposition whose weight is , so choosing lets us dial that weight to any value in .
Step 2. Evaluate the half-angle sine: . Why: this is the crux — the flag amplitude on is exactly , inversely proportional to the eigenvalue, so a large eigenvalue is suppressed and a small one enhanced, which is what inverting requires.
Step 3. Demand validity for every branch: needs , hence . Normalizing the spectrum so gives , so . Why: the smallest eigenvalue is the binding constraint; the whole inverse-condition-number factor enters here, purely to keep the rotation angle real for the hardest-to-invert eigen-direction.
Step 4. Read off the consequence: the flag amplitude for the smallest eigenvalue saturates near , but for typical eigenvalues it is , so the flagged branch carries weight . Why: the constant that makes the rotation legal simultaneously shrinks the post-selected probability, which is exactly why HHL's cost tracks — the mechanism and its price are two faces of the choice of . *For the 2×2 example with : gives and flag amplitude , while gives and flag amplitude — each matching exactly.*
Go deeper · Derivation C · 1 minCondition-number cost and amplitude amplification
The goal is to derive the success probability of the flag measurement from the Born rule and then show how amplitude amplification converts the naive repetition count into , which is the single most important resource statement in modern analyses of HHL. The argument is short but it is where the algorithm's practical viability is decided, so each factor of is tracked explicitly rather than absorbed into soft-O notation.
Step 1. Apply the Born rule to the flagged branch: , the summed squared amplitude on . Why: post-selection succeeds with probability equal to the total weight of the component, and because the eigen-branches are orthogonal these weights simply add.
Step 2. Insert and the normalization : each term is at least , and since the sum is . Why: the constant from the previous derivation directly sets the scale; the probability is small precisely because had to be small to invert the smallest eigenvalue.
Step 3. Count naive repetitions: succeeding once from probability takes independent runs. Why: without amplification, post-selection is just rejection sampling, and the expected number of trials to a first success is the reciprocal of the per-trial probability.
Step 4. Amplify instead: amplitude amplification boosts a success amplitude to in rounds, each one call to the HHL circuit and its inverse. Why: amplitude amplification is the Grover-style quadratic speedup applied to the flag, turning probabilistic repetitions into coherent iterations — the reason the headline runtime is linear, not quadratic, in . *For the 2×2 example, , equal to with .*
Limiting cases
How HHL's cost and meaning shift at the edges of its assumptions:
| Case | Result | Meaning |
|---|---|---|
| Well-conditioned | Success probability , no amplification needed; the dependence dominates and the exponential-in-dimension speedup is at its cleanest. | |
| Ill-conditioned | Runtime (original) or (improved); as the rotation angle saturates and , so the speedup vanishes for near-singular systems. | |
| High precision | Original HHL scales as from phase-estimation resolution; Childs–Kothari–Somma reach via a linear-combination-of-unitaries approximation of . | |
| Dense matrix | Sparsity enters the simulation of ; when is dense, makes the simulation cost and the exponential advantage over classical solvers disappears. | |
| Full read-out demanded | tomography of all | Recovering all amplitudes needs measurements, restoring linear-in- cost; the advantage holds only for an observable with an efficiently implementable . |
Worked examples
1 · A 2×2 system solved by hand, end to end (fully worked)
Solve with and on the HHL circuit: find the eigenbasis, the rotation angles, the output state, and the success probability. Take .
Step 1. Diagonalize . Its eigenvalues are with eigenvectors (for ) and (for ). The condition number is — very well-conditioned.
Step 2. Load . Normalized, , so the eigen-overlaps are . Both eigen-branches start with equal weight.
Step 3. Rotate to invert. The angles are : for , (flag amplitude ); for , (flag amplitude ). The smaller eigenvalue gets the larger amplitude, as inversion demands.
Step 4. Assemble the post-selected output. The flagged branch is . Converting to the computational basis gives , which is exactly . Normalizing () yields , i.e. amplitudes and .
Step 5. Success probability. . Because is tiny, the flag reads on 62.5% of runs — no amplification required. Result: , recovered with probability 62.5%, exactly matching .
2 · Sizing the exponential speedup (N = 2³⁰)
A sparse system has unknowns, row sparsity , condition number , and you want one expectation value to precision . Estimate the register sizes and compare the quantum and classical costs.
Step 1. Qubit budget. The solution register needs qubits — the entire billion-dimensional vector lives here. The clock needs qubits to resolve eigenvalues down to , plus one flag ancilla: about qubits total to represent a -dimensional linear solve.
Step 2. Classical cost. Conjugate gradient must perform matrix-vector products over all entries: operations — every one of the billion components must be touched at least once.
Step 3. Quantum cost. HHL scales as in the dimension: with the improved bound and , the dimension contributes only polynomially in , not in . The collapse is the whole point: a factor of in the dimension dependence alone.
Step 4. The catch, quantified. That -fold dimension advantage survives only if is efficiently measurable, is efficiently preparable, and the oracle for is cheap; and it is throttled by (a factor of overhead) and by . Ask for the full vector instead of and the read-out cost erases everything. The dimension speedup is exponential (), but it is realized only through a global observable and only when the input/output and conditioning are benign.
Physics of the portrait
HHL is a theorem in computational complexity, yet it sits in every quantum-information course because it drew the boundary of quantum advantage for the most practical task in all of numerical mathematics — and then a decade of "fine print" mapped exactly how sharp that boundary is.
Origins · 1 minAram Harrow and how this was discovered
Aram W. Harrow, together with Avinatan Hassidim and Seth Lloyd, published Quantum Algorithm for Linear Systems of Equations in Physical Review Letters in 2009, and the three initials gave the algorithm its name. The construction was a conceptual jolt: for two decades the flagship quantum algorithms — Deutsch–Jozsa, Simon, Shor, Grover — attacked number-theoretic or search problems, but HHL reached into the daily machinery of engineering and science, the linear solve at the heart of every finite-element model and every least-squares fit, and claimed an exponential speedup in the dimension. Harrow, a physicist trained at MIT under Ike Chuang and now a professor there, has spent his career on precisely the questions HHL forces: what quantum computers can and cannot do faster, and how to prove it. The algorithm's reception drove its own literature. Scott Aaronson's 2015 essay Read the fine print laid out the four caveats — state preparation, condition number, sparsity, and read-out — that any honest speedup claim must clear, and Ewin Tang's 2018 "dequantization" showed that some HHL-based machine-learning proposals had classical analogues after all, sharpening rather than shrinking the result. Meanwhile Ambainis, and later Childs, Kothari, and Somma, improved the and dependences, and the modern framework of block-encoding and quantum singular value transformation absorbed HHL as a special case. What began as one surprising circuit became the founding document of quantum linear algebra.
Going further
Texts. Harrow, Hassidim, Lloyd, Quantum Algorithm for Linear Systems of Equations, Phys. Rev. Lett. 103, 150502 (2009) · Nielsen & Chuang, Quantum Computation and Quantum Information (10th anniversary ed.), Ch. 4–5 (phase estimation and Hamiltonian simulation) · Preskill, Lecture Notes for Physics 219, Ch. 6 · Childs, Kothari, Somma, Quantum algorithm for systems of linear equations with exponentially improved dependence on precision, SIAM J. Comput. 46, 1920 (2017) · Aaronson, Read the fine print, Nature Physics 11, 291 (2015) · Dervovic et al., Quantum linear systems algorithms: a primer, arXiv:1802.08227 (2018). The rotation identity with is elementary trigonometry. The success probability and the amplification count follow from the Brassard–Høyer–Mosca–Tapp amplitude-amplification bound. The 2×2 worked example ( with eigenvalues ; ; angles ; ; ) and the resource estimate (, clock qubits, classical operations) were checked numerically. The improved runtime is from Childs–Kothari–Somma (2017).
Prerequisites. Quantum Phase Estimation · Quantum Fourier Transform · Amplitude Amplification. Leads to. Grover's Search Algorithm · Amplitude Amplification.
Ask the tutor: Ask me to run the 2×2 example through every register — phase estimation, the and rotations, and the post-selection that returns — or to show how the fine-print caveats decide whether a real-world linear solve keeps its exponential speedup.
Does HHL solve linear systems faster than my laptop?
For getting the actual answer vector, no. HHL never produces the list of numbers ; it produces a quantum state whose amplitudes are those numbers. If you need all of them, you must measure the state many times — tomography costing — which is no better than a classical solve. HHL is faster only when you want a single global property of the solution, such as an expectation value , an overlap with a reference state, or a yes/no answer, and only when the matrix is sparse and well-conditioned and the input is loadable efficiently. It is best thought of as a way to learn one fact about the solution to a gigantic system without ever forming the solution.
Why must A be Hermitian, and what if it is not?
Hermiticity guarantees a real spectrum and a complete orthonormal eigenbasis, which is exactly what makes phase estimation of well-defined — the unitary has eigenphases that the clock register can read. If is not Hermitian, you do not give up: you embed it in the Hermitian dilation and solve , whose solution has sitting in one block. The dilation doubles the dimension (one extra qubit) and leaves the sparsity and condition number essentially unchanged, so it is a free move in the asymptotics. Hermiticity is therefore a convenience of exposition, not a real restriction on the problems HHL can address.
What exactly is the condition number, and why does it hurt so much?
The condition number measures how close is to singular: a large means some eigen-direction is barely stretched, so inverting it demands a huge amplitude. In HHL that shows up twice. First, the inversion constant must satisfy so the rotation angle stays valid for the smallest eigenvalue, which shrinks the success probability to . Second, phase estimation must resolve eigenvalues down to , needing extra clock qubits and longer evolution times. Amplitude amplification softens the first cost from to , but nothing removes the entirely — an ill-conditioned system is genuinely hard, quantum or classical, because near-singularity is a real obstruction, not an artifact of the algorithm.
Where does the exponential speedup actually come from?
From compressing dimension into qubits. An -component vector lives in the amplitudes of qubits, so a million-dimensional problem uses twenty qubits and a billion-dimensional one uses thirty. Phase estimation then acts on all eigen-components in a single superposition, and the controlled rotation inverts every eigenvalue at once — the operations a classical machine would do one eigenvalue at a time happen in parallel across the whole spectrum. That is the source of the collapse. The catch is symmetric: the same compression that lets you hold numbers cheaply prevents you from reading them cheaply. So the speedup is real for the compute step and forbidden for the read-out step, which is why HHL is useful only for questions whose answers are themselves small.
How does HHL improve on the original κ² and 1/ε scaling?
Two separate refinements. The in the original success probability becomes through amplitude amplification — Ambainis' variable-time amplitude amplification handles the fact that different eigen-branches take different times to invert, squeezing the repetition count down without spoiling the branches that finish early. The from phase-estimation resolution and Hamiltonian-simulation error becomes in the Childs–Kothari–Somma algorithm, which sidesteps phase estimation entirely and instead approximates the function directly by a linear combination of unitaries built from a Chebyshev or Fourier expansion. The modern statement, , folds both improvements together and is what block-encoding and quantum singular value transformation reproduce as a special case.
Which quantum subroutines does HHL call, and in what order?
Five stages, in sequence. First, Hamiltonian simulation turns the matrix into the unitary — sparsity and oracle access are what make this efficient. Second, quantum phase estimation (which ends in an inverse quantum Fourier transform) writes each eigenvalue into the clock register. Third, a controlled rotation on a flag ancilla imprints the amplitude , performing the inversion. Fourth, the inverse of phase estimation uncomputes and resets the clock so the eigenvalue register disentangles. Fifth, amplitude amplification on the flag boosts the post-selection success probability from toward . This is why HHL sits downstream of phase estimation, the Fourier transform, and amplitude amplification in the dependency graph — it is a composite of all three.