Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Conditional correctness of the bit-query program: from a run of c′c'c′ on (e,n)(e,n)(e,n) to answers about its output

Proved
MIPRE.Cost.Prog.bitQueryProg_runs

by thomasvidick · Oct 12, 2026 · Mathlib 0df444a (Lean v4.33.1)

mipre-formalizationpolynomial-timerecursive-compressionsuccinct-descriptionsuniversal-machine

We work in the ambient cost model: data are binary trees with size\mathrm{size}size the number of nodes, programs (Prog) form a first-order language with de Bruijn variables, and ρ⊢p⇓tr\rho \vdash p \Downarrow^{t} rρ⊢p⇓tr (Eval ρ p r t) means that ppp evaluated in the environment ρ\rhoρ halts with result rrr at cost ttt; a program runs on the input vvv to rrr at cost ttt (Prog.Runs) when [v]⊢p⇓tr[v] \vdash p \Downarrow^t r[v]⊢p⇓tr. Every type α\alphaα with a size-aware encoding (SizedEncoding) has an encoding map enc:α→Data\mathrm{enc} : \alpha \to \mathrm{Data}enc:α→Data and the size ∥a∥=size(enc(a))\|a\| = \mathrm{size}(\mathrm{enc}(a))∥a∥=size(enc(a)) (esize). Programs are encoded by their syntax trees; pairs by enc(a,b)=cons(enc(a),enc(b))\mathrm{enc}(a, b) = \mathrm{cons}(\mathrm{enc}(a), \mathrm{enc}(b))enc(a,b)=cons(enc(a),enc(b)), so that ∥(a,b)∥=∥a∥+∥b∥+1\|(a, b)\| = \|a\| + \|b\| + 1∥(a,b)∥=∥a∥+∥b∥+1; bit strings as lists of bits; and natural numbers in binary, so that ∥m∥≤4∣m∣+1\|m\| \le 4|m| + 1∥m∥≤4∣m∣+1 where ∣m∣|m|∣m∣ is the bit length of mmm (Nat.size).

A universal machine UUU (UniversalMachine) consists of a closed program uuu (U.univ) and a polynomial pU∈N[X]p_U \in \mathbb{N}[X]pU​∈N[X] (U.bound) such that, for every program ccc and data v,rv, rv,r: if ccc runs on vvv to rrr at cost ttt, then uuu runs on cons(enc(c),v)\mathrm{cons}(\mathrm{enc}(c), v)cons(enc(c),v) to rrr at some cost at most pU(∥c∥+size(v)+t)p_U(\|c\| + \mathrm{size}(v) + t)pU​(∥c∥+size(v)+t); and if uuu runs on cons(enc(c),v)\mathrm{cons}(\mathrm{enc}(c), v)cons(enc(c),v) to rrr, then ccc runs on vvv to rrr.

The bit-query program βu\beta_uβu​ (bitQueryProg u) takes as input the encoding of (((c′,e),n),m)(((c', e), n), m)(((c′,e),n),m) — two programs c′c'c′ and eee, a parameter nnn of some encodable type α\alphaα, and a query m∈Nm \in \mathbb{N}m∈N — runs uuu on cons(enc(c′),enc(e,n))\mathrm{cons}(\mathrm{enc}(c'), \mathrm{enc}(e, n))cons(enc(c′),enc(e,n)), that is, simulates c′c'c′ on the input (e,n)(e, n)(e,n), and feeds the resulting string yyy and the query mmm to the bit-indexing program bitAtProg. The answer expected to a bit-query mmm about yyy is (bitQueryAnswer y m)

ans(y,m)={enc(ym)if m<∣y∣,2‾otherwise,\mathrm{ans}(y, m) = \begin{cases} \mathrm{enc}(y_m) & \text{if } m < |y|,\\ \underline{2} & \text{otherwise,}\end{cases}ans(y,m)={enc(ym​)2​​if m<∣y∣,otherwise,​

with ymy_mym​ the mmm-th bit of yyy and 2‾\underline 22​ the unary numeral 222, the out-of-range marker.

Theorem. Let UUU be a universal machine with program uuu and polynomial pUp_UpU​, let c′,ec', ec′,e be programs, n:αn : \alphan:α, y∈{0,1}∗y \in \{0,1\}^*y∈{0,1}∗, m∈Nm \in \mathbb{N}m∈N, and suppose that c′c'c′ runs on (e,n)(e, n)(e,n) to yyy at cost ttt:

[enc(e,n)]⊢c′⇓tenc(y).[\mathrm{enc}(e, n)] \vdash c' \Downarrow^{t} \mathrm{enc}(y).[enc(e,n)]⊢c′⇓tenc(y).

Put s=∥c′∥+∥e∥+∥n∥+ts = \|c'\| + \|e\| + \|n\| + ts=∥c′∥+∥e∥+∥n∥+t and let BUB_UBU​ be the polynomial (bitQueryBound U)

BU(s)=pU(s+1)+(s+1)(s+534)+2s+29.B_U(s) = p_U(s + 1) + (s+1)(s+534) + 2s + 29.BU​(s)=pU​(s+1)+(s+1)(s+534)+2s+29.

Then there is a cost TTT with

T≤BU(s)⋅(∣m∣+1)2and[enc(((c′,e),n),m)]  ⊢  βu  ⇓T  ans(y,m).T \le B_U(s)\cdot (|m| + 1)^2 \qquad\text{and}\qquad [\mathrm{enc}(((c', e), n), m)] \;\vdash\; \beta_u \;\Downarrow^{T}\; \mathrm{ans}(y, m).T≤BU​(s)⋅(∣m∣+1)2and[enc(((c′,e),n),m)]⊢βu​⇓Tans(y,m).

The string yyy is given only implicitly, as the output of c′c'c′ on (e,n)(e, n)(e,n); the theorem says that βu\beta_uβu​ answers any bit-query about it at a cost polynomial in the sizes of the data and in the running time of c′c'c′, times (∣m∣+1)2(|m|+1)^2(∣m∣+1)2. It is the engine of isSuccinctDesc_hardcode: hardcoding ((c′,e),n)((c', e), n)((c′,e),n) into βu\beta_uβu​ turns it into a succinct description of yyy in the sense of blueprint def:succinct, which is how the proofs of the recursive compression lemma (lem:recursive-compression) and of the compressibility criterion describe the string computed at the next recursion level.

Formalization Note The parameter type α\alphaα is any type with a SizedEncoding (in the compression lemmas it is N\mathbb{N}N or a pair of naturals), and nnn enters the bound only through ∥n∥\|n\|∥n∥. The factor (∣m∣+1)2(|m|+1)^2(∣m∣+1)2 comes from the bit walk: it takes at most ∣y∣+1|y| + 1∣y∣+1 iterations, each of cost at most (size(enc(y))+534)(∣m∣+1)2(\mathrm{size}(\mathrm{enc}(y)) + 534)(|m|+1)^2(size(enc(y))+534)(∣m∣+1)2 (bitAtIter_le), and both ∣y∣|y|∣y∣ and size(enc(y))\mathrm{size}(\mathrm{enc}(y))size(enc(y)) are at most ttt, because a run of cost ttt produces a result of size at most ttt (Eval.size_le); this gives the term (s+1)(s+534)(s+1)(s+534)(s+1)(s+534). The term pU(s+1)p_U(s+1)pU​(s+1) is the universal machine's overhead, its argument being ∥c′∥+size(enc(e,n))+t=s+1\|c'\| + \mathrm{size}(\mathrm{enc}(e,n)) + t = s + 1∥c′∥+size(enc(e,n))+t=s+1. The term 2s+292s + 292s+29 absorbs the copies of the arguments and of the intermediate values and the constant-cost rules, after using x≤x(∣m∣+1)2x \le x(|m|+1)^2x≤x(∣m∣+1)2 and ∥m∥≤4∣m∣+1\|m\| \le 4|m|+1∥m∥≤4∣m∣+1. Only the forward direction is stated: a run of c′c'c′ yields a run of βu\beta_uβu​; nothing is claimed about βu\beta_uβu​ when c′c'c′ does not halt.

Preamble
import Mathlib.Algebra.Polynomial.Eval.Defs
import Mathlib.Data.List.Basic
import Mathlib.Data.Nat.Bits
import Mathlib.Data.Nat.Notation
import Mathlib.Data.Nat.Size
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
import Definitions.Def_MIPRE_Foundations_Cost_Basic
import Definitions.Def_MIPRE_Foundations_Cost_Encoding
import Definitions.Def_MIPRE_Foundations_Cost_PolyTime
import Definitions.Def_MIPRE_Foundations_Cost_Closure
import Definitions.Def_MIPRE_Foundations_Cost_Loops
import Definitions.Def_MIPRE_Foundations_Cost_Unary
import Definitions.Def_MIPRE_Foundations_Cost_Numeric
import Definitions.Def_MIPRE_Foundations_Cost_BitQuery
import Definitions.Def_MIPRE_Foundations_Cost_Toolkit
import Definitions.Def_MIPRE_Foundations_Cost_Succinct

open MIPRE
open MIPRE.Cost
open MIPRE.Cost.Prog
open Polynomial
Formal statement
theorem MIPRE.Cost.Prog.bitQueryProg_runs (U : UniversalMachine) {α : Type*} [SizedEncoding α]
    (c' e : Prog) (n : α) (y : BitStr) (m : ℕ) {t : ℕ}
    (hrun : c'.Runs (encode (e, n)) (encode y) t) :
    ∃ T ≤ (bitQueryBound U).eval (esize c' + esize e + esize n + t) * (Nat.size m + 1) ^ 2,
      (bitQueryProg U.univ).Runs (encode (((c', e), n), m)) (bitQueryAnswer y m) T := by sorry
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/Cost/Succinct.lean#L73-L157; internal lemma of the formalization of blueprint def:succinct, used in lem:recursive-compression, https://vidick.github.io/MIPRE-formalization/blueprint/; [MNY] A. Marks, S. S. Nezhadi, H. Yuen, The recursive compression method for proving undecidability results, manuscript, Definition 2.4 and Lemma 5.1

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