Level 3 · Algorithms

The HHL Algorithm: Solving Linear Systems on a Quantum Computer, and the Fine Print

About 4,922 words · roughly 22 minute read · sources checked December 3, 2026

Solving a system of linear equations is one of the most common tasks in science and engineering. Given a matrix A and a vector b, find the vector x such that A x = b. Weather models, circuit design, machine learning and many other fields turn their problems into huge linear systems. In 2008 Aram Harrow, Avinatan Hassidim and Seth Lloyd published a quantum algorithm for this task, now called HHL after their initials, with a startling claim: its running time depends only on the logarithm of the size of the matrix.

That claim made HHL famous, and it is also easy to misread. The algorithm does not output the solution vector x. It outputs a quantum state whose amplitudes are proportional to x, and reading that state out in full would cost as much as the classical computation. The honest picture is a precise, conditional statement about a precise, narrow task. In this lesson we build that picture step by step.

We start with what a linear system and its condition number are, using computed examples. Then we explain the algorithm in four steps, work a 2×2 example by hand, and check it against a circuit-level simulation I wrote, which reproduces the hand calculation exactly, including a success probability of 0.625. We then look at the resource scaling and at the four caveats raised in Scott Aaronson’s article, whose full text I opened, and finish with what the abstracts of the original paper and of Tang’s work say.

As in earlier lessons, no Qiskit was available to me, so all numbers come from my own NumPy calculations. I describe exactly what each computation did. Where I use a claim from a paper I say which paper and I limit it to what I read.

What you will learn

  • What a linear system is, and what the condition number measures, with a computed example of a badly conditioned system.
  • The four steps of HHL: encode b, estimate eigenvalues, rotate an ancilla, and undo the estimation.
  • A 2×2 example worked by hand and checked by simulation, with the success probability.
  • Why the algorithm outputs a state and not a list of numbers, and what that means in practice.
  • How the condition number and the precision affect the cost.
  • The four caveats that decide whether HHL gives an exponential speed-up.

Helpful first: Quantum Phase Estimation, Linear Algebra for Quantum Computing.

The problem: Ax = b

A linear system is a set of equations in which each unknown appears only to the first power, for example 1.5x₁ + 0.5x₂ = 1 and 0.5x₁ + 1.5x₂ = 0. Written compactly, A x = b, where A is a square table of numbers called a matrix, x is the list of unknowns and b is the list of right-hand sides. Solving the system means finding x. For a matrix with N rows and N columns, the standard classical method, Gaussian elimination, takes a number of steps proportional to N³. For a million unknowns that is around 10¹⁸ operations in the dense case, which is why people use smarter methods for special matrices.

The abstract of the HHL paper, which I opened, gives the classical comparison it uses: for a sparse N×N matrix, meaning one where each row has only a few non-zero entries, with condition number κ, the best known classical algorithms take time of order N√κ. We will define κ in a moment. The point is that classical methods have to touch all N entries of the answer, so their cost grows at least linearly with N.

A small system worked by hand

Take the matrix A with rows (1.5, 0.5) and (0.5, 1.5), and the vector b = (1, 0). Solving by elimination gives x = (0.75, −0.25). Check: 1.5 × 0.75 + 0.5 × (−0.25) = 1.125 − 0.125 = 1, and 0.5 × 0.75 + 1.5 × (−0.25) = 0.375 − 0.375 = 0. Both equations hold. This is the example we will follow through the whole lesson.

Eigenvalues and the condition number

Matrices like this one have special directions, called eigenvectors, along which the matrix acts by simple stretching: A v = λ v, where λ is the eigenvalue. For our A the eigenvalues are λ₁ = 1 and λ₂ = 2, with eigenvectors v₁ = (1, −1)/√2 and v₂ = (1, 1)/√2. I confirmed these with a numerical eigenvalue routine. The condition number κ is the ratio of the largest to the smallest eigenvalue size, here 2/1 = 2. It measures how lopsided the stretching is.

Why do we care? Because solving Ax = b means undoing the stretching, which divides each component of b by the matching eigenvalue. A tiny eigenvalue means a huge division, so small changes in b can cause large changes in x. This is the meaning of an ill-conditioned system, and it matters for HHL because the algorithm’s cost grows with κ.

Worked example

A badly conditioned system, computed

  1. Take A with rows (1, 0.99) and (0.99, 1). Its eigenvalues are 0.01 and 1.99, so κ = 199. I computed this with a numerical routine.
  2. For b = (1, 1) the solution is x = (0.50251, 0.50251). Now change the second entry of b by 0.01 to get (1, 1.01), a change of 0.71% in b. The new solution is (0.00503, 1.00503). The solution changed by 99.5%.
  3. For b = (1, −1) the solution is x = (100, −100), a hundredfold amplification. Changing the second entry to −0.99 gives (99.50, −99.50), a change of only about 0.5%.
  4. The difference is direction. The vector (1, 1) is an eigenvector with the large eigenvalue 1.99, so its solution is small (0.5), and the small change in b, which has a component along the small-eigenvalue direction, is amplified a hundredfold relative to it. The vector (1, −1) already lies along the small-eigenvalue direction, so its solution is already huge, and the same small change barely matters in relative terms.
  5. The lesson: when κ is large, whether the answer is stable depends on the direction of b, and in the worst direction a 0.7% error in the input can change the output by nearly 100%.

In a real application, the input b comes from measurements or from a model, and it is never exact. A large condition number means the answer may be dominated by errors. That is one reason methods for ill-conditioned problems are delicate even on classical computers.

Remember this number

The condition number κ appears twice in the story of HHL: it controls how hard the classical problem is, and it controls how much the quantum algorithm costs. A quantum algorithm cannot make a badly conditioned problem easy.

The idea behind HHL in four steps

HHL treats the vector b as a quantum state, which we write |b⟩ and which has the entries of b, normalised, as its amplitudes. With n qubits you can store N = 2ⁿ numbers as amplitudes, so a million-entry vector needs only 20 qubits and a billion-entry vector needs 30. The algorithm’s output is the state |x⟩, proportional to the solution vector. I call this the state encoding. Whether you can prepare |b⟩ cheaply is one of the caveats we will return to.

The algorithm exploits the fact that A is easy to understand in its eigenbasis. Write b as a combination of eigenvectors: b = Σⱼ βⱼ vⱼ. Then the solution is x = Σⱼ (βⱼ / λⱼ) vⱼ. Each component is just divided by its eigenvalue. HHL performs these divisions in superposition, on all components at once. There are four steps.

  1. Prepare |b⟩ in the main register. In the eigenbasis this state is Σⱼ βⱼ |vⱼ⟩.
  2. Run phase estimation using the evolution operator e^(iAt) for some time t. This is the same circuit as in the phase estimation lesson, with U = e^(iAt) and the eigenvectors of A as its eigenstates. It writes an estimate of each eigenvalue λⱼ into a clock register, so the state becomes Σⱼ βⱼ |vⱼ⟩|λ̃ⱼ⟩.
  3. Add an ancilla qubit and rotate it, controlled on the clock value, so that its amplitude of |1⟩ equals C/λ̃ⱼ, where C is a constant chosen no larger than the smallest eigenvalue. The state becomes Σⱼ βⱼ |vⱼ⟩|λ̃ⱼ⟩ (√(1 − C²/λⱼ²)|0⟩ + (C/λⱼ)|1⟩).
  4. Undo the phase estimation so the clock register returns to |0⟩, then measure the ancilla. If it reads 1, the main register is in the state proportional to Σⱼ (βⱼ/λⱼ) |vⱼ⟩, which is |x⟩. If it reads 0, discard and start again.

Step 3 is where the actual division happens, encoded in the amplitude of the ancilla. Step 4’s measurement keeps only the part of the state where the ancilla is 1; that selects the 1/λ amplitudes and throws away the rest, which is why the result is a state proportional to the solution. The probability of seeing 1 is not 1, and we will compute it.

|b⟩  →  Σⱼ βⱼ |vⱼ⟩                                  (step 1)
     →  Σⱼ βⱼ |vⱼ⟩ |λ̃ⱼ⟩                            (step 2: phase estimation)
     →  Σⱼ βⱼ |vⱼ⟩ |λ̃ⱼ⟩ (… |0⟩ + (C/λⱼ) |1⟩)       (step 3: controlled rotation)
     →  after undoing step 2 and measuring the ancilla as 1:   |x⟩ ∝ Σⱼ (βⱼ/λⱼ) |vⱼ⟩
The four steps of HHL on the eigenbasis components. The factor 1/λⱼ enters through the ancilla rotation.

The abstract of the original paper, which I opened, says the algorithm estimates the expectation value of an operator associated with x, such as x†Mx, rather than finding the whole solution vector x. That is the same point: the output is a state, and you extract limited information from it by measuring.

The 2×2 example, by hand and by simulation

Let us run the algorithm on A with rows (1.5, 0.5) and (0.5, 1.5) and b = (1, 0). From the eigendecomposition, b = (v₁ + v₂)/√2, since v₁ = (1, −1)/√2 and v₂ = (1, 1)/√2 add to (2, 0)/√2 = (√2, 0), and dividing by √2 gives (1, 0). So the components are β₁ = β₂ = 1/√2 = 0.7071.

Step by step

  • Step 1: the main register holds |b⟩ = (|v₁⟩ + |v₂⟩)/√2.
  • Step 2: choose the evolution time t₀ = 2π/4, so the eigenvalue 1 gives a phase of 1/4 and the eigenvalue 2 gives a phase of 2/4. With two clock qubits (four levels) these are exactly representable. The clock register then holds |01⟩ for v₁ and |10⟩ for v₂. My simulation gave clock probabilities 0, 0.5, 0.5, 0 for the values 0, 1, 2, 3, as expected.
  • Step 3: set C = 1, the smallest eigenvalue. The ancilla amplitudes for |1⟩ are C/λ₁ = 1 for the first component and C/λ₂ = 0.5 for the second.
  • Step 4: after undoing the phase estimation, the part of the state with the ancilla in |1⟩ is (1/√2)(1·|v₁⟩ + 0.5·|v₂⟩). Its squared length is (1/2)(1 + 0.25) = 0.625. That is the probability of reading 1.

The normalised output is therefore proportional to |v₁⟩ + 0.5|v₂⟩. Expressed in the ordinary basis, with v₁ = (1, −1)/√2 and v₂ = (1, 1)/√2, that is (1, −1)/√2 + 0.5(1, 1)/√2 = (1.5, −0.5)/√2, which is proportional to (0.75, −0.25), the classical solution. After normalising, the state is (0.94868, −0.31623).

QuantityHand calculationCircuit-level simulation
Success probability P(ancilla = 1)(1/2)(1 + 1/4) = 0.6250.625
Output state (normalised)(0.94868, −0.31623)(0.94868, −0.31623)
Exact solution direction x/‖x‖(0.94868, −0.31623)(0.94868, −0.31623)
Overlap squared with the exact direction11.0 (to 8 decimals)
Clock distribution before rotation0.5 on |01⟩, 0.5 on |10⟩0, 0.5, 0.5, 0

Results of the 2×2 example. The simulation is my own four-qubit matrix simulation: two clock qubits, one data qubit and one ancilla, with exact phase estimation because the eigenvalues fit the clock.

To check my understanding I did not stop at the hand calculation. I wrote a matrix-level simulation of the full circuit on four qubits, with the Hadamards on the clock, the controlled powers of e^(iAt₀), the inverse quantum Fourier transform, the controlled ancilla rotations, and then the inverse of all those steps. It gave a success probability of 0.625 and an output state identical to the exact solution direction to eight decimal places. That the simulation matches the hand calculation, which uses only the eigen-decomposition, is a good sign that the description above is right for this example.

I want to be clear about one thing the example does not show. The eigenvalues here were chosen so that two clock qubits represent them exactly. For general eigenvalues the clock estimate has errors, and those errors propagate into the output state. I did not simulate that general case, so I make no claim about how the accuracy depends on the clock size.

The success probability and the choice of C

The ancilla reads 1 with a probability that depends on the eigenvalues, on how b is split among them, and on the constant C. In general, the probability is the sum over components of |βⱼ|² times (C/λⱼ)². In words: each eigencomponent contributes its weight times the square of its ancilla amplitude.

P(success)  =  C²  ·  Σⱼ  |βⱼ|² / λⱼ²
Success probability of one run of HHL. The constant C must be no larger than the smallest eigenvalue, so that C/λⱼ never exceeds 1.

For our example, with β₁² = β₂² = 0.5 and eigenvalues 1 and 2, the sum is 0.5/1 + 0.5/4 = 0.625, and with C = 1 the success probability is 0.625, as the simulation found. The constant C is a design choice that must be at most the smallest eigenvalue, or else the amplitude C/λ for the smallest eigenvalue would exceed 1, which is not allowed for an amplitude. Making C larger helps, so you choose it as large as is allowed. Making it smaller makes the success probability drop with its square:

Choice of CSuccess probability (my calculation)Expected repetitions per success
1.0 (equal to the smallest eigenvalue)0.6251.6
0.50.156256.4
0.250.0390625.6

Effect of C in the 2×2 example. The success probability is C² × 0.625, so halving C divides the probability by four. The expected number of repetitions is one over the probability.

Each failed run costs a full run of the circuit, so a low success probability multiplies the cost. The abstract of Brassard and coauthors’ paper, which I opened for the amplitude estimation lesson, says that amplitude amplification finds a good element after about 1/√a repetitions, where a is the success probability. That suggests that the repetition cost of HHL can be reduced from about 1/P to about 1/√P by amplification. I mention this as an application of that abstract’s statement and did not look at how the HHL paper handles it.

Why the condition number drives the cost

In a real problem the matrix is scaled so that its largest eigenvalue is at most 1, which makes the smallest eigenvalue about 1/κ. Then C must be about 1/κ, the success probability involves 1/κ², and the phase estimation must resolve eigenvalues as small as 1/κ. I derive here only the resolution part, from the counting rule in the phase estimation lesson: to tell apart eigenvalues near 1/κ to a relative precision δ, the clock must resolve phases of about δ/κ, so it needs about log₂(κ/δ) qubits, and the evolution operator must be applied about κ/δ times in total.

Condition number κRelative precision δClock qubits t ≈ ⌈log₂(κ/δ)⌉Applications of e^(iAt₀) about 2ᵗ − 1
100.17127
1000.1101,023
1,0000.11416,383

A rough estimate of the phase-estimation cost, from my own application of the 2ᵗ − 1 counting rule. These are not figures from the HHL paper, and the full algorithm has other factors I did not include.

The pattern is that the number of evolution steps grows in proportion to κ. This matches the abstract’s statement that the running time is polynomial in κ, and Aaronson’s remark, quoted below, that the runtime grows nearly linearly with κ. Since the abstract of the HHL paper reports the classical baseline as N√κ, both methods depend on κ, and the relative advantage is about the factor N versus log N.

How the right-hand side changes the success probability

The success probability depends on the direction of b, because b decides how much weight falls on each eigenvector, and the small-eigenvalue components contribute more. I ran the ideal output for several choices of b in the same 2×2 system, always with C = 1, and compared the output with the exact normalised solution.

b (normalised)Weights on v₁ (λ = 1) and v₂ (λ = 2)Success probabilityOutput stateMatches exact solution?
(1, 0)0.5 and 0.50.625(0.94868, −0.31623)Yes
(0, 1)0.5 and 0.50.625(−0.31623, 0.94868)Yes
(0.7071, 0.7071)0 and 10.25(0.70711, 0.70711)Yes
(0.7071, −0.7071)1 and 01.0(0.70711, −0.70711)Yes
(0.6, 0.8)0.02 and 0.980.265(0.48564, 0.87416)Yes
(0.8, 0.6)0.02 and 0.980.265(0.87416, 0.48564)Yes

Ideal HHL output for six right-hand sides, computed by me with the eigen-decomposition listing. The output always points along the exact solution; only the success probability changes.

Three patterns are visible. First, the output is always the exact solution direction, which is the whole point of the algorithm. Second, when b lies entirely along the eigenvector with the smaller eigenvalue, v₁, the success probability is 1, because the ancilla amplitude C/λ₁ equals 1. When b lies entirely along v₂, the probability is (1/2)² = 0.25. Third, a b that is mostly along the large-eigenvalue direction, like (0.6, 0.8), has low success probability, 0.265. The right-hand sides whose solution is large are the ones that succeed most often, which makes sense: success means the solution component survived the scaling by C, and a large solution survives better.

A useful mental model

The probability of success is the squared size of the unnormalised solution when A is scaled so its smallest eigenvalue is C. A right-hand side that produces a short solution gives a low success probability, and the algorithm must be repeated more often.

In the 2×2 case the repetitions needed are 1.6 on average for the first row and 4 for the third row. For a large system with a bad direction of b, the number can grow large, and this effect adds to the cost from the condition number.

What the logarithm means in numbers

To get a feeling for the claim that the dependence on N is logarithmic, look at how many qubits the state |b⟩ needs and compare with the classical baseline of order N√κ from the abstract.

Qubits n for |b⟩Matrix dimension N = 2ⁿ
101,024
201,048,576
301,073,741,824
401,099,511,627,776
501,125,899,906,842,624

Number of amplitudes stored by n qubits. The exponential growth of N in n is the source of the logarithmic dependence.

NCondition number κClassical baseline N√κ (order of magnitude)
1,000,00010about 3.2 million
1,000,00010010 million
1,000,000,00010010 billion

The classical baseline from the abstract, evaluated for three cases. These are scale estimates for the cost expression N√κ and are not run times.

A billion unknowns corresponds to 30 qubits for |b⟩. That is a small register, and it is the reason the algorithm is so striking on paper. But the table must be read with the caveats. To use the 30-qubit register, you must be able to load a billion-entry vector into it quickly, apply the matrix evolution efficiently, keep κ small, and be content with a global property of the answer. If any of those conditions fails, the advantage can vanish, as the article I opened argues.

There is also a comparison that is easy to forget. The classical baseline in the abstract is for finding the whole solution vector, N numbers. The quantum algorithm gives one global quantity. These are different tasks, and comparing their costs directly is the kind of apples-to-oranges comparison that the fine-print article warns about. A fair comparison asks how fast a classical algorithm could compute the same global quantity, given the same kind of access to the data.

The fine print: four caveats

The abstract of the HHL paper describes the quantum runtime as polynomial in log N and κ, an exponential improvement over the best classical algorithm, with the dependence on the dimension N being logarithmic. I opened Scott Aaronson’s article “Quantum machine learning algorithms: read the fine print”, and it lists four caveats to this headline. I summarise them in my own words.

  1. Input. The vector b must be loaded into a quantum state |b⟩ quickly. In general that takes a quantum random-access memory and a fairly uniform b. If preparing |b⟩ takes a number of steps that grows as a power of N, then, in the article’s words, the exponential speed-up of HHL vanishes in the very first step.
  2. Applying the evolution. The quantum computer must apply e^(−iAt) efficiently. That is feasible for a sparse matrix with a suitable quantum memory, but if it takes a power of N in time, the speed-up disappears.
  3. The condition number. The matrix must be well-conditioned. The runtime grows nearly linearly with κ, so if κ grows like a power of N, the speed-up is gone.
  4. The output. HHL outputs a quantum state, not the solution vector. Measuring reveals only limited statistics, such as an inner product. Learning one particular entry of x generally takes about N repetitions, which again eliminates the speed-up.

Each caveat can be seen in our computed examples. The input caveat corresponds to step 1 of the algorithm, which I simply assumed. The evolution caveat corresponds to step 2, where I built the matrix e^(iAt₀) by exponentiating the 2×2 matrix, which is trivial at this size but is the expensive part in general. The condition number caveat is the 199-versus-2 example, where the stability of the answer depends on the direction of b. The output caveat is visible in the fact that our final answer was a state, and to see its two numbers (0.94868 and −0.31623) we would need many measurements.

CaveatWhat must hold for the exponential speed-upWhat happens if it fails
Input|b⟩ can be prepared in time polylogarithmic in NThe preparation step costs a power of N and the speed-up vanishes at the start
Evolutione^(−iAt) can be applied efficiently, for example for sparse AThe cost of step 2 becomes a power of N
Condition numberκ grows at most polylogarithmically with NThe runtime, nearly linear in κ, grows as a power of N
OutputYou need only a global property of x, such as an inner productReading individual entries needs about N repetitions

The four caveats, summarised from the article I opened. The conditions are about the problem you want to solve, not about the circuit.

What the speed-up really is

HHL is an exponential speed-up for a specific kind of task: sampling a global quantity from the solution of a sparse, well-conditioned system whose right-hand side is easy to prepare. It is not an exponentially faster way to solve linear systems in general, and the article I opened is explicit about this.

Dequantization and what it means for HHL-style claims

The caveats are about what the algorithm needs. A second line of work asks whether a classical algorithm could do just as well under the same assumptions. In the quantum machine learning lesson I described Tang’s paper on a classical algorithm for recommendation systems, whose abstract says the classical algorithm matches the quantum one up to polynomial slowdown, so the quantum algorithm gave no exponential speed-up there. That paper concerns a recommendation-systems algorithm that was built from related techniques, not HHL itself, and I did not open any source that says the same applies to HHL. So I do not claim that.

What I can say is that the lesson transfers as a warning. When an exponential claim depends on a specific way of accessing the data, check whether a classical algorithm is allowed the same kind of access. If it is, the gap may be much smaller than advertised. I take that to be the main practical message of the fine-print discussion.

A short program to check the 2×2 example

The listing below reproduces the hand calculation using the eigen-decomposition directly. It computes the eigenvalues, expresses b in the eigenbasis, divides each component by its eigenvalue after scaling by C, and reports the success probability and the normalised output. I ran this exact listing. The printed output is the eigenvalues [1. 2.], the success probability 0.625 and the output [0.94868, −0.31623].

import numpy as np

A = np.array([[1.5, 0.5], [0.5, 1.5]])
b = np.array([1.0, 0.0])

w, V = np.linalg.eigh(A)           # eigenvalues and eigenvectors
bt = V.T @ b                       # components of b in the eigenbasis
C = w.min()                        # as large as allowed
out = V @ (bt * C / w)             # amplitudes after the ancilla rotation
P = np.sum((bt * C / w) ** 2)      # probability that the ancilla reads 1
out = out / np.linalg.norm(out)
print(w, round(P, 5), np.round(out, 5))
# prints: [1. 2.] 0.625 [ 0.94868 -0.31623]
A classical emulation of the ideal HHL output for a 2×2 system. It does not simulate the circuit; it computes what an ideal run would produce.

This listing takes shortcuts a quantum computer cannot take. It computes the eigendecomposition directly, which is the thing the quantum algorithm estimates by phase estimation. Its value is as a reference: if you ever implement HHL on a simulator, you can compare your circuit’s output with these numbers.

For the circuit-level check I used a separate, longer matrix program with four qubits. I describe it in words rather than print it, because it is long. It applied the Hadamards, the controlled evolution, the inverse quantum Fourier transform, the controlled ancilla rotations and the inverses, and its post-selected output matched the numbers above to eight decimal places.

Where HHL fits in the bigger picture

HHL is rarely used on its own. It is a subroutine inside larger algorithms, for tasks where linear systems appear and where only a global property of the solution is needed. Because of the caveats above, whether any real application meets all four conditions is a matter of ongoing research, and I did not survey the applications. The Aaronson article I opened is explicitly about the caveats for quantum machine learning algorithms built on this kind of linear-algebra subroutine.

From a teaching point of view, HHL is valuable because it combines most of the tools you have met so far in the algorithms level: state encoding in amplitudes, phase estimation, controlled rotations and post-selection. If you can follow the four steps and the 2×2 example, you have understood a good part of how quantum algorithms are put together.

ToolWhere it appeared beforeRole in HHL
Phase estimationQuantum phase estimation lessonWrites the eigenvalues of A into a clock register
Quantum Fourier transformQFT lessonThe inverse transform inside phase estimation
Controlled rotationsQuantum gates lessonPut the factor C/λ into the ancilla amplitude
Post-selection / amplificationGrover and amplitude estimation lessonsKeep the successful branch; amplification can cut the repetitions
Amplitude encodingMulti-qubit systems lessonStores b and x in the amplitudes of n qubits

How earlier lessons feed into HHL.

Common mistakes and misunderstandings

  • Saying HHL solves Ax = b in logarithmic time. It prepares a state proportional to x under conditions; it does not output the vector, and the logarithmic dependence is only on N, not on κ or the precision.
  • Forgetting the ancilla measurement. Without post-selecting on 1, the main register holds a mixture that is not |x⟩.
  • Choosing C larger than the smallest eigenvalue. The ancilla amplitude C/λ would exceed 1, which is not a valid amplitude.
  • Ignoring κ. In the badly conditioned example above, a 0.7% change in b changed the solution by 99.5%.
  • Assuming exact eigenvalue estimates. My 2×2 example was constructed so the clock was exact; general cases have estimation errors.
  • Assuming the speed-up survives any input. The four caveats exist exactly because it does not.

Frequently asked questions

Does HHL beat the best classical algorithm?

Under its conditions, the abstract of the paper says exponential improvement over the best classical algorithm for the task it defines, which is estimating a quantity like x†Mx for a sparse system. The article I opened argues that the conditions are restrictive. I have not verified the status of the best classical alternatives and do not claim a current comparison.

Why does it need the matrix to be sparse?

Because applying e^(iAt) must be efficient. For sparse matrices there are methods to do this, and Aaronson’s article says this is feasible for sparse A with a suitable quantum memory. I did not study those methods.

How many qubits does it need?

The state |b⟩ needs log₂ N qubits, so 20 qubits store a million entries and 30 store a billion. The clock and the ancilla add more. In my example, N = 2 needed one data qubit, two clock qubits and one ancilla, four in all.

Could I run HHL on today’s hardware?

Only for tiny systems like our 2×2 case, and I did not run it on hardware. The phase estimation inside it needs deep circuits, which are beyond current noisy devices for anything of useful size.

What is a good next step?

Try the 2×2 simulation with a different b, such as (0, 1). The solution is (−0.25, 0.75), and I would expect the same success probability by symmetry of the components, but I leave that for you to check yourself.

Practice questions

Check yourself

For A with rows (1.5, 0.5) and (0.5, 1.5), what is the condition number?

The eigenvalues are 1 and 2, so κ = 2/1 = 2.

Solve Ax = b for b = (1, 0) with the same A.

x = (0.75, −0.25). Check: 1.5(0.75) + 0.5(−0.25) = 1 and 0.5(0.75) + 1.5(−0.25) = 0.

In the 2×2 example with C = 1, what is the success probability?

C² × Σ βⱼ²/λⱼ² = 0.5/1 + 0.5/4 = 0.625.

If we halve C to 0.5, what is the new success probability?

0.625 × 0.25 = 0.15625.

Why must C be no larger than the smallest eigenvalue?

The ancilla amplitude C/λ must not exceed 1, and it is largest for the smallest λ.

Name the four caveats in one word each.

Input, evolution, condition number, output.

For κ = 1,000 and δ = 0.1, roughly how many clock qubits does my rule give?

⌈log₂(10,000)⌉ = 14.

Summary

  • HHL prepares a quantum state proportional to the solution of Ax = b, using phase estimation to read eigenvalues, a controlled rotation to apply 1/λ, and post-selection.
  • In my 2×2 example, a hand calculation and a four-qubit matrix simulation both give success probability 0.625 and the output (0.94868, −0.31623).
  • The cost depends on the condition number κ; a badly conditioned example (κ = 199) turned a 0.7% input change into a 99.5% output change.
  • The headline exponential speed-up comes with four caveats about input, evolution, conditioning and output, as set out in the article I opened.
  • HHL is best understood as a subroutine and a teaching example of how quantum algorithms combine phase estimation, rotations and post-selection.

References and further reading

I opened the arXiv abstract page of Harrow, Hassidim and Lloyd, and the full text of Aaronson’s article “Quantum machine learning algorithms: read the fine print” (the PDF I opened shows no venue line, and I list the HHL citation it gives). I also use the abstract of Tang’s paper from the quantum machine learning lesson. I did not open the full text of the HHL paper, so I do not quote its formulas for the runtime beyond what the abstract states. All examples, simulations and tables are my own computations.

  1. Quantum algorithm for solving linear systems of equations (arXiv / Phys. Rev. Lett. (Harrow, Hassidim, Lloyd, 2008)) Opened the abstract page. Estimates an expectation value of an operator associated with x; classical baseline of order N√κ for sparse matrices; runtime polynomial in log N and κ.
  2. Quantum machine learning algorithms: read the fine print (Scott Aaronson (author’s copy; the PDF I opened shows no venue line)) Opened the full text. Four caveats on the HHL speed-up: input, applying the evolution, condition number, and output.
  3. A quantum-inspired classical algorithm for recommendation systems (arXiv (E. Tang, 2018)) Abstract opened earlier in this project. Classical algorithm matching the quantum one up to polynomial slowdown for recommendation systems.
  4. Quantum Amplitude Amplification and Estimation (arXiv (Brassard, Høyer, Mosca, Tapp, 2000)) Abstract opened. Amplitude amplification finds a good element after about 1/√a repetitions.