Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Efficient s-m-n, forward direction: a run of ppp on (d,x)(d,x)(d,x) yields a run of s(p,d)s(p,d)s(p,d) on xxx at additive linear overhead

Proved
MIPRE.Cost.hardcode_time

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

computabilitycost-modelmipre-formalizationpolynomial-timesmn-theorem

Programs of the ambient cost model (Prog) take their input as variable 000 of a de Bruijn environment; a program ppp is closed (p.WellScoped 1) if it reads no variable other than its input. Data are binary trees, size\mathrm{size}size being the number of nodes. Write p(x)⇓trp(x) \Downarrow_t rp(x)⇓t​r (p.Runs x r t) for "ppp run on the single input xxx halts with result rrr at cost ttt" in the timed big-step semantics, in which each evaluation rule costs one unit and reading a variable or a literal costs the size of the value in addition. The s-m-n map of the model is

s(p,d)  :=  let cons(const d, var 0) in p(‘hardcode p d‘),s(p, d) \;:=\; \mathtt{let}\ \mathtt{cons}(\mathtt{const}\ d,\ \mathtt{var}\ 0)\ \mathtt{in}\ p \qquad\text{(`hardcode p d`)},s(p,d):=let cons(const d, var 0) in p(‘hardcode p d‘),

the program which pairs the literal ddd with its own input and runs ppp on the pair.

Statement. Let ppp be a closed program, d,x,rd, x, rd,x,r data and t∈Nt \in \mathbb{N}t∈N. If p(cons(d,x))⇓trp(\mathtt{cons}(d, x)) \Downarrow_t rp(cons(d,x))⇓t​r, then

s(p,d)(x)  ⇓ t+size(d)+size(x)+3  r.s(p,d)(x) \;\Downarrow_{\,t + \mathrm{size}(d) + \mathrm{size}(x) + 3}\; r .s(p,d)(x)⇓t+size(d)+size(x)+3​r.

This is one half of the functional equation φs(p,d)(x)=φp(d,x)\varphi_{s(p,d)}(x) = \varphi_p(d, x)φs(p,d)​(x)=φp​(d,x) of the efficient s-m-n theorem (blueprint lem:smn, [MNY, Lemma 2.2]), with the forward time transfer. It is used wherever a program with a hardcoded argument must be shown to run fast: the Kleene fixed point (kleeneFix_runs_of, efficient_fixed_point), succinctness of the hardcoded bit-query program (isSuccinctDesc_hardcode), the compiler from Mathlib's codes (exists_compile), and the time transfer of the self-referential decider in the recursive compression lemma.

Formalization Note: The conclusion is a run with an exact cost, not an upper bound: size(d)\mathrm{size}(d)size(d) for building the literal, size(x)+1\mathrm{size}(x) + 1size(x)+1 for reading the input, one unit for the pairing node and one for the let_. [MNY] only asks the runtimes of eee and s(e,x)s(e,x)s(e,x) to be polynomially related. The closedness hypothesis on ppp is what allows the run of ppp to be transported into the environment [cons(d,x),x][\mathtt{cons}(d,x), x][cons(d,x),x] in which the body of the let_ executes: the original input remains visible below the pair, but a closed program never reads it.

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 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_Toolkit

open MIPRE
open MIPRE.Cost
open Polynomial
Formal statement
theorem MIPRE.Cost.hardcode_time {p : Prog} (hp : p.WellScoped 1) {d x r : Data} {t : ℕ}
    (h : p.Runs (.cons d x) r t) : (hardcode p d).Runs x r (t + d.size + x.size + 3) := by sorry
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/Cost/Toolkit.lean#L71-L76; blueprint lem:smn, https://vidick.github.io/MIPRE-formalization/blueprint/; [MNY] A. Marks, S. S. Nezhadi, H. Yuen, The recursive compression method for proving undecidability results, manuscript, Lemma 2.2

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