Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Strengthening: a well-scoped program ignores extra environment entries

Proved
MIPRE.Cost.Eval.of_append_of_wellScoped

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

computabilitycost-modelmipre-formalizationsmn-theorem

Programs of the ambient model use de Bruijn variables: var i\mathsf{var}\,ivari reads the iii-th entry of the environment (a list of values), elim i n c\mathsf{elim}\,i\,n\,celiminc inspects the iii-th entry and binds its two components as variables 000 and 111 in ccc, let e b\mathsf{let}\,e\,bleteb binds one variable in bbb, and loop b\mathsf{loop}\,bloopb iterates bbb on the state held in variable 000. A program ppp is well-scoped in nnn variables, written WellScoped  n  p\mathsf{WellScoped}\;n\;pWellScopednp, when every var i\mathsf{var}\,ivari and elim i\mathsf{elim}\,ielimi it contains has iii below the number of variables in scope (nnn at the top level, n+2n+2n+2 under an elim\mathsf{elim}elim, n+1n+1n+1 under a let\mathsf{let}let), and every loop\mathsf{loop}loop occurs with at least one variable in scope.

Let ρ\rhoρ and ρ′\rho'ρ′ be environments, ppp a program, rrr a value and t∈Nt \in \mathbb{N}t∈N. Suppose that ppp is well-scoped in ∣ρ∣|\rho|∣ρ∣ variables, where ∣ρ∣|\rho|∣ρ∣ is the length of ρ\rhoρ, and that ppp halts in the concatenated environment ρ+ ⁣ ⁣+ρ′\rho \mathbin{+\!\!+} \rho'ρ++ρ′ with result rrr at cost ttt. Then

Eval  ρ  p  r  t,\mathsf{Eval}\;\rho\;p\;r\;t ,Evalρprt,

that is, ppp halts in ρ\rhoρ alone with the same result and the same cost.

This is the strengthening direction of the inertness of extra environment entries; the companion weakening lemma Eval.append_of_wellScoped goes the other way. It is used whenever a run of a composite program is taken apart: the backward time transfer of the efficient s-m-n map (hardcode_time_rev, which restricts a run of let (cons (const d) (var 0)) p\mathsf{let}\,(\mathsf{cons}\,(\mathsf{const}\,d)\,(\mathsf{var}\,0))\,plet(cons(constd)(var0))p on xxx to a run of ppp on (d,x)(d, x)(d,x)), the Kleene fixed point and the compilation of the model to Mathlib's partial recursive functions.

Formalization Note: Prog.WellScoped n p is the recursive predicate of Cost/Basic.lean; the loop\mathsf{loop}loop clause requires 0<n0 < n0<n because the loop rule replaces the head of the environment. Lookup beyond the end of an environment returns nil\mathsf{nil}nil rather than failing, so the hypothesis of well-scopedness is what guarantees that no read reaches into ρ′\rho'ρ′. The cost ttt is preserved exactly, not merely bounded.

Preamble
import Mathlib.Data.List.Basic
import Mathlib.Data.Nat.Notation
import Definitions.Def_MIPRE_Foundations_Cost_Basic

open MIPRE
open MIPRE.Cost
open MIPRE.Cost.Eval
Formal statement
theorem MIPRE.Cost.Eval.of_append_of_wellScoped {env extra : Env} {p : Prog} {r : Data} {t : ℕ}
    (h : Eval (env ++ extra) p r t) (hp : p.WellScoped env.length) : Eval env p r t := by sorry
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/Cost/Basic.lean#L378-L419; internal lemma of the formalization of blueprint lem:smn, https://vidick.github.io/MIPRE-formalization/blueprint/

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