Langlib

Langlib.Automata.LinearBounded.Inclusion.TuringMachine

NLBA Languages ⊆ Turing Machine Languages #

We show that every language recognized by a nondeterministic linearly bounded automaton (NLBA) is also recognized by a Turing machine, adapting the LBA ⊆ TM proof for the nondeterministic case.

Strategy #

The key challenge is that NLBAs are nondeterministic: there may be multiple possible successor configurations at each step. We handle this by BFS determinization: the simulating Turing machine tracks the entire set of currently reachable NLBA configurations, expanding it by one nondeterministic step at a time.

Part 1: BFS Determinization #

We define stepFinset M S, which expands a Finset of configurations by one NLBA step, and iterStepFinset M S k, which applies k expansion steps. We prove:

Part 2: Concrete TM0 Simulation #

We construct a Turing.TM0.Machine that simulates a given NLBA via BFS:

  1. Reading phase: Same as the LBA simulation — read input symbols into the state.
  2. Simulation phase: Track a Finset (DLBA.Cfg Γ Λ n) of reachable configurations. At each step, expand the set via stepFinset. If any configuration is accepting, halt. If the set reaches a fixpoint (no new configurations), loop forever.

The TM0 halts if and only if the NLBA accepts the input.

Main Results #

Initialization #

def LBA.initCfg {Γ : Type u_1} {Λ : Type u_2} {n : } (M : Machine Γ Λ) (w : Fin (n + 1)Γ) :
DLBA.Cfg Γ Λ n

Initial configuration for a Fin-indexed input word.

Equations
Instances For
    def LBA.LanguageN {Γ : Type u_1} {Λ : Type u_2} (M : Machine Γ Λ) (n : ) :
    Set (Fin (n + 1)Γ)

    The language recognized by an NLBA at a fixed input length.

    Equations
    Instances For

      Part 1: BFS Determinization #

      def LBA.hasAccepting {Γ : Type u_1} {Λ : Type u_2} {n : } (M : Machine Γ Λ) (S : Finset (DLBA.Cfg Γ Λ n)) :

      Whether a Finset of configurations contains an accepting one.

      Equations
      Instances For
        noncomputable instance LBA.hasAcceptingDec {Γ : Type u_1} {Λ : Type u_2} {n : } (M : Machine Γ Λ) (S : Finset (DLBA.Cfg Γ Λ n)) :
        Equations
        noncomputable def LBA.stepFinset {Γ : Type u_1} {Λ : Type u_2} {n : } [Fintype Γ] [Fintype Λ] [DecidableEq Γ] [DecidableEq Λ] (M : Machine Γ Λ) (S : Finset (DLBA.Cfg Γ Λ n)) :
        Finset (DLBA.Cfg Γ Λ n)

        One-step BFS expansion: union of S with all configurations reachable in one NLBA step from any configuration in S.

        Equations
        Instances For
          noncomputable def LBA.iterStepFinset {Γ : Type u_1} {Λ : Type u_2} {n : } [Fintype Γ] [Fintype Λ] [DecidableEq Γ] [DecidableEq Λ] (M : Machine Γ Λ) (S : Finset (DLBA.Cfg Γ Λ n)) :
          Finset (DLBA.Cfg Γ Λ n)

          Iterated BFS expansion.

          Equations
          Instances For
            theorem LBA.subset_stepFinset {Γ : Type u_1} {Λ : Type u_2} {n : } [Fintype Γ] [Fintype Λ] [DecidableEq Γ] [DecidableEq Λ] (M : Machine Γ Λ) (S : Finset (DLBA.Cfg Γ Λ n)) :
            theorem LBA.step_mem_stepFinset {Γ : Type u_1} {Λ : Type u_2} {n : } [Fintype Γ] [Fintype Λ] [DecidableEq Γ] [DecidableEq Λ] (M : Machine Γ Λ) (S : Finset (DLBA.Cfg Γ Λ n)) {cfg cfg' : DLBA.Cfg Γ Λ n} (hcfg : cfg S) (hstep : Step M cfg cfg') :
            cfg' stepFinset M S
            theorem LBA.iterStepFinset_subset_succ {Γ : Type u_1} {Λ : Type u_2} {n : } [Fintype Γ] [Fintype Λ] [DecidableEq Γ] [DecidableEq Λ] (M : Machine Γ Λ) (S : Finset (DLBA.Cfg Γ Λ n)) (k : ) :
            theorem LBA.iterStepFinset_mono {Γ : Type u_1} {Λ : Type u_2} {n : } [Fintype Γ] [Fintype Λ] [DecidableEq Γ] [DecidableEq Λ] (M : Machine Γ Λ) (S : Finset (DLBA.Cfg Γ Λ n)) {i j : } (hij : i j) :
            theorem LBA.reaches_mem_iterStepFinset {Γ : Type u_1} {Λ : Type u_2} {n : } [Fintype Γ] [Fintype Λ] [DecidableEq Γ] [DecidableEq Λ] (M : Machine Γ Λ) (S : Finset (DLBA.Cfg Γ Λ n)) {cfg cfg' : DLBA.Cfg Γ Λ n} (hcfg : cfg S) (hreach : Reaches M cfg cfg') :
            ∃ (k : ), cfg' iterStepFinset M S k

            Part 2: Concrete TM0 Simulation #

            inductive LBA.NSimState (Γ : Type u_1) (Λ : Type u_2) (n : ) :
            Type (max u_1 u_2)

            States of the TM0 machine simulating an NLBA via BFS.

            Instances For
              instance LBA.NSimState.instInhabited {Γ : Type u_1} {Λ : Type u_2} {n : } :
              Equations
              noncomputable def LBA.nToTM0 {Γ : Type u_1} {Λ : Type u_2} [Fintype Γ] [Fintype Λ] [DecidableEq Γ] [DecidableEq Λ] (M : Machine Γ Λ) (n : ) :

              The TM0 machine that simulates a given NLBA via breadth-first search.

              Equations
              Instances For
                def LBA.encodeInput {Γ : Type u_1} {n : } (w : Fin (n + 1)Γ) :

                Encode an NLBA input as a TM0 input (list over Option Γ).

                Equations
                Instances For
                  @[reducible, inline]
                  noncomputable abbrev LBA.ntm0Step {Γ : Type u_1} {Λ : Type u_2} [Fintype Γ] [Fintype Λ] [DecidableEq Γ] [DecidableEq Λ] (M : Machine Γ Λ) (n : ) :

                  The TM0 step function for the NLBA simulation machine.

                  Equations
                  Instances For
                    @[reducible, inline]
                    abbrev LBA.NSimCfg (Γ : Type u_1) (Λ : Type u_2) (n : ) :
                    Type (max u_1 u_2 u_1)

                    Abbreviation for TM0 configurations in the NLBA simulation.

                    Equations
                    Instances For
                      noncomputable def LBA.ntm0Init {Γ : Type u_1} {Λ : Type u_2} {n : } [Fintype Γ] [Fintype Λ] [DecidableEq Γ] [DecidableEq Λ] (_M : Machine Γ Λ) (w : Fin (n + 1)Γ) :
                      NSimCfg Γ Λ n

                      The initial TM0 configuration for a given encoded input.

                      Equations
                      Instances For

                        Tape Helper Lemmas #

                        theorem LBA.tape_iter_move_right_nth {α : Type u_1} [Inhabited α] (T : Turing.Tape α) (k : ) (i : ) :
                        theorem LBA.encodeInput_length {Γ : Type u_1} {n : } (w : Fin (n + 1)Γ) :
                        theorem LBA.encodeInput_getI {Γ : Type u_1} {n : } (w : Fin (n + 1)Γ) (k : ) (hk : k < n + 1) :
                        (encodeInput w).getI k = some (w k, hk)
                        theorem LBA.encodeInput_getI_end {Γ : Type u_1} {n : } (w : Fin (n + 1)Γ) :
                        (encodeInput w).getI (n + 1) = none

                        Reading Phase #

                        theorem LBA.reading_single_step {Γ : Type u_1} {Λ : Type u_2} {n : } [Fintype Γ] [Fintype Λ] [DecidableEq Γ] [DecidableEq Λ] (M : Machine Γ Λ) (acc : List Γ) (a : Γ) (T : Turing.Tape (Option Γ)) (hhead : T.head = some a) :
                        ntm0Step M n { q := NSimState.reading acc, Tape := T } = some { q := NSimState.reading (acc ++ [a]), Tape := Turing.Tape.move Turing.Dir.right T }
                        theorem LBA.reading_to_simulating {Γ : Type u_1} {Λ : Type u_2} {n : } [Fintype Γ] [Fintype Λ] [DecidableEq Γ] [DecidableEq Λ] (M : Machine Γ Λ) (acc : List Γ) (hacc : acc.length = n + 1) (T : Turing.Tape (Option Γ)) (hhead : T.head = none) :
                        ∃ (T' : Turing.Tape (Option Γ)), ntm0Step M n { q := NSimState.reading acc, Tape := T } = some { q := NSimState.simulating {initCfg M fun (i : Fin (n + 1)) => acc.get (Fin.cast i)}, Tape := T' }
                        theorem LBA.reading_phase_k_steps {Γ : Type u_1} {Λ : Type u_2} {n : } [Fintype Γ] [Fintype Λ] [DecidableEq Γ] [DecidableEq Λ] (M : Machine Γ Λ) (w : Fin (n + 1)Γ) (k : ) (hk : k n + 1) :
                        theorem LBA.reading_phase_complete {Γ : Type u_1} {Λ : Type u_2} {n : } [Fintype Γ] [Fintype Λ] [DecidableEq Γ] [DecidableEq Λ] (M : Machine Γ Λ) (w : Fin (n + 1)Γ) :
                        ∃ (T : Turing.Tape (Option Γ)), Turing.Reaches (ntm0Step M n) (ntm0Init M w) { q := NSimState.simulating {initCfg M w}, Tape := T }

                        Simulation Phase #

                        theorem LBA.simulation_step_bfs {Γ : Type u_1} {Λ : Type u_2} {n : } [Fintype Γ] [Fintype Λ] [DecidableEq Γ] [DecidableEq Λ] (M : Machine Γ Λ) (S : Finset (DLBA.Cfg Γ Λ n)) (T : Turing.Tape (Option Γ)) (hnacc : ¬hasAccepting M S) (hne : stepFinset M S S) :
                        ∃ (T' : Turing.Tape (Option Γ)), ntm0Step M n { q := NSimState.simulating S, Tape := T } = some { q := NSimState.simulating (stepFinset M S), Tape := T' }
                        theorem LBA.simulation_halts_on_accept {Γ : Type u_1} {Λ : Type u_2} {n : } [Fintype Γ] [Fintype Λ] [DecidableEq Γ] [DecidableEq Λ] (M : Machine Γ Λ) (S : Finset (DLBA.Cfg Γ Λ n)) (T : Turing.Tape (Option Γ)) (hacc : hasAccepting M S) :
                        ntm0Step M n { q := NSimState.simulating S, Tape := T } = none
                        theorem LBA.iterStepFinset_fixpoint {Γ : Type u_1} {Λ : Type u_2} {n : } [Fintype Γ] [Fintype Λ] [DecidableEq Γ] [DecidableEq Λ] (M : Machine Γ Λ) (S : Finset (DLBA.Cfg Γ Λ n)) {i : } (hfix : stepFinset M (iterStepFinset M S i) = iterStepFinset M S i) {m : } (hm : i m) :
                        theorem LBA.simulation_reaches_iterStepFinset {Γ : Type u_1} {Λ : Type u_2} {n : } [Fintype Γ] [Fintype Λ] [DecidableEq Γ] [DecidableEq Λ] (M : Machine Γ Λ) (S₀ : Finset (DLBA.Cfg Γ Λ n)) (T₀ : Turing.Tape (Option Γ)) (k : ) (hnacc : j < k, ¬hasAccepting M (iterStepFinset M S₀ j)) (hgrow : j < k, stepFinset M (iterStepFinset M S₀ j) iterStepFinset M S₀ j) :
                        ∃ (T : Turing.Tape (Option Γ)), Turing.Reaches (ntm0Step M n) { q := NSimState.simulating S₀, Tape := T₀ } { q := NSimState.simulating (iterStepFinset M S₀ k), Tape := T }
                        theorem LBA.tm0_halts_of_nlba_accepts {Γ : Type u_1} {Λ : Type u_2} {n : } [Fintype Γ] [Fintype Λ] [DecidableEq Γ] [DecidableEq Λ] (M : Machine Γ Λ) (S₀ : Finset (DLBA.Cfg Γ Λ n)) (T : Turing.Tape (Option Γ)) (hacc : cfgS₀, Accepts M cfg) :
                        (Turing.eval (ntm0Step M n) { q := NSimState.simulating S₀, Tape := T }).Dom
                        theorem LBA.eval_dom_of_reaches {σ : Type u_1} (f : σOption σ) (a b : σ) (hr : Turing.Reaches f a b) (hb : (Turing.eval f b).Dom) :

                        Main Theorem #

                        theorem LBA.lba_language_subset_tm0_language {Γ : Type u_1} {Λ : Type u_2} {n : } [Fintype Γ] [Fintype Λ] [DecidableEq Γ] [DecidableEq Λ] (M : Machine Γ Λ) (w : Fin (n + 1)Γ) (hw : w LanguageN M n) :

                        Main theorem: Every word accepted by the NLBA is also accepted by the simulating TM0 machine. This establishes that NLBA languages are a subset of TM0-recognizable languages.