The interpreter loop halts only along a machine run that reaches a final configuration with the same value
ProvedMIPRE.Cost.Machine.interpLoop_revLet interpBody be the body of the self-interpreter's loop: on the encoding of a configuration of the evaluation machine it stops with the returned value if is final, and otherwise continues with . The lemma is the converse of interpLoop_runs: a halting run of the loop can only come from the machine.
Let , let be a configuration, an environment and a value. If
then there are and an environment with
that is, the machine run from reaches a final configuration, and its value is the result of the loop.
This is the backward half of the efficient universal machine (blueprint lem:universal-tm): if the universal program halts on with result , then the machine run of on reaches a final configuration with value , and by the correspondence between machine runs and derivations (halts_iff) the program halts on with result . Without it, the universal program could halt with a value the simulated program never produces.
Formalization Note: The lemma is stated for an arbitrary configuration and arbitrary trailing environment , and for any cost , since it is proved by strong induction on ; no bound on or on sizes is needed. The number of machine steps is not related to in the statement.
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.interpLoop_rev : ∀ (t : ℕ) (c : Cfg) (env : Env) (r : Data),
Eval (c.toData :: env) (.loop interpBody) r t → ∃ N e, step^[N] c = ⟨.ret r, e, []⟩ := by sorry