HHL algorithm

Also known as: Harrow–Hassidim–Lloyd algorithm

On this page 7

The HHL algorithm, named after Aram Harrow, Avinatan Hassidim and Seth Lloyd (the Harrow–Hassidim–Lloyd algorithm), is a quantum procedure that takes a sparse, well-conditioned matrix A and a vector b encoded as a quantum state and produces a quantum state proportional to the solution x = A⁻¹b. Published in 2009, it is one of the foundational quantum algorithms in quantum computing because it showed that linear algebra, the backbone of scientific computing and machine learning, can in principle run with runtime polylogarithmic in the matrix dimension.

The headline speedup is real but heavily qualified. HHL does not output the solution vector as a list of numbers; it outputs a state from which only global properties of x can be estimated efficiently. Whether the speedup survives depends on how the input is loaded, how the matrix behaves and what the user actually wants to learn from the answer.

How the HHL algorithm inverts a matrix

HHL inverts a Hermitian matrix by working in its eigenbasis, where inversion reduces to dividing each component by its eigenvalue. The algorithm never computes the eigenvalues explicitly; it writes them into an ancilla register and then applies a controlled rotation that encodes 1/λ into an amplitude.

The procedure runs in four stages, and each stage relies on a standard building block from the same family of quantum algorithms. The following table summarizes the stages and the subroutines behind them.

StageOperationUnderlying subroutine
State preparationLoad b as the state |b⟩Amplitude encoding or QRAM
Phase estimationWrite eigenvalues λ of A into a clock registerQuantum phase estimation with Hamiltonian simulation of e^(iAt)
Conditional rotationRotate an ancilla by an angle proportional to C/λControlled single-qubit rotations
Uncomputation and post-selectionReverse phase estimation, measure ancilla as 1Inverse phase estimation plus amplitude amplification
The four stages of the HHL algorithm

After the ancilla is measured in the success state, the main register holds |x⟩, the normalized solution. Because success is probabilistic, HHL typically uses amplitude amplification to boost the success probability, which costs a number of repetitions proportional to the condition number κ.

Complexity and the parameters that control it

The original HHL analysis gives a runtime of roughly O(log(N) s² κ² / ε), where N is the dimension, s the sparsity, κ the condition number and ε the target precision. The dependence on N is the source of the famous exponential speedup, while the dependence on κ and ε is where practical cost hides.

Each parameter plays a distinct role, and a poor value in any one of them can erase the advantage. The table below lists what each parameter means and how it affects the cost.

ParameterMeaningEffect on runtime
Dimension NSize of the linear systemLogarithmic, the source of speedup
Sparsity sMaximum nonzero entries per rowPolynomial, through Hamiltonian simulation
Condition number κRatio of largest to smallest singular valueQuadratic in the original version
Precision εAllowed error in the output stateInverse-linear in the original version
Parameters that determine HHL cost

Later work by Ambainis and by Childs, Kothari and Somma reduced the κ dependence to nearly linear and the precision dependence to polylogarithmic in 1/ε, using variable-time amplitude amplification and techniques related to the linear combination of unitaries. Modern formulations based on quantum singular value transformation express matrix inversion as a polynomial approximation of 1/x, which unifies these improvements.

The caveats that limit the speedup

Scott Aaronson summarized the conditions for a genuine HHL advantage as the fine print of the algorithm. Each condition must hold at once; otherwise a classical method of comparable cost exists or the quantum output is unusable.

  • Input loading must be cheap. Preparing |b⟩ for an arbitrary vector can take time linear in N, which cancels the logarithmic runtime.
  • The matrix must be sparse or efficiently simulable, so that e^(iAt) can be implemented with a small circuit.
  • The condition number must be small, ideally polylogarithmic in N, or the repetitions dominate.
  • Only summary statistics can be read out. Reading all N amplitudes of |x⟩ requires on the order of N measurements.
  • No efficient classical shortcut may exist, a condition that dequantization results have narrowed for low-rank problems.

The readout caveat is the most frequently misunderstood. HHL efficiently estimates quantities such as an expectation value x†Mx or the overlap of x with another state, which is useful when the solution feeds into a further quantum subroutine rather than a classical spreadsheet.

HHL compared with classical and variational solvers

HHL competes with mature classical solvers such as the conjugate gradient method and with near-term quantum alternatives. The comparison below shows why the choice depends on hardware and on the required output.

MethodTypical costOutputHardware requirement
Gaussian eliminationO(N³)Full vectorClassical computer
Conjugate gradientO(N s √κ log(1/ε))Full vectorClassical computer
HHL and successorsPolylog in N, polynomial in κQuantum state |x⟩Fault-tolerant quantum computer
Variational linear solverUnknown, heuristicApproximate stateNoisy intermediate-scale device
Linear system solvers compared

Variational approaches trade guarantees for shallow circuits, in the spirit of the variational quantum eigensolver. HHL itself requires deep circuits with many controlled operations, so it belongs to the fault-tolerant era rather than to current noisy processors.

Where HHL is applied and what has been demonstrated

Proposed applications of HHL include finite-element simulation, differential equations, electromagnetic scattering, least-squares fitting and quantum machine learning tasks such as support vector machines and recommendation systems. In each case the useful output must be a scalar derived from the solution rather than the full vector.

Experimental demonstrations so far have solved 2×2 and small 4×4 systems on photonic, superconducting and nuclear magnetic resonance platforms. These experiments validate the circuit structure but do not show any speedup, because problems of that size are trivial classically and the circuits are compiled with prior knowledge of the eigenvalues.

ApplicationQuantity of interestMain obstacle
Differential equationsIntegrated field or energyLarge condition numbers after discretization
Recommendation systemsSampled preferred itemsDequantized by classical sampling algorithms
Electromagnetic scatteringRadar cross-sectionEfficient preparation of the source vector
Least-squares regressionPrediction for a new inputData loading without QRAM
Application areas and their fit for HHL

In plain words

Many problems in science and engineering come down to solving a huge set of linked equations. The HHL algorithm is a recipe for a future quantum computer to handle such equations far faster than an ordinary computer, at least on paper. The catch is that the answer stays locked inside the quantum machine.

Think of it like a chef who can cook an enormous soup almost instantly but can only hand out a single spoonful for tasting. If a small taste, such as the average saltiness, is all that is needed, the shortcut is excellent. If every ingredient must be listed, the speed advantage disappears.

A real-world example

An aerospace engineering team studies how a radar wave scatters off a new drone fuselage. Discretizing the surface produces a linear system with about one billion unknowns, yet the engineers only need one number: the radar cross-section at a specific viewing angle.

On a future fault-tolerant machine, the team would encode the incident wave as a quantum state, run HHL on the sparse interaction matrix, and then estimate the overlap of the solution with a measurement state. If the preconditioned system has a condition number near 100 and the incident wave has a compact description, the quantum runtime grows only with the logarithm of the system size. Today the same team runs a preconditioned iterative solver on a classical cluster, and HHL remains a research benchmark for when hardware with thousands of logical qubits becomes available.