Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Efficient s-m-n, backward direction: a run of s(p,d)s(p,d)s(p,d) on xxx restricts to a run of ppp on (d,x)(d,x)(d,x) of no larger cost

Proved
MIPRE.Cost.hardcode_time_rev

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

computabilitycost-modelmipre-formalizationsmn-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 s(p,d)(x)⇓trs(p,d)(x) \Downarrow_t rs(p,d)(x)⇓t​r, then there is a cost t′≤tt' \le tt′≤t with

p(cons(d,x))  ⇓t′  r.p(\mathtt{cons}(d, x)) \;\Downarrow_{t'}\; r .p(cons(d,x))⇓t′​r.

This is the other 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]): hardcoding creates no halting behaviour that ppp does not have, and does not lower the cost. It is used to invert runs of hardcoded programs: in the backward direction of kleeneFix_halts_iff inside the Kleene fixed-point theorem efficient_fixed_point, in the halting equivalence of the compiler exists_compile, and to invert the runs of the search program of the compressibility criterion.

Formalization Note: By determinism of the semantics the cost is in fact t′=t−size(d)−size(x)−3t' = t - \mathrm{size}(d) - \mathrm{size}(x) - 3t′=t−size(d)−size(x)−3, but the statement records only t′≤tt' \le tt′≤t, which is what its consumers need. The closedness hypothesis is used to strip the extra environment entry xxx from the run of the body; without it the body could read the original input and the restriction would fail.

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_rev {p : Prog} (hp : p.WellScoped 1) {d x r : Data} {t : ℕ}
    (h : (hardcode p d).Runs x r t) : ∃ t' ≤ t, p.Runs (.cons d x) r t' := by sorry
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/Cost/Toolkit.lean#L78-L87; 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