Langlib

Langlib.Classes.Recursive.Inclusion.ByTapeFromComputable

is_Recursive_byTape from a computable decider #

This file builds, from a total computable decider f : List T → Bool for a language L, an always-halting TM0 over Option (T ⊕ Γ) that leaves a designated acceptSym under the head exactly on the words of L, i.e. is_Recursive_byTape L.

The construction threads the Mathlib Code → TM2 → TM1 → TM0 translation chain, but unlike the .Dom-only bridge code_implies_isTM_direct, it tracks the final tape (not just halting), because acceptance is read off the head symbol.

SPIKE: Computable f → ToPartrec.Code with characterized output #

Given f : List T → Bool computable, we produce a ToPartrec.Code bitCode with bitCode.eval [Encodable.encode w] = some [if f w then 1 else 0].

noncomputable def ByTapeFromComputable.bitFn {T : Type} [Primcodable T] (f : List TBool) :

The unary ℕ → ℕ function: decode the input as a word and return the bit.

Equations
Instances For
    theorem ByTapeFromComputable.partrec_bitFn {T : Type} [Primcodable T] (f : List TBool) (hf : Computable f) :
    Nat.Partrec' fun (v : List.Vector 1) => (bitFn f) v.head

    A ToPartrec.Code computing bitFn f (as a singleton output).

    Equations
    Instances For

      Output shaping: bit → [] / [0] #

      Code.case Code.zero Code.nil maps [0] ↦ [0] (reject) and [1] ↦ [] (accept). Composed with bitCode₀, the full code outputs [] exactly when f w = true.

      The full decider code on the encoded input. Outputs [] iff f w = true.

      Equations
      Instances For

        TM2 final configuration #

        By PartrecToTM2.tr_eval, the TM2 machine reaches halt v where v is the output of the code.

        noncomputable def ByTapeFromComputable.outWord {T : Type} (f : List TBool) (w : List T) :

        The output word of the decider code on w.

        Equations
        Instances For

          The composed code (with list-encoding prefix) on shiftedEncoding w evaluates to outWord f w.

          Generic chain tape descent (TM2 halt v → TM0 tape) #

          For any code c and input v such that the TM2 reaches halt v, the chain TM0 ChainTM0 reaches a configuration whose tape head is the embedded final-tape head. We track the full configuration via the Mathlib Respects relations.

          @[reducible, inline]

          The chain TM1 initial config (matches partrec_init_trCfg).

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

            TM1 descent: the chain TM1 reaches some config with TrCfg (halt vOut) cfg₁, where vIn is the input and vOut the reached output.

            TM0 descent: the chain TM0 reaches a config whose tape is the TM1 final tape, starting from TM1to0.trCfg ChainTM1 (chainTM1Init c v).

            Tape-tracking eval lemmas for reroot / restrict / alphabet-lift #

            Each underlying Respects relation preserves the tape, so Turing.tr_eval transports a final config of known tape.

            theorem ByTapeFromComputable.reroot_eval_tape {Γ : Type} [Inhabited Γ] {Λ : Type} [Inhabited Λ] (M : Turing.TM0.Machine Γ Λ) (q₀ : Λ) (l : List Γ) (cf : Turing.TM0.Cfg Γ Λ) (hmem : cf Turing.eval (Turing.TM0.step M) { q := q₀, Tape := Turing.Tape.mk₁ l }) :

            Re-rooted TM0: a final config with tape T is reached, given the original reaches a final config with tape T from ⟨q₀, Tape.mk₁ l⟩.

            theorem ByTapeFromComputable.restrict_eval_tape {Γ : Type} [Inhabited Γ] {Λ : Type} [Inhabited Λ] (M : Turing.TM0.Machine Γ Λ) (S : Finset Λ) (hS : Turing.TM0.Supports M S) (l : List Γ) (cf : Turing.TM0.Cfg Γ Λ) (hmem : cf Turing.eval (Turing.TM0.step M) (Turing.TM0.init l)) :
            ∃ (cf' : Turing.TM0.Cfg Γ { q : Λ // q S }), cf'.Tape = cf.Tape cf' Turing.eval (Turing.TM0.step (Turing.TM0.restrict M S hS)) (Turing.TM0.init l)

            Restricted TM0: tape-tracking version of restrict_eval_dom_iff.

            theorem ByTapeFromComputable.restrictReroot_eval_tape {Γ : Type} [Inhabited Γ] {Λ : Type} [Inhabited Λ] (M : Turing.TM0.Machine Γ Λ) (S : Finset Λ) (hS : Turing.TM0.Supports M S) (q₀ : Λ) (hq₀ : q₀ S) (l : List Γ) (cf : Turing.TM0.Cfg Γ Λ) (hmem : cf Turing.eval (Turing.TM0.step M) { q := q₀, Tape := Turing.Tape.mk₁ l }) :

            Restrict+reroot TM0: tape-tracking version of tm0RestrictReroot_eval_dom.

            theorem ByTapeFromComputable.lift_eval_tape {Γ Γ₂ : Type} [Inhabited Γ] [Inhabited Γ₂] {Λ : Type} [Inhabited Λ] (M : Turing.TM0.Machine Γ Λ) (emb : ΓΓ₂) (inv : Γ₂Γ) (hemb : ∀ (a : Γ), inv (emb a) = a) (hemb_default : emb default = default) (l : List Γ) (cf : Turing.TM0.Cfg Γ Λ) (hmem : cf Turing.eval (Turing.TM0.step M) (Turing.TM0.init l)) :

            Alphabet-lifted TM0: tape-tracking version of lift_eval_dom.

            The final TM1 tape head for a halt v config #

            From TrCfg (halt v) cfg₁, the TM1 tape head is (true, L.head) where each stack component is the head of the reversed encoded stack.

            The accepting symbol: the embedding of the accept TM1 head.

            Equations
            Instances For

              A reject head (whose main component is some cons) embeds to something different from acceptSym.

              Chain TM0 with Fintype states and final tape #

              The analogue of code_to_tm0_fintype_general, but additionally producing the final tape (the embedded addBottom L head).

              Final assembly #

              is_Recursive_byTape from a computable decider.

              The assembled TM0 over Option (T ⊕ ChainΓ) is compose M_conv (directEmbedTM0 M), where M_conv writes the chain input from w, M is the chain decider, and the alphabet is lifted via directBlankEmb. It always halts and its final head is acceptSym exactly on words of L.

              theorem is_Recursive_byTape_of_computable_decide {T : Type} [DecidableEq T] [Fintype T] [Primcodable T] (L : Language T) (f : List TBool) (hf : Computable f) (hL : ∀ (w : List T), w L f w = true) :

              is_Recursive_byTape from a computable decider (top-level form).

              theorem is_Recursive_of_computable_decide {T : Type} [DecidableEq T] [Fintype T] [Primcodable T] (L : Language T) (f : List TBool) (hf : Computable f) (hL : ∀ (w : List T), w L f w = true) :

              A total computable Boolean decision procedure yields a recursive language. Combining the tape-output decider construction with the tape-vs-state acceptance equivalence is_Recursive_of_byTape.