Quantum Algorithms Database

HHL Algorithm

Solves systems of linear equations exponentially faster than classical methods, under specific conditions.

Last reviewed September 30, 2026. Check the linked sources for anything that may have changed since.

Year

2008 (arXiv); 2009 (Physical Review Letters)

Inventor(s)

Aram Harrow, Avinatan Hassidim, and Seth Lloyd

Speedup Type

Exponential Speedup

Difficulty

★★★★★

Overview

The HHL algorithm solves a linear system of equations. Given a matrix A and a vector b, it prepares a quantum state whose amplitudes are proportional to the solution x of A x = b. For a sparse, well-conditioned N by N matrix, it does this in time that scales as a polynomial in the logarithm of N, compared with a time at least linear in N for classical methods.

The headline result is an exponential speedup, but it comes with significant fine print. You do not get the full solution vector, only a quantum state that encodes it, from which you can estimate a quantity such as an inner product. The algorithm also requires fast access to the input vector and a matrix that has a particular structure. HHL is still among the most influential algorithms in quantum computing because it introduced the idea of quantum linear algebra.

The problem

Solving a system of linear equations (Ax = b) — a problem underlying enormous amounts of scientific computing and machine learning.

History

Aram Harrow, Avinatan Hassidim, and Seth Lloyd posted the paper in 2008, and it appeared in Physical Review Letters in 2009. It sparked a wave of work on quantum machine learning, because linear systems and matrix operations sit at the core of regression, support vector machines, and principal component analysis.

The first experimental demonstrations came in 2013 on tiny two-by-two systems, using photonic and NMR devices. In 2015 Scott Aaronson wrote an influential essay, Read the Fine Print, that described the conditions under which the speedup holds. In 2018, Ewin Tang showed that a closely related quantum machine learning algorithm for recommendation systems could be matched by a classical algorithm with similar sampling access, which led to a wave of dequantization results. Improvements by Childs, Kothari, and Somma in 2017, and by Gilyén and coauthors in 2019 using quantum singular value transformation, reduced the dependence on precision and condition number.

Intuition

The key idea is to diagonalize the matrix without ever writing it down. Any invertible Hermitian matrix A has eigenvectors and eigenvalues, and A inverse acts on each eigenvector by dividing by its eigenvalue. If you could write the input vector b in the eigenbasis of A, and divide each component by the corresponding eigenvalue, you would have the solution.

HHL does this with quantum phase estimation. It applies the evolution e to the i A t, so that the eigenvalues appear as phases, and uses phase estimation to write each eigenvalue into an ancilla register in superposition. It then performs a controlled rotation that multiplies each eigencomponent by a factor proportional to 1 over its eigenvalue, undoes the phase estimation to uncompute the eigenvalue register, and finally measures an ancilla qubit. If the result is 1, the main register holds the solution state.

This is why the matrix must be sparse and well conditioned. Sparsity lets e to the i A t be implemented efficiently, and a small condition number kappa, the ratio of the largest to the smallest eigenvalue, keeps the controlled rotation from amplifying noise and keeps the success probability reasonable.

How it works

Encodes the linear system into a quantum state, uses quantum phase estimation to find eigenvalues, and inverts them to construct the solution — all without ever writing out the full solution vector classically.

  1. Prepare the quantum state b, the amplitudes of which are the entries of the vector, in an input register. This requires efficient state preparation, for example from a quantum memory or a structured circuit.
  2. Add a clock register of ancilla qubits and apply quantum phase estimation with the unitary e to the i A t, entangling the eigenvalues of A with the clock register.
  3. Add a single ancilla qubit and apply a controlled rotation, conditioned on the clock register, that sets the ancilla amplitude proportional to a constant divided by the eigenvalue.
  4. Apply the inverse of the phase estimation circuit to uncompute the clock register.
  5. Measure the ancilla qubit. If the result is 1, the input register holds the normalized solution state. If the result is 0, repeat; amplitude amplification can reduce the number of repetitions.
  6. Extract the information you want, such as an expectation value of an observable on the solution state, by repeating the whole procedure many times and measuring.

Worked example

Take the two-by-two system in which A has 1.5 on both diagonal entries and 0.5 on both off-diagonal entries, and b is the vector (1, 0). The eigenvalues of A are 1 and 2, with eigenvectors (1, -1) over the square root of 2 and (1, 1) over the square root of 2. The vector b is an equal-weight combination of those two eigenvectors. HHL multiplies the first component by 1 over 1 and the second by 1 over 2 and then normalizes. The exact solution is x = (3/4, -1/4), so the output state is proportional to (3, -1), which is what the quantum circuit prepares.

Early experiments verified this kind of two-by-two example. They confirmed that the structure works, but they could not demonstrate any speedup, since solving a two-by-two system classically is trivial.

Complexity and resources

Quantum runtimeO(log N times s squared times kappa squared divided by epsilon), where s is sparsity, kappa the condition number, and epsilon the precision
Best classical (exact, sparse)O(N s kappa log of 1 over epsilon) using conjugate gradient
Improved quantum versionsPolylogarithmic in 1 over epsilon and linear in kappa with later techniques
OutputA quantum state proportional to the solution, not the explicit vector
QubitsAbout log N plus ancillas for the clock and rotation registers

Hardware needs

Fault-tolerant hardware with deep circuits, because phase estimation and Hamiltonian simulation of A are expensive.

A way to prepare the vector b efficiently and, for classical data, a quantum memory that may not exist at scale.

Sparse access to the matrix, so that e to the i A t can be simulated efficiently.

Real-world impact

Has significant caveats (requires the matrix to be 'sparse' and well-conditioned, and the output is a quantum state, not a classical answer), but is foundational to quantum machine learning research.

Applications

Solving differential equations by discretizing them into large sparse linear systems, as in fluid dynamics and electromagnetic scattering.

Quantum machine learning subroutines that rely on matrix inversion, such as regression and support vector machines.

Estimating properties of the solution, such as the electromagnetic scattering cross section, rather than reading out the whole vector.

Serving as a theoretical anchor: matrix inversion with these constraints is BQP-complete.

Limitations

  • The input vector must be loaded into a quantum state, which can cost as much as the classical solution.
  • The output is a quantum state, so reading all N entries would take about N repetitions and wipe out the speedup.
  • The matrix must be sparse and have a small condition number.
  • For machine learning tasks, classical dequantized algorithms can match the speedup when low-rank assumptions hold.

Common misconceptions

  • HHL does not give you the solution vector. It gives a quantum state from which you can sample or estimate expectation values.
  • The exponential speedup does not apply to arbitrary linear systems. It requires sparsity, good conditioning, and efficient input and output.
  • It has not been used to solve a practical large problem. Experiments so far are on tiny systems.

How it compares

Classical conjugate gradient is polynomial in N, but it returns the full solution and has no input-output issues.

Variational linear solvers such as VQLS aim to run on near-term devices, but they offer no proven speedup.

Quantum singular value transformation generalizes HHL to many matrix functions with better scaling.

Why it matters

HHL shows that quantum computers can in principle perform linear algebra on exponentially large objects in logarithmic time, and it started the field of quantum machine learning. Many later algorithms are built from its ingredients: phase estimation, controlled rotations, and amplitude amplification.

It is equally valuable as a case study in how to read speedup claims. Aaronson's fine print, followed by dequantization, shows how input assumptions, output limits, and classical competition shape what a speedup really means.

What HHL promises, and what it does not

The HHL algorithm is named for Aram Harrow, Avinatan Hassidim and Seth Lloyd, authors of 'Quantum algorithm for solving linear systems of equations' (arXiv 0811.3171). The problem is to take a matrix A and a vector b and find x such that Ax = b. The crucial detail in the abstract is what the algorithm outputs: not the full solution vector x, but an approximation of the expectation value of some operator associated with x, for example x'Mx.

The abstract states that for a sparse N by N matrix A with condition number kappa, the best classical algorithms can find x and estimate x'Mx in time of order N times the square root of kappa, while the quantum algorithm runs in poly(log N, kappa) time, which the authors describe as an exponential improvement over the best classical algorithm.

Reading this carefully is the key to using the algorithm honestly. The exponential speedup is in the dimension N, it depends on the matrix being sparse and well-conditioned, and the answer is a summary quantity rather than the vector itself. Reading out all N entries of x would cost at least N operations, which erases the gain.

The fine print that determines whether HHL helps

Researchers usually list several conditions that must hold at once. The input vector b has to be loaded into a quantum state efficiently, which is not free for arbitrary classical data. The matrix has to be sparse enough that the evolution it defines can be simulated efficiently. The condition number has to be modest, since the runtime depends on kappa. And the question you ask has to be about a property of x, not x itself. When any one fails, the exponential advantage can disappear.

These caveats do not mean the algorithm is useless. They mean that it is a subroutine whose value depends on the surrounding pipeline, and that fair comparisons need to count the cost of state preparation and read-out. This is a recurring lesson in quantum algorithms for linear algebra.

  • Input: load b as a quantum state (a cost that depends on how b is stored).
  • Matrix: sparse and efficiently simulable, with a manageable condition number kappa.
  • Output: an expectation value such as x'Mx, not the whole vector x.
  • Runtime (as stated in the abstract): poly(log N, kappa) versus order N times the square root of kappa classically.

How it works at a high level

HHL uses quantum phase estimation as its engine. The matrix defines a unitary evolution, and phase estimation reads out the eigenvalues of A in a register while the state of b is expressed in the eigenvector basis. A controlled rotation then applies a factor proportional to the inverse of each eigenvalue, and the phase estimation is undone so that the eigenvalue register is cleared. Measuring a flag qubit tells you whether the inversion succeeded; the process is repeated until it does.

Because the inversion step divides by eigenvalues, small eigenvalues cause large amplification, which is the reason the condition number appears in the runtime.

The dequantization story: Ewin Tang's result

A major development in this area came from Ewin Tang's paper 'A quantum-inspired classical algorithm for recommendation systems' (arXiv 1807.04271). It gives a classical algorithm that outputs an l2-norm sample from a rank-k approximation of an m by n matrix in time O(poly(k) log(mn)), only polynomially slower than the quantum algorithm, so Kerenidis and Prakash's quantum recommendation system does not give an exponential speedup over classical algorithms, under the sampling-access assumptions used.

This result matters for HHL-style algorithms because it showed that some claimed exponential speedups for machine-learning linear algebra came from the data-access model rather than from quantum mechanics alone. When the classical algorithm is given comparable sampling access, the gap shrinks to a polynomial one. It is a good example of why the input model has to be part of any speedup claim. It does not say that HHL itself has been dequantized in every setting; the matrix-inversion problem for general sparse matrices is treated differently, and this page does not claim otherwise.

Frequently asked questions

What does the HHL algorithm do?

It prepares a quantum state proportional to the solution of a linear system A x = b, for a sparse, well-conditioned matrix A.

Is HHL exponentially faster than classical solvers?

In its query model, yes, but only when state preparation, sparsity, conditioning, and the limited form of output are all favorable. In many practical settings the advantage disappears.

Can I use HHL to speed up machine learning?

Possibly for specific structured problems. For many learning tasks, dequantized classical algorithms can match the quantum speedup under comparable access assumptions.

What is the condition number?

The ratio of the largest to the smallest eigenvalue of the matrix. A large condition number makes the problem harder and increases the cost of HHL.

Has HHL been run on real hardware?

Yes, on tiny systems such as two-by-two matrices, using photonic, NMR, and superconducting devices. These were demonstrations of the structure, not of speedup.

Related algorithms

References and further reading

Sources opened and checked on December 1, 2026. Resource estimates and claims change, so check the originals.

  1. Quantum algorithm for solving linear systems of equations (arXiv (Harrow, Hassidim, Lloyd)) Opened. Source for the problem statement, output type and runtime comparison.
  2. A quantum-inspired classical algorithm for recommendation systems (arXiv (E. Tang)) Opened. Source for the O(poly(k) log(mn)) classical running time.
  3. Quantum measurements and the Abelian Stabilizer Problem (arXiv (A. Yu. Kitaev)) Opened. Background on phase estimation, the engine HHL builds on.

← Back to Algorithms Database