Strengthening: a well-scoped program ignores extra environment entries
ProvedMIPRE.Cost.Eval.of_append_of_wellScopedPrograms of the ambient model use de Bruijn variables: reads the -th entry of the environment (a list of values), inspects the -th entry and binds its two components as variables and in , binds one variable in , and iterates on the state held in variable . A program is well-scoped in variables, written , when every and it contains has below the number of variables in scope ( at the top level, under an , under a ), and every occurs with at least one variable in scope.
Let and be environments, a program, a value and . Suppose that is well-scoped in variables, where is the length of , and that halts in the concatenated environment with result at cost . Then
that is, halts in alone with the same result and the same cost.
This is the strengthening direction of the inertness of extra environment entries; the companion weakening lemma Eval.append_of_wellScoped goes the other way. It is used whenever a run of a composite program is taken apart: the backward time transfer of the efficient s-m-n map (hardcode_time_rev, which restricts a run of on to a run of on ), the Kleene fixed point and the compilation of the model to Mathlib's partial recursive functions.
Formalization Note: Prog.WellScoped n p is the recursive predicate of Cost/Basic.lean; the clause requires because the loop rule replaces the head of the environment. Lookup beyond the end of an environment returns rather than failing, so the hypothesis of well-scopedness is what guarantees that no read reaches into . The cost is preserved exactly, not merely bounded.
import Mathlib.Data.List.Basic import Mathlib.Data.Nat.Notation import Definitions.Def_MIPRE_Foundations_Cost_Basic open MIPRE open MIPRE.Cost open MIPRE.Cost.Eval
theorem MIPRE.Cost.Eval.of_append_of_wellScoped {env extra : Env} {p : Prog} {r : Data} {t : ℕ}
(h : Eval (env ++ extra) p r t) (hp : p.WellScoped env.length) : Eval env p r t := by sorry