The step-cost program on an evaluate-configuration reduces to the case program selected by the constructor tag
ProvedMIPRE.Cost.Machine.stepCostProg_evThe clocked self-interpreter needs, at each simulated step, the exact cost that the evaluation machine charges for the step from the configuration ; the program stepCostProg computes it, in unary, from the encoding . On a configuration in evaluation mode, "evaluate ", the cost depends only on the constructor of and on its arguments: it is of the variable's value for , for , for , , and , and for . Accordingly stepCostProg takes the configuration apart and dispatches on the unary constructor tag of the program to one of seven fixed case programs (tags to standing for , , , , , , ), each of which receives the pair (payload of , encoded environment) as its input.
Let , let (the payload of a program with tag ), (an encoded environment), (an encoded stack) and be values, and let . Suppose that the -th case program, run on the single input , halts with result at cost . Then there is a cost
such that stepCostProg, run on the encoded evaluate-configuration
(control "evaluate the program with tag and payload ", environment , stack ) halts with the same result at cost .
This is the common prefix of all seven evaluate-cases of the correctness theorem stepCostProg_runs, which then only has to run each case program on its pair. It serves the clocked universal machine of blueprint lem:universal-tm.
Formalization Note: The case programs are the list costCases of Cost/Universal.lean, indexed with List.getD (default , never reached since ); the overhead in the bound is the cost of walking the dispatch chain, one per tag. The hypothesis is a run in the one-element environment (the case programs are closed), and the conclusion is a run in the one-element environment holding the encoded configuration, that is, a Prog.Runs statement spelled out.
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.stepCostProg_ev (k : ℕ) (body env kont r : Data) {t : ℕ}
(hk : k < costCases.length)
(h : Eval [Data.cons body env] (costCases.getD k .nil) r t) :
∃ s ≤ t + 2 * body.size + 2 * env.size + kont.size + k + 14,
Eval [Data.cons (.cons .nil (.cons (.ofNat k) body)) (.cons env kont)] stepCostProg r s := by sorry