Soundness of the `ToPartrec` translation: computes every value of on
ProvedMIPRE.Cost.Prog.ofCode_soundMathlib's Turing.ToPartrec.Code is a small first-order language on lists of natural numbers, with the partial semantics : ; , the head of the empty list being ; ; ; ; , , ; and is the least fixed point (PFun.fix) that returns if and recurses on otherwise. Write for " on is defined, with value ". In the ambient cost model, lists of naturals are encoded as -chains of unary numerals, (encL; the numeral is the list of copies of ), and (p.Runs x r t) denotes a run of the program on the input with result at cost . The translation (Prog.ofCode) maps each construct to a program of the model — elims on the input for the primitives and for , let_ binders with calls of the translated subprograms for and , and a loop for .
Statement. For every code and lists of naturals ,
This is one direction of the correctness of the translation; with ofCode_complete it gives that halts on exactly when is defined (ofCode_halts_iff), which the compiler exists_compile uses to transport the halting problem of Mathlib's Nat.Partrec.Code into the model, for the halting form of the compression lemmas (blueprint lem:halting-form).
Formalization Note: The statement is computability-only: the cost is existential and no bound is claimed — the module docstring of the cost model explains why Mathlib's ToPartrec.Code cannot serve as a polynomial-time model. Lists of naturals are encoded with unary numerals, unlike the binary encoding of used elsewhere in the development, because the translation mirrors and the head tests of and by single elims.
import Mathlib.Algebra.Polynomial.Eval.Defs import Mathlib.Computability.PartrecCode import Mathlib.Computability.Primrec.List import Mathlib.Computability.TuringMachine.Config 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 import Definitions.Def_MIPRE_Foundations_Cost_FromPartrec open MIPRE open MIPRE.Cost open MIPRE.Cost.Prog open Turing.ToPartrec (Code)
theorem MIPRE.Cost.Prog.ofCode_sound : ∀ (c : Code) (v w : List ℕ), w ∈ c.eval v →
∃ t, (ofCode c).Runs (encL v) (encL w) t := by sorry