Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

`clockRun` returns the flagged value on a run that halts within the cost budget and the size guard

Proved
MIPRE.Cost.Machine.clockRun_of_final

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

computabilitymipre-formalizationself-interpreteruniversal-machine

Let clockRun(c0,k,Θ,b,n)\mathtt{clockRun}(c_0, k, \Theta, b, n)clockRun(c0​,k,Θ,b,n) be the specification of the clocked interpreter loop: starting from the nnn-th configuration stepn(c0)\mathsf{step}^{n}(c_0)stepn(c0​) of the machine run of c0c_0c0​, with bbb further iterations allowed, it is the flagged value cons (cons nil nil) r\mathsf{cons}\,(\mathsf{cons}\,\mathsf{nil}\,\mathsf{nil})\,rcons(consnilnil)r if the current configuration is final with value rrr; otherwise it is nil\mathsf{nil}nil if b=0b = 0b=0, and for b=b′+1b = b'+1b=b′+1 it is clockRun(c0,k,Θ,b′,n+1)\mathtt{clockRun}(c_0, k, \Theta, b', n+1)clockRun(c0​,k,Θ,b′,n+1) when the cumulative cost costSum(c0,n+1)\mathsf{costSum}(c_0, n+1)costSum(c0​,n+1) of the first n+1n+1n+1 steps is at most kkk and the encoded size of the (n+1)(n+1)(n+1)-st configuration is at most Θ\ThetaΘ, and nil\mathsf{nil}nil otherwise.

Let c0c_0c0​ be a configuration, k,Θ,N∈Nk, \Theta, N \in \mathbb{N}k,Θ,N∈N, rrr a value and eee an environment. Suppose that

  1. stepN(c0)=⟨ret r,e,[ ]⟩\mathsf{step}^{N}(c_0) = \langle\mathsf{ret}\,r, e, [\,]\ranglestepN(c0​)=⟨retr,e,[]⟩ (the run reaches a final configuration with value rrr at step NNN),
  2. costSum(c0,N)≤k\mathsf{costSum}(c_0, N) \le kcostSum(c0​,N)≤k (it does so within the cost budget), and
  3. size⌈stepn(c0)⌉≤Θ\mathrm{size}\lceil\mathsf{step}^{n}(c_0)\rceil \le \Thetasize⌈stepn(c0​)⌉≤Θ for all nnn (every configuration of the run is within the guard).

Then for all b,nb, nb,n with n≤N≤n+bn \le N \le n + bn≤N≤n+b,

clockRun(c0,k,Θ,b,n)=cons (cons nil nil) r.\mathtt{clockRun}(c_0, k, \Theta, b, n) = \mathsf{cons}\,(\mathsf{cons}\,\mathsf{nil}\,\mathsf{nil})\,r .clockRun(c0​,k,Θ,b,n)=cons(consnilnil)r.

Together with clockRun_of_not (the timeout case) this identifies the value of the clocked loop with the budgeted result clockedResult (clockRun_eq): a run of cost t≤kt \le kt≤k takes at most 3t≤3k3t \le 3k3t≤3k machine steps (eval_steps_count), so the step budget 3k+13k+13k+1 suffices. It serves the clocked universal machine of blueprint lem:universal-tm.

Formalization Note: clockRun is the noncomputable specification function of Cost/Universal.lean (finality is decided classically); the statement is purely about it and the machine, not about any program. Hypothesis 3 is demanded for all nnn, which is harmless since final configurations are fixed. The conclusion holds for every n≤Nn \le Nn≤N, not only n=0n = 0n=0, as required by the induction.

Preamble
import Mathlib.Algebra.Polynomial.Eval.Defs
import Mathlib.Computability.Primrec.List
import Mathlib.Data.List.Basic
import Mathlib.Data.Nat.Bits
import Mathlib.Data.Nat.Notation
import Mathlib.Data.Nat.Size
import Mathlib.Logic.Denumerable
import Mathlib.Logic.Function.Iterate
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_Toolkit
import Definitions.Def_MIPRE_Foundations_Cost_Machine
import Definitions.Def_MIPRE_Foundations_Cost_Codable
import Definitions.Def_MIPRE_Foundations_Cost_MachineData
import Definitions.Def_MIPRE_Foundations_Cost_Interpreter
import Definitions.Def_MIPRE_Foundations_Cost_MachineBound
import Definitions.Def_MIPRE_Foundations_Cost_Universal

open MIPRE
open MIPRE.Cost
open MIPRE.Cost.Machine
open Polynomial
open MIPRE.Cost.Prog
Formal statement
theorem MIPRE.Cost.Machine.clockRun_of_final (c₀ : Cfg) (k Θ : ℕ) (N : ℕ) (r : Data) (e : Env)
    (hN : step^[N] c₀ = ⟨.ret r, e, []⟩) (hcost : costSum c₀ N ≤ k)
    (hΘ : ∀ n, (step^[n] c₀).toData.size ≤ Θ) :
    ∀ b n, n ≤ N → N ≤ n + b → clockRun c₀ k Θ b n = .cons (.cons .nil .nil) r := by sorry
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/Cost/Universal.lean#L1107-L1136; internal lemma of the formalization of blueprint lem:universal-tm, 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