Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Correctness of compiling straight-line programs to reversible lookup circuits

Proved
OPI.compile_spec

by sragavan · Nov 11, 2026 · Mathlib 0df444a (Lean v4.33.1)

lean-formalizationquantum-algorithmstwo-fold-opi-construction

A straight-line program over a value type VVV is a list of instructions dst:=op(src1,…,srcr)\mathit{dst}:=\mathit{op}(\mathit{src}_1,\dots,\mathit{src}_r)dst:=op(src1​,…,srcr​) acting on environments ρ:N→V\rho:\mathbb N\to Vρ:N→V. Running it (kRun\mathrm{kRun}kRun) applies the updates ρ←ρ[dst↦op(ρ(src))]\rho\leftarrow\rho[\mathit{dst}\mapsto\mathit{op}(\rho(\mathit{src}))]ρ←ρ[dst↦op(ρ(src))] in order. Values carry a fixed-length binary encoding enc:V→{0,1}L\mathrm{enc}:V\to\{0,1\}^{L}enc:V→{0,1}L with a left inverse. Each identifier iii has a register reg(i)\mathrm{reg}(i)reg(i) of qubits. The compiler turns each instruction into one table lookup that XORs enc(op(decoded sources))\mathrm{enc}(\mathit{op}(\text{decoded sources}))enc(op(decoded sources)) into the destination register, using ancillas asasas and a flag fff.

Hypotheses.

  • Layout up to NNN: for i<Ni<Ni<N the registers have length LLL, have no repeated wires, are pairwise disjoint, and avoid asasas and fff.
  • Well-formedness (relative to the set SSS of identifiers defined initially): every source is defined, <N<N<N, and the sources of an instruction are distinct; every destination is fresh, <N<N<N, and written by only one instruction.
  • Every source register list fits the lookup ancillas: r⋅L≤∣as∣+2r\cdot L\le|as|+2r⋅L≤∣as∣+2.
  • In the input configuration zzz, reg(i)\mathrm{reg}(i)reg(i) holds enc(ρ(i))\mathrm{enc}(\rho(i))enc(ρ(i)) for every i∈Si\in Si∈S; all destination registers are 000; asasas and fff are 000.

Statement. After the compiled reversible circuit,

reg(i) holds enc(kRun(prog,ρ)(i))for every i∈S∪{destinations},\mathrm{reg}(i)\ \text{holds}\ \mathrm{enc}\big(\mathrm{kRun}(\mathit{prog},\rho)(i)\big)\quad\text{for every } i\in S\cup\{\text{destinations}\},reg(i) holds enc(kRun(prog,ρ)(i))for every i∈S∪{destinations},

and every wire outside the destination registers is unchanged. In particular, sources and scratch are restored.

This is how the classical relinearization decoder (Gauss–Jordan elimination over Fq\mathbb F_qFq​, written as a straight-line program) becomes a reversible circuit inside the quantum decoder.

Preamble
import Definitions.Def_TwoFoldOPI_CL_Part01
import Mathlib
import Definitions.Def_QAlgorithms_Defs_Circuit
import Definitions.Def_QAlgorithms_Defs_GradientMethods
import Definitions.Def_QAlgorithms_Defs_OPIOraclePrograms
import Definitions.Def_QAlgorithms_Defs_OPIUniformity
import Definitions.Def_QAlgorithms_Defs_Fourier
import Definitions.Def_TwoFoldOPI_elemBits
import Definitions.Def_TwoFoldOPI_schurSquare
import Definitions.Def_TwoFoldOPI_schurFailureSum
import Definitions.Def_CodingTheory
import Definitions.Def_OAIThreeMachineSched01
import Definitions.Def_CookLevin_Cost
import Definitions.Def_TwoFoldOPI_codeOf
import Definitions.Def_TwoFoldOPI_solves
import Definitions.Def_TwoFoldOPI_Input
import Definitions.Def_TwoFoldOPI_CLSerializableF
open OPI
open QAlgorithms
variable {n : ℕ} {V : Type}
Formal statement
theorem OPI.compile_spec (E : Enc V) (reg : ℕ → List (Fin n)) (as : List (Fin n)) (f : Fin n) (N : ℕ)
    (hlay : Layout E reg as f N) :
    ∀ (Is : List (KIns V)) (S : ℕ → Prop) (ρ : ℕ → V) (z : Qubits n), PWF N S Is →
      (∀ i, S i → i < N) → (∀ I ∈ Is, I.dst < N) →
      (∀ I ∈ Is, I.src.length * E.L ≤ as.length + 2) →
      Encodes E reg S ρ z → (∀ I ∈ Is, ∀ a ∈ reg I.dst, z a = false) →
      (∀ a ∈ as ++ [f], z a = false) →
      Encodes E reg (fun i => S i ∨ ∃ I ∈ Is, I.dst = i) (kRun Is ρ) (revAct (compile E reg as f Is) z) ∧
      (∀ a, (∀ I ∈ Is, a ∉ reg I.dst) → revAct (compile E reg as f Is) z a = z a) := by sorry
Source
Formalization of Theorem 7.4 (algorithmic part), repository https://github.com/sragavan99/lean-prove2me-fills/blob/db81d0d4e3fa008609ed37789a2eb2f6f08ee48d/WorkInProgress/QuantumOPIVariants/OPI/SSA.lean#L105-L190

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