`clockRun` returns the flagged value on a run that halts within the cost budget and the size guard
ProvedMIPRE.Cost.Machine.clockRun_of_finalLet be the specification of the clocked interpreter loop: starting from the -th configuration of the machine run of , with further iterations allowed, it is the flagged value if the current configuration is final with value ; otherwise it is if , and for it is when the cumulative cost of the first steps is at most and the encoded size of the -st configuration is at most , and otherwise.
Let be a configuration, , a value and an environment. Suppose that
- (the run reaches a final configuration with value at step ),
- (it does so within the cost budget), and
- for all (every configuration of the run is within the guard).
Then for all with ,
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 takes at most machine steps (eval_steps_count), so the step budget 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 , which is harmless since final configurations are fixed. The conclusion holds for every , not only , as required by the induction.
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
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