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 Ax=bAx=b. 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 NN — touch every entry of the answer and you have already paid Ω(N)\Omega(N). Harrow, Hassidim, and Lloyd's 2009 construction refuses to pay that. It never writes the solution down. Instead it encodes the entire NN-component vector xx into the amplitudes of an n=log⁡2Nn=\log_2 N qubit state ∣x⟩|x\rangle, and it manufactures that state in time polylogarithmic in NN. A million-dimensional system lives in twenty qubits; a billion-dimensional one in thirty. The engine is spectral. Written in its own eigenbasis, A=∑jλj∣uj⟩⟨uj∣A=\sum_j\lambda_j|u_j\rangle\langle u_j|, and solving Ax=bAx=b means nothing more than dividing each component of bb by its eigenvalue λj\lambda_j. A classical machine does those divisions one at a time; HHL does all NN at once. Quantum phase estimation on the unitary eiAt0e^{iAt_0} tags every eigenvector ∣uj⟩|u_j\rangle with its eigenvalue λj\lambda_j in an ancillary register, a single controlled rotation writes an amplitude proportional to 1/λj1/\lambda_j, and running phase estimation backwards erases the scratch work — leaving a state proportional to ∑jβjλj−1∣uj⟩=A−1∣b⟩\sum_j\beta_j\lambda_j^{-1}|u_j\rangle=A^{-1}|b\rangle. 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 NN amplitudes by tomography costs Ω(N)\Omega(N) and erases the speedup — the win is real only for a summary property ⟨x∣M∣x⟩\langle x|M|x\rangle. The runtime carries the condition number κ\kappa and the sparsity ss, so ill-conditioned or dense systems bleed the advantage away. And the whole edifice assumes coherent oracle access to AA and efficient preparation of ∣b⟩|b\rangle. 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.

Key takeaways
  • HHL prepares a quantum state ∣x⟩|x\rangle whose amplitudes are the (normalized) entries of the solution to Ax=bAx=b, for an N×NN\times N Hermitian, ss-sparse, well-conditioned matrix AA.
  • The original runtime is O~(s2κ2log⁡N/ϵ)\tilde O(s^2\kappa^2\log N/\epsilon) — exponentially faster in the dimension NN than the O(Nsκlog⁡(1/ϵ))O(Ns\sqrt{\kappa}\log(1/\epsilon)) of classical conjugate gradient.
  • The mechanism is quantum phase estimation on eiAt0e^{iAt_0}, which loads each eigenvalue λj\lambda_j into an ancilla, followed by a controlled rotation that writes an amplitude ∝1/λj\propto 1/\lambda_j, then uncomputation.
  • The speedup is genuine only for extracting a global property ⟨x∣M∣x⟩\langle x|M|x\rangle; full read-out by tomography costs Ω(N)\Omega(N) and destroys the advantage.
  • The condition number κ\kappa enters because the inversion succeeds with probability Θ(1/κ2)\Theta(1/\kappa^2); amplitude amplification softens O(κ2)O(\kappa^2) repetitions to O(κ)O(\kappa).
  • Later work (Ambainis; Childs–Kothari–Somma) cut the dependence to κ polylog(1/ϵ)\kappa\,\mathrm{polylog}(1/\epsilon), and HHL is now the seed of the whole field of quantum linear algebra.
  • Key idea: phase estimation on eiAt0e^{iAt_0} transfers each eigenvalue λj\lambda_j of AA into an ancilla register, a controlled rotation writes an amplitude ∝1/λj\propto 1/\lambda_j, and uncomputing the register leaves a state proportional to A−1∣b⟩=∑jβjλj−1∣uj⟩A^{-1}|b\rangle=\sum_j\beta_j\lambda_j^{-1}|u_j\rangle — the entire spectral inversion carried out in superposition.
The core insight

Phase estimation on eiAt0e^{iAt_0} transfers each eigenvalue λj\lambda_j of AA into an ancilla register; a controlled rotation then writes an amplitude ∝1/λj\propto 1/\lambda_j, so that uncomputing the eigenvalue register leaves a state proportional to A−1∣b⟩=∑jβjλj−1∣uj⟩A^{-1}|b\rangle=\sum_j\beta_j\lambda_j^{-1}|u_j\rangle. 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 Ax=bAx=b, simulating Hamiltonians, and estimating spectra are all read off from one unifying framework that traces directly back to the HHL rotation λ↦1/λ\lambda\mapsto 1/\lambda. 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 AA in its own eigenbasis, where it is simply a list of multipliers: the eigenvector ∣uj⟩|u_j\rangle gets scaled by λj\lambda_j. Solving Ax=bAx=b is then the most elementary act imaginable — take the input ∣b⟩=∑jβj∣uj⟩|b\rangle=\sum_j\beta_j|u_j\rangle, and divide each spectral component by its eigenvalue to get ∑jβjλj−1∣uj⟩\sum_j\beta_j\lambda_j^{-1}|u_j\rangle. The classical difficulty is that the eigenbasis is hidden: you would have to diagonalize AA first, an O(N3)O(N^3) chore. HHL's sleight of hand is that it never diagonalizes anything. Quantum phase estimation, run on the unitary eiAt0e^{iAt_0} that Hamiltonian simulation builds from AA, acts diagonally on each ∣uj⟩|u_j\rangle automatically — it writes the eigenvalue λj\lambda_j into a clock register without anyone ever computing an eigenvector. Every eigen-branch is processed in parallel because they all ride the same superposition.

Figure
The HHL circuit worked on a 2×2 example: phase estimation reads each eigenvalue into the clock register, a controlled rotation writes amplitude C/λ onto the flag, phase estimation is undone, and post-selecting the flag on 1 leaves the solution in the input register. For A with eigenvalues λ = 1 and 2 and C = 1 the rotation angles are θ = 180° and 60°, and the flag reads 1 with probability 62.5%
The HHL circuit: read the eigenvalues, rotate to invert, uncompute, post-select the flag clock input flag |0⟩ᵗ |b⟩ |0⟩ QPE eⁱᴬᵗ⁰ Rᵧ QPE† clock→|0⟩ |λ̃ⱼ⟩|uⱼ⟩ amp C/λⱼ on |1⟩ |x⟩ worked 2×2: A = [[1.5, 0.5],[0.5, 1.5]], eigenvalues λ = 1 and 2, condition number κ = 2 θ = 2 arcsin(C/λ) with C = 1 → θ = 180° for λ = 1, 60° for λ = 2; flag = 1 with probability 62.5% output |x⟩ = √0.9 |0⟩ − √0.1 |1⟩ ∝ A⁻¹|b⟩, the normalized solution of Ax = b

The controlled rotation is the algorithm's one genuinely clever move. Conditioned on the clock register holding λ~j\tilde\lambda_j, a single ancilla qubit is rotated by θj=2arcsin⁡(C/λ~j)\theta_j=2\arcsin(C/\tilde\lambda_j), depositing amplitude exactly C/λ~jC/\tilde\lambda_j on its ∣1⟩|1\rangle branch. A large eigenvalue gives a small amplitude, a small eigenvalue a large one — precisely the λ↦1/λ\lambda\mapsto 1/\lambda scaling that inverts AA. Post-selecting that flag ancilla on ∣1⟩|1\rangle keeps only the inverted branch, but the probability of landing there is ∼(C/λ)2\sim(C/\lambda)^2, and the smallest eigenvalue forces C≲∣λmin⁡∣∼1/κC\lesssim|\lambda_{\min}|\sim 1/\kappa. That single constraint is the taproot of every κ\kappa 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.

Figure
Runtime versus problem dimension N = 2ⁿ on a logarithmic scale: classical conjugate gradient must touch all N entries and scales as N, while HHL scales as a polynomial in log N. At N = 2²⁰ ≈ 1.05×10⁶ the classical cost is about a million matrix-vector operations while HHL runs in the qubit count n = 20 up to polylog and κ factors — an exponential gap in the dimension that widens without bound
The punchline: classical cost grows as N, HHL as poly(log N) — exponential in the dimension 10⁰ 10³ 10⁶ 10⁹ 2⁰ 2²⁰ 2⁴⁰ 2⁶⁰ matrix dimension N = 2ⁿ (n = number of qubits) runtime (operations) classical ≈ N HHL ≈ poly(log N) ≈ 1.05×10⁶ ops n = 20 qubits gap at N = 2²⁰: million-fold in N

The core equations

The problem is the most familiar one in computational science, with three structural assumptions attached. AA is Hermitian so that phase estimation is well-defined; sparse so that eiAt0e^{iAt_0} can be simulated in polylogarithmic time; and well-conditioned so the inversion does not blow up.

Ax=b,x=A−1b,A=A†(1)Ax=b,\qquad x=A^{-1}b,\qquad A=A^{\dagger} \qquad (1)

where: AA — N×NN\times N Hermitian, ss-sparse matrix with condition number κ\kappa; bb — right-hand side, loaded as ∣b⟩=∑ibi∣i⟩/∥b∥|b\rangle=\sum_i b_i|i\rangle/\lVert b\rVert; xx — solution, delivered as ∣x⟩=∑ixi∣i⟩/∥x∥|x\rangle=\sum_i x_i|i\rangle/\lVert x\rVert; κ=∣λmax⁡∣/∣λmin⁡∣\kappa=|\lambda_{\max}|/|\lambda_{\min}| — condition number. Reading: a non-Hermitian AA is first embedded in a Hermitian dilation, so Hermiticity costs nothing in generality. Everything happens in the eigenbasis of AA, even though it is never computed. The spectral theorem hands us a real spectrum and an orthonormal eigenbasis, and the input decomposes along it.

A=∑j=1Nλj ∣uj⟩⟨uj∣,∣b⟩=∑j=1Nβj ∣uj⟩,βj=⟨uj∣b⟩(2)A=\sum_{j=1}^{N}\lambda_j\,|u_j\rangle\langle u_j|,\qquad |b\rangle=\sum_{j=1}^{N}\beta_j\,|u_j\rangle,\qquad \beta_j=\langle u_j|b\rangle \qquad (2)

where: λj\lambda_j — jj-th real eigenvalue of AA; ∣uj⟩|u_j\rangle — orthonormal eigenvector; βj\beta_j — overlap of ∣b⟩|b\rangle with ∣uj⟩|u_j\rangle. Reading: HHL processes each ∣uj⟩|u_j\rangle branch independently and in parallel, which is why the target below is a term-by-term division. Inverting AA is nothing but dividing each spectral coefficient by its eigenvalue — the operation the controlled rotation will realize physically.

A−1∣b⟩=∑j=1Nβj λj−1 ∣uj⟩(3)A^{-1}|b\rangle=\sum_{j=1}^{N}\beta_j\,\lambda_j^{-1}\,|u_j\rangle \qquad (3)

where: λj−1\lambda_j^{-1} — the inverse eigenvalue, the multiplier that turns bb into xx along the jj-th axis. Reading: the whole algorithm is a physical device for writing the amplitudes βjλj−1\beta_j\lambda_j^{-1} without ever isolating a single ∣uj⟩|u_j\rangle. Phase estimation of the simulated unitary eiAt0e^{iAt_0} is the eigenvalue-reading engine: because eiAt0∣uj⟩=eiλjt0∣uj⟩e^{iAt_0}|u_j\rangle=e^{i\lambda_j t_0}|u_j\rangle, it writes a binary estimate of λj\lambda_j into a clock register entangled with ∣uj⟩|u_j\rangle.

∣uj⟩∣0⟩⊗t  → QPE[eiAt0]   ∣uj⟩∣λ~j⟩(4)|u_j\rangle|0\rangle^{\otimes t}\;\xrightarrow{\ \mathrm{QPE}[e^{iAt_0}]\ }\;|u_j\rangle|\tilde\lambda_j\rangle \qquad (4)

where: eiAt0e^{iAt_0} — unitary from Hamiltonian simulation of AA; ∣λ~j⟩|\tilde\lambda_j\rangle — tt-qubit register storing λjt0/2π\lambda_j t_0/2\pi to tt bits; t0t_0 — evolution time fixed so λjt0∈[0,2π)\lambda_j t_0\in[0,2\pi), setting the eigenvalue resolution. Reading: tt bits of clock give eigenvalue precision ∼2−t\sim 2^{-t}, and resolving λmin⁡∼1/κ\lambda_{\min}\sim 1/\kappa needs t≳log⁡2(κ/ϵ)t\gtrsim\log_2(\kappa/\epsilon) qubits. The controlled rotation performs λ↦1/λ\lambda\mapsto 1/\lambda. A flag ancilla is rotated by an angle read off the clock, so its ∣1⟩|1\rangle amplitude comes out inversely proportional to the eigenvalue.

∣λ~j⟩∣0⟩  →  ∣λ~j⟩ ⁣(1−C2λ~j2 ∣0⟩+Cλ~j ∣1⟩),θj=2arcsin⁡ ⁣(Cλ~j)(5)|\tilde\lambda_j\rangle|0\rangle\;\to\;|\tilde\lambda_j\rangle\!\left(\sqrt{1-\tfrac{C^2}{\tilde\lambda_j^{2}}}\,|0\rangle+\tfrac{C}{\tilde\lambda_j}\,|1\rangle\right),\qquad \theta_j=2\arcsin\!\left(\tfrac{C}{\tilde\lambda_j}\right) \qquad (5)

where: CC — normalization constant obeying C≤∣λmin⁡∣∼1/κC\le|\lambda_{\min}|\sim 1/\kappa so that C/λ~j≤1C/\tilde\lambda_j\le 1; ∣1⟩|1\rangle — flag whose post-selection keeps the inverted branch. Reading: sin⁡(θj/2)=C/λ~j\sin(\theta_j/2)=C/\tilde\lambda_j, so the flag amplitude is exactly proportional to 1/λj1/\lambda_j; the cap C≲1/κC\lesssim 1/\kappa is the sole reason the success probability is small. Uncomputing the clock and post-selecting the flag on ∣1⟩|1\rangle leaves the input register holding the solution, up to phase-estimation error.

∣x⟩  ∝  ∑jβj Cλj ∣uj⟩  =  C A−1∣b⟩(6)|x\rangle\;\propto\;\sum_{j}\beta_j\,\frac{C}{\lambda_j}\,|u_j\rangle\;=\;C\,A^{-1}|b\rangle \qquad (6)

where: ∣x⟩|x\rangle — normalized solution state after uncomputation and post-selection. Reading: the surviving amplitudes are βj/λj\beta_j/\lambda_j up to the global constant CC, which is exactly A−1∣b⟩A^{-1}|b\rangle renormalized. The flag reads ∣1⟩|1\rangle with probability set by the branch weights, which is where κ\kappa enters and where amplitude amplification buys it back.

Psuccess=∑j∣βj∣2C2λj2=Θ ⁣(1κ2),Namp=O ⁣(1Psuccess)=O(κ)(7)P_{\mathrm{success}}=\sum_j|\beta_j|^2\frac{C^2}{\lambda_j^2}=\Theta\!\left(\frac{1}{\kappa^2}\right),\qquad N_{\mathrm{amp}}=O\!\left(\frac{1}{\sqrt{P_{\mathrm{success}}}}\right)=O(\kappa) \qquad (7)

where: PsuccessP_{\mathrm{success}} — probability of measuring the flag in ∣1⟩|1\rangle; NampN_{\mathrm{amp}} — number of amplitude-amplification rounds. Reading: naive repetition costs O(κ2)O(\kappa^2) runs, but amplifying the flagged branch reduces this quadratically to O(κ)O(\kappa) — the linear-in-κ\kappa factor of modern HHL. Assembling Hamiltonian simulation, phase estimation, and amplification gives the runtime, together with its later improvement and the honest classical comparison.

THHL=O~ ⁣(s2κ2log⁡Nϵ)→ CKS O~ ⁣(sκ polylog(N/ϵ)),Tclassical=O ⁣(Nsκ log⁡1ϵ)(8)T_{\mathrm{HHL}}=\tilde O\!\left(\frac{s^2\kappa^2\log N}{\epsilon}\right)\xrightarrow{\ \mathrm{CKS}\ }\tilde O\!\big(s\kappa\,\mathrm{polylog}(N/\epsilon)\big),\qquad T_{\mathrm{classical}}=O\!\big(Ns\sqrt{\kappa}\,\log\tfrac1\epsilon\big) \qquad (8)

where: ss — row sparsity; ϵ\epsilon — target precision; O~\tilde O — soft-O suppressing log factors; TclassicalT_{\mathrm{classical}} — conjugate gradient on a sparse positive-definite system. Reading: the decisive change is N→log⁡NN\to\log N; the useful output is a global property ⟨M⟩=⟨x∣M∣x⟩\langle M\rangle=\langle x|M|x\rangle, since anything requiring all NN amplitudes reinstates the classical cost.

Derivation AFull HHL state evolution end to end

The goal is to track the complete quantum state — clock, input, and flag registers together — from the initial product ∣0⟩c⊗t∣b⟩∣0⟩f|0\rangle_c^{\otimes t}|b\rangle|0\rangle_f through phase estimation, the controlled rotation, uncomputation, and post-selection, and to prove that what survives is proportional to A−1∣b⟩A^{-1}|b\rangle. Working entirely in the eigenbasis of AA makes every step a diagonal action on the ∣uj⟩|u_j\rangle 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 ∑jβj ∣0⟩c∣uj⟩∣0⟩f\sum_j\beta_j\,|0\rangle_c|u_j\rangle|0\rangle_f. Why: any vector expands in the orthonormal eigenbasis, and writing it this way lets us follow each eigen-branch jj separately, since every gate below acts diagonally on ∣uj⟩|u_j\rangle.

Step 2. Apply phase estimation of eiAt0e^{iAt_0} to the clock and input registers, giving ∑jβj ∣λ~j⟩c∣uj⟩∣0⟩f\sum_j\beta_j\,|\tilde\lambda_j\rangle_c|u_j\rangle|0\rangle_f. Why: eiAt0∣uj⟩=eiλjt0∣uj⟩e^{iAt_0}|u_j\rangle=e^{i\lambda_j t_0}|u_j\rangle, so QPE writes the eigenphase into the clock; this is the only place the matrix AA 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 Ry(2arcsin⁡(C/λ~j))R_y(2\arcsin(C/\tilde\lambda_j)) conditioned on the clock, producing ∑jβj ∣λ~j⟩c∣uj⟩(1−C2/λ~j2 ∣0⟩f+Cλ~j∣1⟩f)\sum_j\beta_j\,|\tilde\lambda_j\rangle_c|u_j\rangle\big(\sqrt{1-C^2/\tilde\lambda_j^2}\,|0\rangle_f+\tfrac{C}{\tilde\lambda_j}|1\rangle_f\big). Why: the flag amplitude on ∣1⟩|1\rangle is now C/λ~jC/\tilde\lambda_j, 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 ∣0⟩c|0\rangle_c, leaving ∑jβj ∣0⟩c∣uj⟩(1−C2/λ~j2 ∣0⟩f+Cλ~j∣1⟩f)\sum_j\beta_j\,|0\rangle_c|u_j\rangle\big(\sqrt{1-C^2/\tilde\lambda_j^2}\,|0\rangle_f+\tfrac{C}{\tilde\lambda_j}|1\rangle_f\big). 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 λ~j≠λj\tilde\lambda_j\neq\lambda_j.

Step 5. Measure the flag and condition on the outcome ∣1⟩|1\rangle, projecting onto 1∑j∣βj∣2C2/λ~j2∑jβjCλ~j∣uj⟩\frac{1}{\sqrt{\sum_j|\beta_j|^2 C^2/\tilde\lambda_j^2}}\sum_j\beta_j\tfrac{C}{\tilde\lambda_j}|u_j\rangle. Why: post-selection keeps only the inverted-amplitude branch and renormalizes it; the surviving amplitudes are ∝βj/λj\propto\beta_j/\lambda_j, precisely the spectral coefficients of A−1∣b⟩A^{-1}|b\rangle.

Step 6. Identify the result: in the ideal limit λ~j=λj\tilde\lambda_j=\lambda_j the state is ∣x⟩=A−1∣b⟩/∥A−1∣b⟩∥|x\rangle=A^{-1}|b\rangle/\lVert A^{-1}|b\rangle\rVert. Why: dividing every eigen-coefficient of ∣b⟩|b\rangle by its eigenvalue and renormalizing is the definition of the normalized solution, so the circuit has solved Ax=bAx=b in the amplitude encoding. *In the ideal limit λ~j=λj\tilde\lambda_j=\lambda_j the derivation reduces to exact inversion; on the 2×2 example it returns ∣x⟩=0.9 ∣0⟩−0.1 ∣1⟩|x\rangle=\sqrt{0.9}\,|0\rangle-\sqrt{0.1}\,|1\rangle.*

Go deeper · Derivation B · 1 minThe inversion rotation and the role of the constant C
Derivation BThe inversion rotation and the role of the constant C

The goal is to show precisely how a single controlled single-qubit rotation implements λ↦1/λ\lambda\mapsto 1/\lambda, and why the normalization constant CC cannot be chosen freely but is pinned to ∼1/κ\sim 1/\kappa 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 κ\kappa overhead is born.

Step 1. Apply Ry(θj)R_y(\theta_j) with θj=2arcsin⁡(C/λ~j)\theta_j=2\arcsin(C/\tilde\lambda_j) to a flag qubit in ∣0⟩|0\rangle, giving cos⁡(θj/2)∣0⟩+sin⁡(θj/2)∣1⟩\cos(\theta_j/2)|0\rangle+\sin(\theta_j/2)|1\rangle. Why: the RyR_y rotation maps ∣0⟩|0\rangle to a real superposition whose ∣1⟩|1\rangle weight is sin⁡(θj/2)\sin(\theta_j/2), so choosing θj\theta_j lets us dial that weight to any value in [0,1][0,1].

Step 2. Evaluate the half-angle sine: sin⁡(θj/2)=sin⁡(arcsin⁡(C/λ~j))=C/λ~j\sin(\theta_j/2)=\sin(\arcsin(C/\tilde\lambda_j))=C/\tilde\lambda_j. Why: this is the crux — the flag amplitude on ∣1⟩|1\rangle is exactly C/λ~jC/\tilde\lambda_j, inversely proportional to the eigenvalue, so a large eigenvalue is suppressed and a small one enhanced, which is what inverting AA requires.

Step 3. Demand validity for every branch: arcsin⁡\arcsin needs C/λ~j≤1C/\tilde\lambda_j\le 1, hence C≤min⁡jλ~j≈∣λmin⁡∣C\le\min_j\tilde\lambda_j\approx|\lambda_{\min}|. Normalizing the spectrum so ∣λmax⁡∣≤1|\lambda_{\max}|\le 1 gives ∣λmin⁡∣=∣λmax⁡∣/κ∼1/κ|\lambda_{\min}|=|\lambda_{\max}|/\kappa\sim 1/\kappa, so C∼1/κC\sim 1/\kappa. 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 11, but for typical eigenvalues it is O(1/κ)O(1/\kappa), so the flagged branch carries weight O(1/κ2)O(1/\kappa^2). Why: the constant that makes the rotation legal simultaneously shrinks the post-selected probability, which is exactly why HHL's cost tracks κ\kappa — the mechanism and its price are two faces of the choice of CC. *For the 2×2 example with C=1C=1: λ=1\lambda=1 gives θ=2arcsin⁡(1)=180°\theta=2\arcsin(1)=180° and flag amplitude 11, while λ=2\lambda=2 gives θ=2arcsin⁡(0.5)=60°\theta=2\arcsin(0.5)=60° and flag amplitude 0.50.5 — each matching C/λC/\lambda exactly.*

Go deeper · Derivation C · 1 minCondition-number cost and amplitude amplification
Derivation CCondition-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 O(κ2)O(\kappa^2) repetition count into O(κ)O(\kappa), 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 κ\kappa is tracked explicitly rather than absorbed into soft-O notation.

Step 1. Apply the Born rule to the flagged branch: Psuccess=∑j∣βj∣2(C/λj)2P_{\mathrm{success}}=\sum_j|\beta_j|^2(C/\lambda_j)^2, the summed squared amplitude on ∣1⟩|1\rangle. Why: post-selection succeeds with probability equal to the total weight of the ∣1⟩|1\rangle component, and because the eigen-branches are orthogonal these weights simply add.

Step 2. Insert C∼1/κC\sim 1/\kappa and the normalization ∣λj∣≤1|\lambda_j|\le 1: each term is at least (C/λmax⁡)2=Θ(1/κ2)(C/\lambda_{\max})^2=\Theta(1/\kappa^2), and since ∑j∣βj∣2=1\sum_j|\beta_j|^2=1 the sum is Θ(1/κ2)\Theta(1/\kappa^2). Why: the constant CC from the previous derivation directly sets the scale; the probability is small precisely because CC had to be small to invert the smallest eigenvalue.

Step 3. Count naive repetitions: succeeding once from probability p=Θ(1/κ2)p=\Theta(1/\kappa^2) takes O(1/p)=O(κ2)O(1/p)=O(\kappa^2) 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 p\sqrt p to Θ(1)\Theta(1) in O(1/p)=O(κ)O(1/\sqrt p)=O(\kappa) 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 O(κ2)O(\kappa^2) probabilistic repetitions into O(κ)O(\kappa) coherent iterations — the reason the headline runtime is linear, not quadratic, in κ\kappa. *For the 2×2 example, Psuccess=12(1)2+12(0.5)2=0.625P_{\mathrm{success}}=\tfrac12(1)^2+\tfrac12(0.5)^2=0.625, equal to C2∥A−1b∥2C^2\lVert A^{-1}b\rVert^2 with C=1C=1.*

Limiting cases

How HHL's cost and meaning shift at the edges of its assumptions:

CaseResultMeaning
Well-conditionedκ=O(1)\kappa=O(1)Success probability Θ(1)\Theta(1), no amplification needed; the log⁡N\log N dependence dominates and the exponential-in-dimension speedup is at its cleanest.
Ill-conditionedκ→∞\kappa\to\inftyRuntime ∝κ2\propto\kappa^2 (original) or κ\kappa (improved); as λmin⁡→0\lambda_{\min}\to 0 the rotation angle saturates and Psuccess→0P_{\mathrm{success}}\to 0, so the speedup vanishes for near-singular systems.
High precisionϵ→0\epsilon\to 0Original HHL scales as 1/ϵ1/\epsilon from phase-estimation resolution; Childs–Kothari–Somma reach polylog(1/ϵ)\mathrm{polylog}(1/\epsilon) via a linear-combination-of-unitaries approximation of 1/x1/x.
Dense matrixs→Ns\to NSparsity enters the simulation of eiAt0e^{iAt_0}; when AA is dense, s=Θ(N)s=\Theta(N) makes the simulation cost poly(N)\mathrm{poly}(N) and the exponential advantage over classical solvers disappears.
Full read-out demandedtomography of all xix_iRecovering all NN amplitudes needs Ω(N)\Omega(N) measurements, restoring linear-in-NN cost; the advantage holds only for an observable ⟨x∣M∣x⟩\langle x|M|x\rangle with an efficiently implementable MM.

Worked examples

1 · A 2×2 system solved by hand, end to end (fully worked)

Solve Ax=bAx=b with A=(1.50.50.51.5)A=\begin{pmatrix}1.5&0.5\\0.5&1.5\end{pmatrix} and b=(1,0)⊤b=(1,0)^{\top} on the HHL circuit: find the eigenbasis, the rotation angles, the output state, and the success probability. Take C=1C=1.

Step 1. Diagonalize AA. Its eigenvalues are λ=1.5±0.5={2,1}\lambda=1.5\pm0.5=\{2,1\} with eigenvectors ∣u1⟩=∣+⟩=(∣0⟩+∣1⟩)/2|u_1\rangle=|+\rangle=(|0\rangle+|1\rangle)/\sqrt2 (for λ1=2\lambda_1=2) and ∣u2⟩=∣−⟩=(∣0⟩−∣1⟩)/2|u_2\rangle=|-\rangle=(|0\rangle-|1\rangle)/\sqrt2 (for λ2=1\lambda_2=1). The condition number is κ=λmax⁡/λmin⁡=2/1=2\kappa=\lambda_{\max}/\lambda_{\min}=2/1=\mathbf{2} — very well-conditioned.

Step 2. Load bb. Normalized, ∣b⟩=∣0⟩=12(∣+⟩+∣−⟩)|b\rangle=|0\rangle=\tfrac{1}{\sqrt2}(|+\rangle+|-\rangle), so the eigen-overlaps are β1=β2=1/2\beta_1=\beta_2=\mathbf{1/\sqrt2}. Both eigen-branches start with equal weight.

Step 3. Rotate to invert. The angles are θj=2arcsin⁡(C/λj)\theta_j=2\arcsin(C/\lambda_j): for λ2=1\lambda_2=1, θ=2arcsin⁡(1)=180°\theta=2\arcsin(1)=\mathbf{180°} (flag amplitude C/λ=1C/\lambda=1); for λ1=2\lambda_1=2, θ=2arcsin⁡(0.5)=60°\theta=2\arcsin(0.5)=\mathbf{60°} (flag amplitude 0.50.5). The smaller eigenvalue gets the larger amplitude, as inversion demands.

Step 4. Assemble the post-selected output. The flagged branch is ∝∑jβj(C/λj)∣uj⟩=12(12∣+⟩+1⋅∣−⟩)\propto\sum_j\beta_j(C/\lambda_j)|u_j\rangle=\tfrac{1}{\sqrt2}\big(\tfrac12|+\rangle+1\cdot|-\rangle\big). Converting to the computational basis gives 0.75∣0⟩−0.25∣1⟩0.75|0\rangle-0.25|1\rangle, which is exactly A−1b=(0.75,−0.25)⊤A^{-1}b=(0.75,-0.25)^{\top}. Normalizing (∥x∥=0.625=0.7906\lVert x\rVert=\sqrt{0.625}=0.7906) yields ∣x⟩=0.9 ∣0⟩−0.1 ∣1⟩|x\rangle=\mathbf{\sqrt{0.9}\,|0\rangle-\sqrt{0.1}\,|1\rangle}, i.e. amplitudes 0.94870.9487 and −0.3162-0.3162.

Step 5. Success probability. Psuccess=∑j∣βj∣2(C/λj)2=12(1)2+12(0.5)2=0.5+0.125=0.625P_{\mathrm{success}}=\sum_j|\beta_j|^2(C/\lambda_j)^2=\tfrac12(1)^2+\tfrac12(0.5)^2=0.5+0.125=\mathbf{0.625}. Because κ=2\kappa=2 is tiny, the flag reads 11 on 62.5% of runs — no amplification required. Result: ∣x⟩=0.9 ∣0⟩−0.1 ∣1⟩|x\rangle=\sqrt{0.9}\,|0\rangle-\sqrt{0.1}\,|1\rangle, recovered with probability 62.5%, exactly matching A−1b=(0.75,−0.25)A^{-1}b=(0.75,-0.25).

2 · Sizing the exponential speedup (N = 2³⁰)

A sparse system has N=230≈1.07×109N=2^{30}\approx1.07\times10^9 unknowns, row sparsity s=10s=10, condition number κ=100\kappa=100, and you want one expectation value ⟨x∣M∣x⟩\langle x|M|x\rangle to precision ϵ=10−2\epsilon=10^{-2}. Estimate the register sizes and compare the quantum and classical costs.

Step 1. Qubit budget. The solution register needs n=log⁡2N=30n=\log_2 N=\mathbf{30} qubits — the entire billion-dimensional vector lives here. The clock needs t≈log⁡2(κ/ϵ)=log⁡2(104)≈14t\approx\log_2(\kappa/\epsilon)=\log_2(10^4)\approx\mathbf{14} qubits to resolve eigenvalues down to λmin⁡∼1/κ\lambda_{\min}\sim1/\kappa, plus one flag ancilla: about 45\mathbf{45} qubits total to represent a 10910^9-dimensional linear solve.

Step 2. Classical cost. Conjugate gradient must perform matrix-vector products over all NN entries: Tclassical≈Nsκ≈(1.07×109)(10)(10)≈1.1×1011T_{\mathrm{classical}}\approx Ns\sqrt{\kappa}\approx(1.07\times10^9)(10)(10)\approx\mathbf{1.1\times10^{11}} operations — every one of the billion components must be touched at least once.

Step 3. Quantum cost. HHL scales as poly(log⁡N)\mathrm{poly}(\log N) in the dimension: with the improved O~(sκ polylog(N/ϵ))\tilde O(s\kappa\,\mathrm{polylog}(N/\epsilon)) bound and log⁡2N=30\log_2 N=30, the dimension contributes only polynomially in 3030, not in 10910^9. The N→log⁡NN\to\log N collapse is the whole point: a factor of ∼N/poly(log⁡N)≈109/103∼106\sim N/\mathrm{poly}(\log N)\approx 10^9/10^3\sim\mathbf{10^6} in the dimension dependence alone.

Step 4. The catch, quantified. That 10610^6-fold dimension advantage survives only if MM is efficiently measurable, ∣b⟩|b\rangle is efficiently preparable, and the oracle for AA is cheap; and it is throttled by κ=100\kappa=100 (a factor of 100100 overhead) and by s=10s=10. Ask for the full vector instead of ⟨x∣M∣x⟩\langle x|M|x\rangle and the Ω(N)≈109\Omega(N)\approx10^9 read-out cost erases everything. The dimension speedup is exponential (N→log⁡NN\to\log N), 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
AH
Aram Harrow
b. 1980 · MIT · quantum algorithms and the theory of quantum information

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 κ2\kappa^2 and 1/ϵ1/\epsilon 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.

History
1996
— Kitaev frames eigenvalue estimation as quantum phase estimation, the engine HHL will use
2009
— Harrow, Hassidim, and Lloyd publish the quantum algorithm for linear systems of equations
2015
— Aaronson's essay Read the fine print catalogues the input, conditioning, and read-out caveats
2017
— Childs, Kothari, and Somma improve the precision dependence to polylog(1/ε)
2018
— Tang dequantizes several HHL-based recommendation and machine-learning speedups

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 sin⁡(θj/2)=C/λ~j\sin(\theta_j/2)=C/\tilde\lambda_j with θj=2arcsin⁡(C/λ~j)\theta_j=2\arcsin(C/\tilde\lambda_j) is elementary trigonometry. The success probability Θ(1/κ2)\Theta(1/\kappa^2) and the O(κ)O(\kappa) amplification count follow from the Brassard–Høyer–Mosca–Tapp amplitude-amplification bound. The 2×2 worked example (AA with eigenvalues 1,21,2; κ=2\kappa=2; angles 180°,60°180°,60°; ∣x⟩=0.9 ∣0⟩−0.1 ∣1⟩|x\rangle=\sqrt{0.9}\,|0\rangle-\sqrt{0.1}\,|1\rangle; Psuccess=0.625P_{\mathrm{success}}=0.625) and the N=230N=2^{30} resource estimate (n=30n=30, t≈14t\approx14 clock qubits, classical ≈1.1×1011\approx1.1\times10^{11} operations) were checked numerically. The improved runtime O~(sκ polylog(N/ϵ))\tilde O(s\kappa\,\mathrm{polylog}(N/\epsilon)) 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 180°180° and 60°60° rotations, and the post-selection that returns 0.9 ∣0⟩−0.1 ∣1⟩\sqrt{0.9}\,|0\rangle-\sqrt{0.1}\,|1\rangle — 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 x1,…,xNx_1,\dots,x_N; it produces a quantum state ∣x⟩|x\rangle whose amplitudes are those numbers. If you need all of them, you must measure the state many times — tomography costing Ω(N)\Omega(N) — 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 ⟨x∣M∣x⟩\langle x|M|x\rangle, 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 eiAt0e^{iAt_0} well-defined — the unitary has eigenphases eiλjt0e^{i\lambda_j t_0} that the clock register can read. If AA is not Hermitian, you do not give up: you embed it in the Hermitian dilation A~=(0AA†0)\tilde A=\begin{pmatrix}0&A\\A^{\dagger}&0\end{pmatrix} and solve A~ y=(b0)\tilde A\,y=\binom{b}{0}, whose solution has A−1bA^{-1}b 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 κ=∣λmax⁡∣/∣λmin⁡∣\kappa=|\lambda_{\max}|/|\lambda_{\min}| measures how close AA is to singular: a large κ\kappa 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 C≲∣λmin⁡∣∼1/κC\lesssim|\lambda_{\min}|\sim1/\kappa so the rotation angle stays valid for the smallest eigenvalue, which shrinks the success probability to Θ(1/κ2)\Theta(1/\kappa^2). Second, phase estimation must resolve eigenvalues down to ∼1/κ\sim1/\kappa, needing ∼log⁡2κ\sim\log_2\kappa extra clock qubits and longer evolution times. Amplitude amplification softens the first cost from κ2\kappa^2 to κ\kappa, but nothing removes the κ\kappa 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 NN-component vector lives in the amplitudes of log⁡2N\log_2 N qubits, so a million-dimensional problem uses twenty qubits and a billion-dimensional one uses thirty. Phase estimation then acts on all NN 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 N→log⁡NN\to\log N collapse. The catch is symmetric: the same compression that lets you hold NN 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 κ2\kappa^2 in the original success probability becomes κ\kappa 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 1/ϵ1/\epsilon from phase-estimation resolution and Hamiltonian-simulation error becomes polylog(1/ϵ)\mathrm{polylog}(1/\epsilon) in the Childs–Kothari–Somma algorithm, which sidesteps phase estimation entirely and instead approximates the function 1/x1/x directly by a linear combination of unitaries built from a Chebyshev or Fourier expansion. The modern statement, O~(sκ polylog(N/ϵ))\tilde O(s\kappa\,\mathrm{polylog}(N/\epsilon)), 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 AA into the unitary eiAt0e^{iAt_0} — 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 RyR_y rotation on a flag ancilla imprints the amplitude C/λjC/\lambda_j, 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 Θ(1/κ2)\Theta(1/\kappa^2) toward Θ(1)\Theta(1). 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.

Before this

Where this leads