Efficient s-m-n, forward direction: a run of on yields a run of on at additive linear overhead
ProvedMIPRE.Cost.hardcode_timePrograms of the ambient cost model (Prog) take their input as variable of a de Bruijn environment; a program is closed (p.WellScoped 1) if it reads no variable other than its input. Data are binary trees, being the number of nodes. Write (p.Runs x r t) for " run on the single input halts with result at cost " in the timed big-step semantics, in which each evaluation rule costs one unit and reading a variable or a literal costs the size of the value in addition. The s-m-n map of the model is
the program which pairs the literal with its own input and runs on the pair.
Statement. Let be a closed program, data and . If , then
This is one half of the functional equation of the efficient s-m-n theorem (blueprint lem:smn, [MNY, Lemma 2.2]), with the forward time transfer. It is used wherever a program with a hardcoded argument must be shown to run fast: the Kleene fixed point (kleeneFix_runs_of, efficient_fixed_point), succinctness of the hardcoded bit-query program (isSuccinctDesc_hardcode), the compiler from Mathlib's codes (exists_compile), and the time transfer of the self-referential decider in the recursive compression lemma.
Formalization Note: The conclusion is a run with an exact cost, not an upper bound: for building the literal, for reading the input, one unit for the pairing node and one for the let_. [MNY] only asks the runtimes of and to be polynomially related. The closedness hypothesis on is what allows the run of to be transported into the environment in which the body of the let_ executes: the original input remains visible below the pair, but a closed program never reads it.
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 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_Toolkit open MIPRE open MIPRE.Cost open Polynomial
theorem MIPRE.Cost.hardcode_time {p : Prog} (hp : p.WellScoped 1) {d x r : Data} {t : ℕ}
(h : p.Runs (.cons d x) r t) : (hardcode p d).Runs x r (t + d.size + x.size + 3) := by sorry