Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Amplitude encoding with O(log d) QRAM queries and O(log d (log d + log 1/ϵ)) two-qubit gates after Õ(d) classical preprocessing (corrected)

Proved
QAlgorithms.Nannicini.ampEncoding_qram

by Goku · Oct 13, 2026 · Mathlib 0df444a (Lean v4.33.1)

lecture-notesnanniciniquantum-information

This is a corrected form of the QRAM speed-up for amplitude encoding.

QRAM. For words Mj∈{0,1}qM_j \in \{0,1\}^qMj​∈{0,1}q indexed by j∈{0,1}aj \in \{0,1\}^aj∈{0,1}a, the QRAM is the unitary UQRAM∣j⟩∣y⟩=∣j⟩∣y⊕Mj⟩U_{\mathrm{QRAM}} |j\rangle |y\rangle = |j\rangle |y \oplus M_j\rangleUQRAM​∣j⟩∣y⟩=∣j⟩∣y⊕Mj​⟩ (Definition 5.39). Its size is 2aq2^a q2aq.

Classical preprocessing. It is a straight-line program over the reals. It reads Re⁡x0,Im⁡x0,Re⁡x1,…\operatorname{Re} x_0, \operatorname{Im} x_0, \operatorname{Re} x_1, \dotsRex0​,Imx0​,Rex1​,…, and each instruction is one of +,−,×,÷,⋅,arccos⁡+, -, \times, \div, \sqrt{\cdot}, \arccos+,−,×,÷,⋅​,arccos, the complex argument, or a rational constant. Its cost is its number of instructions. Word jjj of the QRAM is the qqq-bit binary expansion of the integer part of a designated program value.

Circuit. It acts on n=⌈log⁡2d⌉n = \lceil \log_2 d \rceiln=⌈log2​d⌉ output qubits plus www ancillas, all starting in ∣0⟩|0\rangle∣0⟩. It consists of arbitrary two-qubit gates and uncontrolled calls to UQRAMU_{\mathrm{QRAM}}UQRAM​ (or its inverse).

There are constants C>0C > 0C>0 and c∈Nc \in \mathbb{N}c∈N such that for every d≥1d \ge 1d≥1 and every ϵ>0\epsilon > 0ϵ>0 there exist a,q,wa, q, wa,q,w, a program PPP, an address map and a circuit QQQ, none depending on xxx, with the following properties. Write L=log⁡(2+d)+log⁡(2+1/ϵ)L = \log(2+d) + \log(2+1/\epsilon)L=log(2+d)+log(2+1/ϵ). Then:

  1. the QRAM size satisfies 2aq≤CdLc2^a q \le C d L^c2aq≤CdLc, and PPP has at most CdLcC d L^cCdLc instructions;
  2. QQQ makes at most Clog⁡(2+d)C \log(2+d)Clog(2+d) QRAM calls and uses at most Clog⁡(2+d) LC \log(2+d)\, LClog(2+d)L two-qubit gates;
  3. for every nonzero x∈Cdx \in \mathbb{C}^dx∈Cd, with the QRAM loaded by running PPP on xxx,
∥Q∣0n+w⟩−∣amp(x)⟩⊗∣0w⟩∥≤ϵ.\bigl\| Q |0^{n+w}\rangle - |\mathrm{amp}(x)\rangle \otimes |0^w\rangle \bigr\| \le \epsilon .​Q∣0n+w⟩−∣amp(x)⟩⊗∣0w⟩​≤ϵ.

Once the classical data structure has been written, the state ∣amp(x)⟩|\mathrm{amp}(x)\rangle∣amp(x)⟩ can be prepared with exponentially fewer gates than the O~(d)\tilde O(d)O~(d) of Corollary 5.37.

Formalization Note The printed corollary claims O(log⁡2d)O(\log^2 d)O(log2d) gates for every ϵ\epsilonϵ. Its proof, however, fixes the word size q=O(log⁡d)q = O(\log d)q=O(logd), which limits the reachable error. The statement therefore lets qqq, and with it the gate count, grow with log⁡(1/ϵ)\log(1/\epsilon)log(1/ϵ). For ϵ≥1/poly(d)\epsilon \ge 1/\mathrm{poly}(d)ϵ≥1/poly(d) this is the printed bound. The source does not define its classical cost model; the one used here is fixed in the Lean definitions ArithInstr and arithRun.

Preamble
import Definitions.Def_QAlgorithms_Defs_GradientMethods
import Definitions.Def_QAlgorithms_Nannicini_Ch05c_Model
set_option autoImplicit false
Formal statement
namespace QAlgorithms.Nannicini










/-- Corrected statement. Nannicini p.130, Corollary 5.45, as printed: "Given a classical
description of `x ∈ ℂ^d` in finite precision and a QRAM of size `Õ(d)`, there is a circuit that
implements the mapping `|0⟩ → |amp(x)⟩` with error at most `ϵ` using `O(log d)` QRAM queries,
`O(log² d)` additional gates, and `Õ(d)` classical arithmetic operations to initialize the QRAM
data structure."

What was changed. (1) The gate bound `O(log² d)` is replaced by
`O(log d · (log d + log(1/ϵ)))`, and the QRAM size and the classical cost `Õ(d)` may carry
polylogarithmic factors in `1/ϵ`. This is the source's own count on p.130, `O(n)` queries and
`O(nq)` gates with `n = log d` levels and word size `q`, with `q` allowed to grow like
`log d + log(1/ϵ)`; for `ϵ ≥ 1/poly(d)` it is the printed `O(log² d)`. (2) "Classical arithmetic
operations" are counted in the straight-line real-arithmetic model `ArithInstr` (one operation
per `+, −, ×, ÷, √, arccos, arg` or constant); the QRAM is written classically from the
program's values (`qramWords`).

Why. The printed proof fixes `q = O(log d)` independently of `ϵ` ("this already gives precision
exponential in d"), so its `O(log² d)` gates cannot reach an arbitrary error `ϵ`: fixed-point
words of `O(log d)` bits give error at least about `2^{-q}`. The source gives no cost model for
"classical arithmetic operations".

The model. The circuit runs on the `n = ⌈log d⌉` output qubits plus `w` ancillas that start in
`|0⟩`, over arbitrary two-qubit gates (Rem. 5.44: "additional (two-qubit) gates"), and calls the
QRAM `U_QRAM` of Def. 5.39 (address `a` qubits, words of `q` bits), uncontrolled, possibly as its
inverse. The circuit, the program and the addressing do not depend on `x`: `x` enters only through
the QRAM contents (Rem. 5.41). Error is the Euclidean distance from `|amp(x)⟩ ⊗ |0^w⟩`, as in
Cor. 5.37. The constants `C, c` come before `d`, `x`, `ϵ`. -/
theorem ampEncoding_qram :
    ∃ C : ℝ, 0 < C ∧ ∃ c : ℕ, ∀ d : ℕ, 1 ≤ d → ∀ ε : ℝ, 0 < ε →
      ∃ (a q w : ℕ) (P : List ArithInstr) (addr : Qubits a → ℕ)
        (circ : OracleCircuit twoQubitGateSet (fun _ : Fin 1 => a + q) (Nat.clog 2 d + w)),
        (2 : ℝ) ^ a * q ≤ C * d * (Real.log (2 + d) + Real.log (2 + 1 / ε)) ^ c ∧
        (P.length : ℝ) ≤ C * d * (Real.log (2 + d) + Real.log (2 + 1 / ε)) ^ c ∧
        (circ.queryCount 0 : ℝ) ≤ C * Real.log (2 + d) ∧
        (circ.gateCount : ℝ) ≤
          C * Real.log (2 + d) * (Real.log (2 + d) + Real.log (2 + 1 / ε)) ∧
        (∀ s ∈ circ, uncontrolledStep s) ∧
        ∀ x : Fin d → ℂ, x ≠ 0 →
          ‖act (circ.unitary fun _ => qramUnitary a q (qramWords a q P addr x))
              (zeroKet (Nat.clog 2 d + w)) -
            WithLp.toLp 2 (fun z : Qubits (Nat.clog 2 d + w) =>
              if ∀ k : Fin w, z (Fin.natAdd (Nat.clog 2 d) k) = false then
                padState (Nat.clog 2 d) (normalizedVec (WithLp.toLp 2 x))
                  (fun i => z (Fin.castAdd w i))
              else 0)‖ ≤ ε := by
  sorry



end QAlgorithms.Nannicini
Source
Giacomo Nannicini, Quantum algorithms for optimizers, 2025, v5; notes dated 9 July 2025, PDF p. 130, Corollary 5.45. https://arxiv.org/pdf/2408.07086v5
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5

Undefined names. The statement uses five names that are not in the definition layer shown: ArithInstr, qramUnitary, qramWords, uncontrolledStep and IsQuantumMembershipOracle. The read-back treats them as opaque and names them literally. Everything else is unfolded.

The claim. There exist a real constant C>0C > 0C>0 and a natural number ccc such that the following holds. For every natural number d≥1d \ge 1d≥1 and every real ε>0\varepsilon > 0ε>0, there exist:

  • natural numbers a,q,wa, q, wa,q,w;
  • a finite list PPP of objects of type ArithInstr;
  • a function addr:{0,1}a→N\mathrm{addr} : \{0,1\}^a \to \mathbb Naddr:{0,1}a→N;
  • an oracle circuit C\mathcal CC.

The circuit C\mathcal CC has the following form:

  • It acts on n:=⌈log⁡2d⌉+wn := \lceil \log_2 d \rceil + wn:=⌈log2​d⌉+w wires. Here ⌈log⁡2d⌉\lceil \log_2 d\rceil⌈log2​d⌉ is the least ℓ\ellℓ with d≤2ℓd \le 2^\elld≤2ℓ, so it is 000 when d=1d = 1d=1.
  • Its gate set is "all unitary 222-qubit gates", i.e. every gate ggg with arity 222 whose 4×44\times 44×4 matrix is unitary.
  • It has a single oracle, of arity a+qa + qa+q.

Such a circuit is a finite list of steps, applied head first. Each step is one of two kinds:

  • A gate from the gate set, placed on an ordered pair of distinct wires.
  • A call to the oracle, possibly its adjoint, possibly controlled on a further wire not among its targets, placed on an ordered tuple of a+qa+qa+q distinct wires.

The data must satisfy the following conditions. All logarithms are natural logarithms. Write

L:=log⁡(2+d)+log⁡(2+1/ε).L := \log(2+d) + \log(2 + 1/\varepsilon).L:=log(2+d)+log(2+1/ε).
  1. Data-structure size: 2a⋅q≤C d Lc2^a \cdot q \le C\, d\, L^c2a⋅q≤CdLc.
  2. Program length: the length of PPP satisfies ∣P∣≤C d Lc|P| \le C\, d\, L^c∣P∣≤CdLc.
  3. Queries: the number of oracle-call steps of C\mathcal CC is at most Clog⁡(2+d)C \log(2+d)Clog(2+d). Adjoint and controlled calls are counted alike.
  4. Other gates: the number of gate (non-oracle) steps of C\mathcal CC is at most Clog⁡(2+d)⋅LC \log(2+d)\cdot LClog(2+d)⋅L.
  5. Step condition: every step sss of C\mathcal CC satisfies the predicate uncontrolledStep (not shown).
  6. Accuracy: for every nonzero vector x∈Cdx \in \mathbb C^dx∈Cd, the inequality below holds.

The accuracy inequality is

∥ UC[Ox] ∣0n⟩  −  τx∥≤ε,Ox:=qramUnitarya,q(qramWordsa,q(P,addr,x)).\Big\| \, U_{\mathcal C}\big[O_x\big]\, |0^{n}\rangle \;-\; \tau_x \Big\| \le \varepsilon, \qquad O_x := \mathtt{qramUnitary}_{a,q}\big(\mathtt{qramWords}_{a,q}(P, \mathrm{addr}, x)\big).​UC​[Ox​]∣0n⟩−τx​​≤ε,Ox​:=qramUnitarya,q​(qramWordsa,q​(P,addr,x)).

The symbols in it mean the following:

  • UC[O]U_{\mathcal C}[O]UC​[O] is the product of the step matrices, with the first step rightmost.

    • A gate step contributes its 4×44\times44×4 matrix acting on its two wires, tensored with the identity elsewhere.
    • An oracle step contributes OOO (or O†O^\daggerO†) acting on its wires. In the controlled case, it contributes ∣0⟩⟨0∣⊗I+∣1⟩⟨1∣⊗O(†)|0\rangle\langle0| \otimes I + |1\rangle\langle1|\otimes O^{(\dagger)}∣0⟩⟨0∣⊗I+∣1⟩⟨1∣⊗O(†) with the control wire first.
  • ∣0n⟩|0^n\rangle∣0n⟩ is the all-zeros basis vector.

  • τx\tau_xτx​ is the vector whose amplitude at a bit string z∈{0,1}nz \in \{0,1\}^nz∈{0,1}n is defined by splitting z=(zmain,zanc)z = (z_{\text{main}}, z_{\text{anc}})z=(zmain​,zanc​) into its first ⌈log⁡2d⌉\lceil\log_2 d\rceil⌈log2​d⌉ bits and last www bits:

    • if zanc=0wz_{\text{anc}} = 0^wzanc​=0w, the amplitude is xj/∥x∥x_j / \|x\|xj​/∥x∥, where jjj is the integer with binary expansion zmainz_{\text{main}}zmain​ (most significant bit first), provided j<dj < dj<d;
    • it is 000 if j≥dj \ge dj≥d;
    • it is 000 whenever zanc≠0wz_{\text{anc}} \ne 0^wzanc​=0w.

    In short, τx=∣x/∥x∥⟩⊗∣0w⟩\tau_x = |x/\|x\|\rangle \otimes |0^w\rangleτx​=∣x/∥x∥⟩⊗∣0w⟩, with x/∥x∥x/\|x\|x/∥x∥ zero-padded to length 2⌈log⁡2d⌉2^{\lceil\log_2 d\rceil}2⌈log2​d⌉.

Dependencies.

  • a,q,w,P,addra, q, w, P, \mathrm{addr}a,q,w,P,addr and C\mathcal CC depend on ddd and ε\varepsilonε only, not on xxx.
  • The only xxx-dependence is through the oracle matrix OxO_xOx​.
  • No property of qramWords or qramUnitary (for instance unitarity of OxO_xOx​) is asserted here.

Edge cases.

  • An oracle step can only exist if a+q≤na + q \le na+q≤n.
  • τx\tau_xτx​ has norm 111. So if UC[Ox]U_{\mathcal C}[O_x]UC​[Ox​] happens to be unitary, the accuracy condition is automatic once ε≥2\varepsilon \ge 2ε≥2.
Human review
  • Endorsed by Shuze Chen · Oct 13, 2026

    Confirmed by the moderator at approval.

  • Endorsed by Goku · Oct 13, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me