Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Amplitude encoding of a complex vector to error ϵ with Õ(d) gates from {H, T, CX}

Proved
QAlgorithms.Nannicini.ampEncoding_gateComplexity

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

lecture-notesnanniciniquantum-information

For a nonzero vector x∈Cdx \in \mathbb{C}^dx∈Cd let n=⌈log⁡2d⌉n = \lceil \log_2 d \rceiln=⌈log2​d⌉ and

∣amp(x)⟩=∑j=0d−1xj∥x∥∣ȷ⃗⟩|\mathrm{amp}(x)\rangle = \sum_{j=0}^{d-1} \frac{x_j}{\|x\|} |\vec\jmath\rangle∣amp(x)⟩=j=0∑d−1​∥x∥xj​​∣​⟩

be its amplitude encoding on nnn qubits, where ȷ⃗\vec\jmath​ is the nnn-bit binary expansion of jjj (most significant bit first) and the basis states with j≥dj \ge dj≥d have amplitude 000. Circuits are built from the universal gate set {H,T,CX}\{H, T, CX\}{H,T,CX}, and their size is their number of gates.

There are constants C>0C > 0C>0 and c∈Nc \in \mathbb{N}c∈N such that for every d≥1d \ge 1d≥1, every nonzero x∈Cdx \in \mathbb{C}^dx∈Cd and every ϵ>0\epsilon > 0ϵ>0 there exist a number www of ancilla qubits and a circuit QQQ on n+wn + wn+w qubits with

∣Q∣≤C d (log⁡(2+d)+log⁡(2+1/ϵ))cand∥Q∣0n+w⟩−∣amp(x)⟩⊗∣0w⟩∥≤ϵ.|Q| \le C\, d\, \bigl(\log(2+d) + \log(2 + 1/\epsilon)\bigr)^{c} \quad\text{and}\quad \bigl\| Q |0^{n+w}\rangle - |\mathrm{amp}(x)\rangle \otimes |0^w\rangle \bigr\| \le \epsilon .∣Q∣≤Cd(log(2+d)+log(2+1/ϵ))cand​Q∣0n+w⟩−∣amp(x)⟩⊗∣0w⟩​≤ϵ.

The circuit may depend on xxx (it is produced from the classical description of xxx); the constants do not depend on ddd, xxx or ϵ\epsilonϵ. This is the gate cost of loading a classical vector into the amplitudes of a quantum state in the standard circuit model, against which the QRAM speedup of §5.3 is measured.

Formalization Note O~(d)\tilde O(d)O~(d) with polylogarithmic dependence on 1/ϵ1/\epsilon1/ϵ (as the source's proof says) is written as CdC dCd times a power of log⁡(2+d)+log⁡(2+1/ϵ)\log(2+d) + \log(2+1/\epsilon)log(2+d)+log(2+1/ϵ). The error is the Euclidean distance of the produced state from ∣amp(x)⟩|\mathrm{amp}(x)\rangle∣amp(x)⟩ with the ancillas back in ∣0⟩|0\rangle∣0⟩. The statement covers every nonzero x∈Cdx \in \mathbb{C}^dx∈Cd, which includes every finite-precision description.

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


/-- Nannicini p.126, Corollary 5.37: "Given a classical description of `x ∈ ℂ^d` in finite
precision, there is a circuit that implements the mapping `|0⟩ → |amp(x)⟩` with error at most
`ϵ` with gate complexity `Õ(d)`."

The circuit is built from the classical data `x` (Rem. 5.35), over the gate set `{H, T, CX}` of
Thm. 1.43, on the `n = ⌈log d⌉` qubits of `|amp(x)⟩` plus `w` ancillas that start in `|0⟩`.
"Error at most `ϵ`" is the Euclidean distance between the produced state and
`|amp(x)⟩ ⊗ |0^w⟩` (§1.3.6). `Õ(d)` with the dependence on `ϵ` polylogarithmic (p.127) is
`C · d · (log(2 + d) + log(2 + 1/ϵ))^c` with constants `C > 0`, `c` chosen before `d`, `x`, `ϵ`.
The statement is for every nonzero `x ∈ ℂ^d`, which contains every finite-precision input. -/
theorem ampEncoding_gateComplexity :
    ∃ C : ℝ, 0 < C ∧ ∃ c : ℕ, ∀ (d : ℕ) (x : Fin d → ℂ), x ≠ 0 → ∀ ε : ℝ, 0 < ε →
      ∃ (w : ℕ) (circ : Circuit htcxGateSet (Nat.clog 2 d + w)),
        (circ.size : ℝ) ≤ C * d * (Real.log (2 + d) + Real.log (2 + 1 / ε)) ^ c ∧
        ‖act circ.unitary (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. 126, Corollary 5.37. https://arxiv.org/pdf/2408.07086v5
Read-back

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

The gate set. Circuits use the gate set consisting of exactly three gates:

  • the Hadamard gate H=12(111−1)H = \frac{1}{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}H=2​1​(11​1−1​);
  • the gate T=diag(1,eiπ/4)T = \mathrm{diag}(1, e^{i\pi/4})T=diag(1,eiπ/4);
  • the CNOT gate, with first qubit as control.

T†T^\daggerT† and other inverses are not included.

A circuit on mmm wires is a finite list of such gates. Each gate is placed on an ordered tuple of distinct wires, the gates are applied in list order, and the circuit acts as the identity on the wires a gate does not touch. Its unitary is the product of the embedded gate matrices, first gate rightmost. Its size is the number of gates in the list.

Notation.

  • log⁡\loglog is the natural logarithm.
  • q=⌈log⁡2d⌉q = \lceil \log_2 d\rceilq=⌈log2​d⌉ is the least kkk with 2k≥d2^k \ge d2k≥d, so q=0q = 0q=0 when d≤1d \le 1d≤1.
  • For a bit string u∈{0,1}qu \in \{0,1\}^qu∈{0,1}q, val(u)\mathrm{val}(u)val(u) is its integer value, most significant bit first.

Claim. There exist a real constant C>0C > 0C>0 and a natural number ccc (possibly 000) with the following property. For every natural number ddd, every nonzero complex vector x∈Cdx \in \mathbb{C}^dx∈Cd (indexed 0,…,d−10, \dots, d-10,…,d−1), and every real ε>0\varepsilon > 0ε>0, there exist:

  • a number w∈Nw \in \mathbb{N}w∈N of ancilla wires, which may depend on ddd, xxx and ε\varepsilonε, and
  • a circuit C\mathcal{C}C over this gate set on q+wq + wq+w wires,

such that two conditions hold.

  1. Size bound.
∣C∣≤C⋅d⋅(log⁡(2+d)+log⁡(2+1/ε))c.|\mathcal{C}| \le C \cdot d \cdot \big(\log(2+d) + \log(2 + 1/\varepsilon)\big)^{c}.∣C∣≤C⋅d⋅(log(2+d)+log(2+1/ε))c.
  1. Accuracy. In Euclidean norm,
∥UC ∣0q+w⟩−∣x~⟩⊗∣0w⟩∥≤ε.\Big\| U_{\mathcal C}\,|0^{q+w}\rangle - |\tilde x\rangle \otimes |0^{w}\rangle \Big\| \le \varepsilon .​UC​∣0q+w⟩−∣x~⟩⊗∣0w⟩​≤ε.
  • UCU_{\mathcal C}UC​ is the circuit's unitary.
  • ∣0q+w⟩|0^{q+w}\rangle∣0q+w⟩ is the all-zeros basis state.
  • The target state is ∣x~⟩⊗∣0w⟩|\tilde x\rangle \otimes |0^{w}\rangle∣x~⟩⊗∣0w⟩, where the ancilla state ∣0w⟩|0^w\rangle∣0w⟩ occupies the last www wires.
  • ∣x~⟩|\tilde x\rangle∣x~⟩ is the qqq-qubit state on the first qqq wires with amplitude on basis string u∈{0,1}qu \in \{0,1\}^qu∈{0,1}q equal to
⟨u∣x~⟩={xval(u)/∥x∥if val(u)<d,0if val(u)≥d.\langle u|\tilde x\rangle = \begin{cases} x_{\mathrm{val}(u)} / \|x\| & \text{if } \mathrm{val}(u) < d,\\ 0 & \text{if } \mathrm{val}(u) \ge d.\end{cases}⟨u∣x~⟩={xval(u)​/∥x∥0​if val(u)<d,if val(u)≥d.​
  • The target has amplitude 000 on every basis state whose last www bits are not all 000.
  • The comparison is exact in the global phase: no phase factor is allowed.

Edge cases.

  • d=0d = 0d=0. The only vector in C0\mathbb{C}^0C0 is 000, so the hypothesis x≠0x \ne 0x=0 cannot be satisfied and this case holds vacuously.
  • d=1d = 1d=1. Here q=0q = 0q=0, and ∣x~⟩|\tilde x\rangle∣x~⟩ is the scalar x0/∣x0∣x_0/|x_0|x0​/∣x0​∣, a unit complex number. The circuit must then approximate x0∣x0∣ ∣0w⟩\tfrac{x_0}{|x_0|}\,|0^w\rangle∣x0​∣x0​​∣0w⟩ on the www ancilla wires alone.
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