A program halts with a value if and only if the evaluation machine reaches a final configuration with that value
ProvedMIPRE.Cost.Machine.halts_iffThe evaluation machine (Machine) is a small-step, CEK-style machine for the ambient language of the cost model. A configuration (Cfg) consists of a control , which is either ("evaluate the program ") or ("return the value "), an environment (a list of data, variable first) and a stack of continuation frames: (the head of a is being evaluated; evaluate in next), (the head value is ; return next), and . The step function (step) is total and deterministic, and it leaves final configurations unchanged. Each configuration is charged a cost : a configuration is charged the unit of the evaluation rule for the head constructor of — for , for , for , for , and , and for , whose unit is charged instead when the value of the body is dispatched at a frame; all other returns cost . Write (costSum) for the cost accumulated over steps, and (Steps) for " and ". The big-step semantics (Eval) is the timed evaluation relation that the machine implements: in the environment halts with result at cost . For a program and an input , write (p.Runs x r t) for .
Statement. For every program and data :
This combines the two directions of the derivation–machine correspondence at the initial configuration of a program on its input. It is the form consumed by the soundness of the self-interpreter (univProg_halts_of, blueprint lem:universal-tm) and by the proof that evaluation is partial recursive (mem_evalData_iff), which transports it along the encoding of configurations as data.
Formalization Note: The left side is the halting predicate of the big-step semantics with an unspecified cost, and the right side mentions only the step function iterated on Cfg, with the environment of the final configuration existential; costs play no role in this statement.
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 Mathlib.Logic.Function.Iterate 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_Machine open MIPRE open MIPRE.Cost open MIPRE.Cost.Machine
theorem MIPRE.Cost.Machine.halts_iff (p : Prog) (x r : Data) :
(∃ t, p.Runs x r t) ↔ ∃ N e, step^[N] ⟨.ev p, [x], []⟩ = ⟨.ret r, e, []⟩ := by sorry