Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

The bit-query answer and the bit-indexing program of succinct descriptions

Definition
MIPRE_Foundations_Cost_BitQuery

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

mipre-formalizationpolynomial-timerecursive-compressionsuccinct-descriptions

This bundle defines the answer a succinct description must give to a bit query, and the program that computes it from an explicitly given string.

MIPRE.Cost.bitQueryAnswer x mx\ mx m, for a bit string x∈{0,1}∗x \in \{0,1\}^*x∈{0,1}∗ and an index m∈Nm \in \mathbb{N}m∈N, is the encoding of the mmm-th bit of xxx (indices from 000) when m<∣x∣m < |x|m<∣x∣, and the out-of-range marker, the unary numeral ofNat(2)\mathrm{ofNat}(2)ofNat(2), when m≥∣x∣m \ge |x|m≥∣x∣:

bitQueryAnswer(x,m)={encode(xm)m<∣x∣,ofNat(2)m≥∣x∣.\mathrm{bitQueryAnswer}(x, m) = \begin{cases} \mathrm{encode}(x_m) & m < |x|,\\ \mathrm{ofNat}(2) & m \ge |x|.\end{cases}bitQueryAnswer(x,m)={encode(xm​)ofNat(2)​m<∣x∣,m≥∣x∣.​

This is the value φe(m)\varphi_e(m)φe​(m) that a succinct description (e,n)(e, n)(e,n) of xxx must return ([MNY, Definition 2.4]).

The cost accounting of the bit-indexing program is packaged in three functions of the bit length L=∣m∣L = |m|L=∣m∣ of the index: MIPRE.Cost.Prog.zeroBound L=(L+1)(4L+9)L = (L + 1)(4L + 9)L=(L+1)(4L+9) bounds one zero test, MIPRE.Cost.Prog.decBound L=(L+2)(60L+100)L = (L + 2)(60L + 100)L=(L+2)(60L+100) bounds one decrement, and MIPRE.Cost.Prog.bitAtIter sy L=sy+8L+zeroBound(L)+decBound(L)+20s_y\ L = s_y + 8L + \mathrm{zeroBound}(L) + \mathrm{decBound}(L) + 20sy​ L=sy​+8L+zeroBound(L)+decBound(L)+20 bounds one iteration when the string has size at most sys_ysy​.

MIPRE.Cost.Prog.bitAtBody and MIPRE.Cost.Prog.bitAtProg =loop bitAtBody= \mathtt{loop}\ \mathrm{bitAtBody}=loop bitAtBody act on the state cons(y,m)\mathtt{cons}(y, m)cons(y,m), with yyy an encoded bit string and mmm an encoded binary index: the body stops with ofNat(2)\mathrm{ofNat}(2)ofNat(2) if yyy is exhausted; otherwise it tests mmm for zero with isZeroProg, stopping with the head bit of yyy if m=0m = 0m=0, and continuing with the tail of yyy and the index m−1m - 1m−1 (computed by decProg) otherwise. Thus bitAtProg on cons(encode y,encode m)\mathtt{cons}(\mathrm{encode}\ y, \mathrm{encode}\ m)cons(encode y,encode m) computes bitQueryAnswer(y,m)\mathrm{bitQueryAnswer}(y, m)bitQueryAnswer(y,m), at a cost of at most (∣y∣+1)⋅bitAtIter(size y,∣m∣)(|y| + 1)\cdot\mathrm{bitAtIter}(\mathrm{size}\ y, |m|)(∣y∣+1)⋅bitAtIter(size y,∣m∣).

The lemmas proved in the bundle are the three recursion equations of bitQueryAnswer: on the empty string every answer is the marker ofNat(2)\mathrm{ofNat}(2)ofNat(2); on b::xb :: xb::x the answer to the query 000 is encode(b)\mathrm{encode}(b)encode(b), and the answer to the query m+1m + 1m+1 is the answer to the query mmm about xxx.

Formalization Note. The index is walked in binary: each zero test and each decrement copies the index, so one iteration costs O(size(y)+∣m∣2)O(\mathrm{size}(y) + |m|^2)O(size(y)+∣m∣2) and the whole walk O(∣y∣⋅(size(y)+∣m∣2))O(|y|\cdot(\mathrm{size}(y) + |m|^2))O(∣y∣⋅(size(y)+∣m∣2)). This quadratic dependence on ∣m∣|m|∣m∣ is the origin of the factor (∣m∣+1)2(|m| + 1)^2(∣m∣+1)2 in the succinctness time budget (n+1)(∣m∣+1)2(n + 1)(|m| + 1)^2(n+1)(∣m∣+1)2 of IsSuccinctDesc, which replaces the paper's bound of nnn on every input (vacuous in a model that charges for reading its input). The marker for an out-of-range query is the unary numeral 222, following [MNY], where φe(m)=2\varphi_e(m) = 2φe​(m)=2 for m≥∣x∣m \ge |x|m≥∣x∣.

Definition code
/-
Copyright (c) 2026 Thomas Vidick. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Vidick
-/
/- Generated for Prove2Me from vidick/MIPRE-formalization@70cbf1c, MIPRE/Foundations/Cost/BitQuery.lean (definition bundle: declarations the uploaded statements rest on);
   produced mechanically by prove2me/tools/gen.py, never edited by hand. -/
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

/-!
# The bit-query program

`bitAtProg` on `(y, m)` — a bit string and a binary index — returns the `m`-th bit of `y`,
or the out-of-range marker `ofNat 2`: this is the answer a succinct description must give
([MNY, Definition 2.4]; `bitQueryAnswer`). It walks `y` while decrementing `m` in binary,
testing for zero at each step, so its cost is `(|y| + 1) · bitAtIter (size y) |m|` with
`bitAtIter` quadratic in `|m|` (each zero test and decrement copies the index). This is
where the `(|m| + 1) ^ 2` factor of the succinctness budget of `IsSuccinctDesc` comes from.
-/

namespace MIPRE.Cost

/-- The answer a succinct description must give to the bit-query `m` about the string
`x`: the `m`-th bit for `m < |x|`, and the out-of-range marker (the unary numeral `2`)
otherwise. -/
def bitQueryAnswer (x : BitStr) (m : ℕ) : Data :=
  if h : m < x.length then encode (x.get ⟨m, h⟩) else Data.ofNat 2

@[simp] theorem bitQueryAnswer_nil (m : ℕ) : bitQueryAnswer [] m = Data.ofNat 2 := by
  simp [bitQueryAnswer]

@[simp] theorem bitQueryAnswer_cons_zero (b : Bool) (x : BitStr) :
    bitQueryAnswer (b :: x) 0 = encode b := by
  simp [bitQueryAnswer]

@[simp] theorem bitQueryAnswer_cons_succ (b : Bool) (x : BitStr) (m : ℕ) :
    bitQueryAnswer (b :: x) (m + 1) = bitQueryAnswer x m := by
  unfold bitQueryAnswer
  by_cases h : m < x.length
  · have h' : m + 1 < (b :: x).length := by simp [h]
    rw [dif_pos h', dif_pos h]
    rfl
  · have h' : ¬ m + 1 < (b :: x).length := by simp [h]
    rw [dif_neg h', dif_neg h]

namespace Prog

/-- Cost of one zero test on a bit string of length `L`. -/
def zeroBound (L : ℕ) : ℕ := (L + 1) * (4 * L + 1 + 8)

/-- Cost of one decrement on a bit string of length `L`. -/
def decBound (L : ℕ) : ℕ := (L + 2) * (10 * (6 * L + 4) + 60)

/-- Cost of one iteration of `bitAtProg` with a string of size at most `sy` and an index of
`L` bits. -/
def bitAtIter (sy L : ℕ) : ℕ := sy + 8 * L + zeroBound L + decBound L + 20

/-- Body of `bitAtProg`: on state `cons y m`, stop with `ofNat 2` if `y` is exhausted; else
test `m` for zero: if zero, stop with the head bit of `y`; otherwise continue with the tail
of `y` and `m - 1`. -/
def bitAtBody : Prog :=
  .elim 0 .nil (.elim 0 (.cons .nil (.const (.ofNat 2)))
    (.let_ (callVar 3 isZeroProg)
      (.elim 0 (.cons .nil (.var 1))
        (.cons (.cons .nil .nil) (.cons (.var 4) (callVar 6 decProg))))))

/-- `bitAtProg` on `cons (encode y) (encode m)` computes `bitQueryAnswer y m`. -/
def bitAtProg : Prog := .loop bitAtBody

end Prog

end MIPRE.Cost
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/Cost/BitQuery.lean; blueprint def:succinct

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