Documentation

MIPRE.Foundations.Cost.FromPartrec

From Mathlib's partial recursive functions into the ambient model #

Mathlib's Turing.ToPartrec.Code is a small first-order language on lists of naturals (zero', succ, tail, cons, comp, case, fix) in which every partial recursive function is computable (Turing.ToPartrec.Code.exists_code). It translates construct by construct into the ambient language (Prog.ofCode), with lists of naturals encoded as cons-chains of unary numerals (encL) and fix as a loop; ofCode_sound and ofCode_complete are the two directions of the correctness of the translation.

exists_compile is the resulting bridge for the halting problem: a map compile from Nat.Partrec.Code to programs, computable on descriptions, such that compile pc halts on the empty input iff pc does on 0: compile pc hardcodes the code number of pc into the translation of a ToPartrec.Code for the universal partial function n ↦ (ofNat n).eval 0.

Lists of naturals as data: a cons-chain of unary numerals.

Equations
Instances For
    @[simp]
    theorem MIPRE.Cost.encL_cons (n : ) (v : List ) :
    encL (n :: v) = (Data.ofNat n).cons (encL v)

    The body of the translation of fix f: run f, then dispatch on the head of the result (stop with the tail if it is 0, continue with the tail otherwise).

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For

      The headI :: tail assembly of the translation of cons f fs, in an environment [fs v, f v, v].

      Equations
      Instances For

        Forward runs of the pieces #

        theorem MIPRE.Cost.Prog.fixBody_runs {pf : Prog} (hpf : WellScoped 1 pf) (v fv : List ) {t : } (h : pf.Runs (encL v) (encL fv) t) :
        ∃ (s : ), Eval [encL v] pf.fixBody (fixFlag fv) s
        theorem MIPRE.Cost.Prog.consTail_runs (fv fsv v : List ) :
        ∃ (s : ), Eval [encL fsv, encL fv, encL v] consTail (encL (fv.headI :: fsv)) s
        theorem MIPRE.Cost.Prog.casePair_runs (y : ) (v' : List ) :
        Eval [Data.nil, Data.ofNat y, Data.ofNat (y + 1), encL v', encL ((y + 1) :: v')] ((var 1).cons (var 3)) (encL (y :: v')) ((Data.ofNat y).size + 1 + ((encL v').size + 1) + 1)

        The pairing step of the case translation, in an environment [nil, ofNat y, ofNat (y + 1), encL v', encL (y + 1 :: v')].

        Soundness #

        theorem MIPRE.Cost.Prog.ofCode_sound (c : Turing.ToPartrec.Code) (v w : List ) :
        w c.eval v∃ (t : ), (ofCode c).Runs (encL v) (encL w) t

        Completeness #

        theorem MIPRE.Cost.Prog.ofCode_complete (c : Turing.ToPartrec.Code) (v : List ) (r : Data) (t : ) :
        (ofCode c).Runs (encL v) r t∃ (w : List ), r = encL w w c.eval v

        Halting of the translation of c on encL v is halting of c on v.

        The halting-problem bridge #

        noncomputable def MIPRE.Cost.univPart (n : ) :

        The universal partial function on code numbers: n ↦ (decode n).eval 0.

        Equations
        Instances For
          theorem MIPRE.Cost.exists_compile :
          ∃ (compile : Nat.Partrec.CodeProg), (Computable fun (pc : Nat.Partrec.Code) => encode (compile pc)) ∀ (pc : Nat.Partrec.Code), Halts (compile pc) Data.nil (pc.eval 0).Dom

          The halting problem transfers from Nat.Partrec.Code to the ambient model along a map compile, computable on descriptions (encode (compile pc) : Data).