Efficient s-m-n, backward direction: a run of on restricts to a run of on of no larger cost
ProvedMIPRE.Cost.hardcode_time_revPrograms 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 there is a cost with
This is the other half of the functional equation of the efficient s-m-n theorem (blueprint lem:smn, [MNY, Lemma 2.2]): hardcoding creates no halting behaviour that does not have, and does not lower the cost. It is used to invert runs of hardcoded programs: in the backward direction of kleeneFix_halts_iff inside the Kleene fixed-point theorem efficient_fixed_point, in the halting equivalence of the compiler exists_compile, and to invert the runs of the search program of the compressibility criterion.
Formalization Note: By determinism of the semantics the cost is in fact , but the statement records only , which is what its consumers need. The closedness hypothesis is used to strip the extra environment entry from the run of the body; without it the body could read the original input and the restriction would fail.
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_rev {p : Prog} (hp : p.WellScoped 1) {d x r : Data} {t : ℕ}
(h : (hardcode p d).Runs x r t) : ∃ t' ≤ t, p.Runs (.cons d x) r t' := by sorry