Forward run of the Kleene two-argument program : from a run of on , at explicit overhead
ProvedMIPRE.Cost.Prog.kleeneProg_runsPrograms of the ambient cost model (Prog) read their input as variable and are closed (WellScoped 1) when they read no other variable; (p.Runs x r t) says that run on the input halts with result at cost in the timed big-step semantics, and is the number of nodes of a datum . Programs are encoded as data by their tree serialization , with (esize), and (hardcode p d) is the s-m-n map, running on the pair of the literal and its input. A universal machine (UniversalMachine) is a closed program with a polynomial such that (i) whenever there is with (time_le), and (ii) whenever there is with (halts_of). A polynomial-time map on programs (PolyTimeFun Prog Prog) is a function with a closed program and an explicit polynomial such that for some , for every .
The two-argument program of the fixed-point construction is (kleeneProg): on an input it forms the pair , applies the s-m-n program smnProg to obtain , applies to obtain , pairs the result with and runs on that pair.
Statement. Let be a universal machine, a polynomial-time map on programs and a program, and write . If , then there is a cost with and
This is the forward half of the fixed-point construction for the efficient Kleene recursion theorem (blueprint lem:kleene, [MNY, Lemma 2.3]): kleeneFix_runs_of instantiates it with , for which is the fixed point, and efficient_fixed_point uses it for the transfer of halting from to .
Formalization Note: The bound is the exact cost of the straight-line program up to the two bounded sub-runs: for the copies of read in the pairing, in passing the pair to the s-m-n program and inside it; for passing to ; bounding that run; for the final pairing and for passing the pair to ; bounding the universal run; and units of rule costs and literals. No hypothesis is placed on : the program whose description is hardcoded need not be closed.
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 import Definitions.Def_MIPRE_Foundations_Cost_Kleene open MIPRE open MIPRE.Cost open MIPRE.Cost.Prog open Polynomial
theorem MIPRE.Cost.Prog.kleeneProg_runs (U : UniversalMachine) (F : PolyTimeFun Prog Prog) (x : Prog)
{v r : Data} {t : ℕ} (h : (F (hardcode x (encode x))).Runs v r t) :
∃ T ≤ 6 * esize x + esize (hardcode x (encode x)) +
F.timeBound.eval (esize (hardcode x (encode x))) +
2 * esize (F (hardcode x (encode x))) + 2 * v.size +
U.bound.eval (esize (F (hardcode x (encode x))) + v.size + t) + 57,
(kleeneProg U.univ F).Runs (.cons (encode x) v) r T := by sorry