Documentation

CslibFrontier.Computability.Machines.Turing.MultiTape.Universal.NondeterministicBudget

The nondeterministic universal machine within a space budget #

A description d (Turing.MultiTapeTM.Universal.Desc), read nondeterministically (Turing.MultiTapeTM.Universal.NStep), accepts x within the budget b (Turing.MultiTapeTM.Universal.BAccepts) when some computation of it on x halts with the output [1] and every configuration of the simulation it reaches after the first is encoded within b bits (Turing.MultiTapeTM.Universal.BStep).

The universal recognizer Turing.MultiTapeTM.Universal.budgetedNUniversal decides this by guessing the computation one transition at a time, as a nondeterministic query machine (Turing.NondeterministicQueryMachine): its state holds the table of d, a cursor into the table, the budget, the configuration of the simulation and the first two symbols of the output, and it reads the input in place, at the simulated input head. A choice false moves the cursor to the next entry; a choice true fires the entry under the cursor, if its key matches the configuration, and returns the cursor to the start of the table. A branch rejects when the cursor runs off the table, when the entry under the cursor does not match, or when the configuration leaves the budget. So the machine accepts exactly when d accepts within the budget (Turing.MultiTapeTM.Universal.budgetedNUniversal_accepts_iff).

Its state takes space linear in the description, the budget and the configuration, so the native compiler of query machines gives a nondeterministic recognizer within space O(S) for any S that bounds the description, the budget and log₂ n (Turing.MultiTapeTM.Universal.exists_recognizesInSpace_bAccepts). Unlike the deterministic Turing.MultiTapeTM.Universal.budgetedUniversal, the input is never copied and no clock is kept: a recognizer may run forever.

Main definitions #

Main results #

References #

Acceptance within a budget #

A step of the description d within the budget b, read nondeterministically, on the input x: a step (Turing.MultiTapeTM.Universal.NStep) to a configuration encoded within b bits.

The description d accepts x within the budget b: from the initial configuration, steps within the budget reach a halted configuration with the output [1].

theorem Turing.MultiTapeTM.Universal.BAccepts.mono {d : Desc} {x : List ℕ} {b b' : ℕ} (h : BAccepts d x b) (hb : b ≤ b') :
BAccepts d x b'

A larger budget accepts more.

Acceptance within a budget is acceptance: forgetting the budget, the description reaches a halted configuration with the output [1].

The universal recognizer #

The state of the universal recognizer: the table of the description, the entries from the cursor on, the budget, the configuration of the simulation and the first two symbols of the output.

  • table : List (Key × Act)

    The table of the description.

  • rest : List (Key × Act)

    The entries of the table from the cursor on.

  • budget : ℕ

    The budget.

  • cfg : SCfg

    The configuration of the simulation.

  • out : List ℕ

    The first two symbols of the output.

theorem Turing.MultiTapeTM.Universal.eNU_rest_polyTime {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → NUState} :
ComputableInPolyTime g✝ encIn✝ eNU → ComputableInPolyTime (fun (c : γ✝) => (g✝ c).rest) encIn✝ (encList (encPair eKey eAct))
theorem Turing.MultiTapeTM.Universal.eNU_table_polyTime {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → NUState} :
ComputableInPolyTime g✝ encIn✝ eNU → ComputableInPolyTime (fun (c : γ✝) => (g✝ c).table) encIn✝ (encList (encPair eKey eAct))
theorem Turing.MultiTapeTM.Universal.eNU_mk_inO {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → List (Key × Act)} {T0 S0 : γ → ℕ} {x1 : γ → List (Key × Act)} {T1 S1 x2 T2 S2 : γ → ℕ} {x3 : γ → SCfg} {T3 S3 : γ → ℕ} {x4 : γ → List ℕ} {T4 S4 : γ → ℕ} (h0 : ComputableInO x0 encIn (encList (encPair eKey eAct)) T0 S0) (h1 : ComputableInO x1 encIn (encList (encPair eKey eAct)) T1 S1) (h2 : ComputableInO x2 encIn encUnary T2 S2) (h3 : ComputableInO x3 encIn eCfg T3 S3) (h4 : ComputableInO x4 encIn (encList encUnary) T4 S4) :
ComputableInO (fun (x : γ) => { table := x0 x, rest := x1 x, budget := x2 x, cfg := x3 x, out := x4 x }) encIn eNU (fun (x : γ) => T0 x + (T1 x + (T2 x + (T3 x + T4 x)))) fun (x : γ) => S0 x + (S1 x + (S2 x + (S3 x + S4 x)))
theorem Turing.MultiTapeTM.Universal.eNU_cfg_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → NUState} :
ComputableInSpace g✝ encIn✝ eNU S✝ → ComputableInSpace (fun (c : γ✝) => (g✝ c).cfg) encIn✝ eCfg S✝
@[reducible, inline]

The tuple of the fields of eNU.

theorem Turing.MultiTapeTM.Universal.eNU_budget_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → NUState} :
ComputableInSpace g✝ encIn✝ eNU S✝ → ComputableInSpace (fun (c : γ✝) => (g✝ c).budget) encIn✝ encUnary S✝

States of the universal recognizer, as their fields, the budget in unary.

theorem Turing.MultiTapeTM.Universal.eNU_table_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → NUState} :
ComputableInSpace g✝ encIn✝ eNU S✝ → ComputableInSpace (fun (c : γ✝) => (g✝ c).table) encIn✝ (encList (encPair eKey eAct)) S✝
theorem Turing.MultiTapeTM.Universal.eNU_mk_budget {γ : Type} {encIn : γ ↪ List Bool} {budget : γ → ℕ} {x0 x1 : γ → List (Key × Act)} {x2 : γ → ℕ} {x3 : γ → SCfg} {x4 : γ → List ℕ} (h0 : ComputableInSpace x0 encIn (encList (encPair eKey eAct)) budget) (h1 : ComputableInSpace x1 encIn (encList (encPair eKey eAct)) budget) (h2 : ComputableInSpace x2 encIn encUnary budget) (h3 : ComputableInSpace x3 encIn eCfg budget) (h4 : ComputableInSpace x4 encIn (encList encUnary) budget) :
ComputableInSpace (fun (x : γ) => { table := x0 x, rest := x1 x, budget := x2 x, cfg := x3 x, out := x4 x }) encIn eNU budget
theorem Turing.MultiTapeTM.Universal.eNU_cfg_polyTime {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → NUState} :
ComputableInPolyTime g✝ encIn✝ eNU → ComputableInPolyTime (fun (c : γ✝) => (g✝ c).cfg) encIn✝ eCfg
theorem Turing.MultiTapeTM.Universal.eNU_rest_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → NUState} :
ComputableInSpace g✝ encIn✝ eNU S✝ → ComputableInSpace (fun (c : γ✝) => (g✝ c).rest) encIn✝ (encList (encPair eKey eAct)) S✝
theorem Turing.MultiTapeTM.Universal.eNU_out_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → NUState} :
ComputableInSpace g✝ encIn✝ eNU S✝ → ComputableInSpace (fun (c : γ✝) => (g✝ c).out) encIn✝ (encList encUnary) S✝
theorem Turing.MultiTapeTM.Universal.eNU_budget_polyTime {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → NUState} :
ComputableInPolyTime g✝ encIn✝ eNU → ComputableInPolyTime (fun (c : γ✝) => (g✝ c).budget) encIn✝ encUnary
theorem Turing.MultiTapeTM.Universal.eNU_mk_deg :
ComputableInDegree (fun (p : List (Key × Act) × List (Key × Act) × ℕ × SCfg × List ℕ) => { table := p.1, rest := p.2.1, budget := p.2.2.1, cfg := p.2.2.2.1, out := p.2.2.2.2 }) eNUFields eNU 1 1
theorem Turing.MultiTapeTM.Universal.eNU_mk_polyTime {γ : Type} {encIn : γ ↪ List Bool} {x0 x1 : γ → List (Key × Act)} {x2 : γ → ℕ} {x3 : γ → SCfg} {x4 : γ → List ℕ} (h0 : ComputableInPolyTime x0 encIn (encList (encPair eKey eAct))) (h1 : ComputableInPolyTime x1 encIn (encList (encPair eKey eAct))) (h2 : ComputableInPolyTime x2 encIn encUnary) (h3 : ComputableInPolyTime x3 encIn eCfg) (h4 : ComputableInPolyTime x4 encIn (encList encUnary)) :
ComputableInPolyTime (fun (x : γ) => { table := x0 x, rest := x1 x, budget := x2 x, cfg := x3 x, out := x4 x }) encIn eNU
theorem Turing.MultiTapeTM.Universal.eNU_out_polyTime {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → NUState} :
ComputableInPolyTime g✝ encIn✝ eNU → ComputableInPolyTime (fun (c : γ✝) => (g✝ c).out) encIn✝ (encList encUnary)

The symbol under the simulated input head at the position p, given the answer a to the query of the position p - 1: blank at position 0.

The universal recognizer within a budget, as a nondeterministic query machine: it queries the input under the simulated input head, guesses the transitions one entry of the table at a time, halts with the simulation and accepts on the output [1]. Its initial state is irrelevant: it is started at Turing.MultiTapeTM.Universal.nuStart with Turing.NondeterministicQueryMachine.withInit.

The start of the universal recognizer on the description d within the budget b.

Correctness #

The universal recognizer accepts exactly when the description accepts within the budget.

Space certificates #

theorem Turing.MultiTapeTM.Universal.nuSym_budget {γ : Type} {encIn : γ ↪ List Bool} {Bs p : γ → ℕ} {a : γ → Option Bool} (hp : ComputableInSpace p encIn encNat Bs) (ha : ComputableInSpace a encIn (encOption encBool) Bs) :
ComputableInSpace (fun (x : γ) => nuSym (p x) (a x)) encIn eSym Bs

The size of the reachable states #

theorem Turing.MultiTapeTM.Universal.length_eNU_run_le (d : Desc) (b : ℕ) (x choices : List Bool) :
(eNU ((budgetedNUniversal.withInit (nuStart d b)).run x choices)).length ≤ 40 * descLen d + 4 * b + 40

The states the universal recognizer reaches from nuStart d b, on any input, are encoded within linear space in the description and the budget.

theorem Turing.MultiTapeTM.Universal.nuStart_budget {α : Type} {enc : α ↪ List Bool} {D : α → Desc} {B S : α → ℕ} (hD : ComputableInSpace D enc eDesc S) (hB : ComputableInSpace B enc encUnary S) :
ComputableInSpace (fun (a : α) => nuStart (D a) (B a)) enc eNU S

The start of the universal recognizer, for a description and a budget computed within a space bound, is computed within that bound.

Machines within a space bound #

theorem Turing.MultiTapeTM.Universal.accepts_iff_bAccepts_descN {k : ℕ} {State : Type} [Finite State] (eS : State ↪ ℕ) (ntm : MultiTapeNTM k Bool State) {input : List Bool} {S b : ℕ} (hS : ntm.RunsInSpace input S) (hb : cfgSpaceBound (descLen (descN eS eBit ntm)) input.length k S ≤ b) :
ntm.Accepts input ↔ BAccepts (descN eS eBit ntm) (List.map (⇑eBit) input) b

A machine within S cells accepts exactly when its description accepts within a budget b at least the size bound Turing.MultiTapeTM.Universal.cfgSpaceBound of its configurations.

The compiled recognizer #

theorem Turing.MultiTapeTM.Universal.exists_recognizesInSpace_bAccepts {α : Type} (enc : α ↪ List Bool) (D : α → Desc) (B S : α → ℕ) (hD : ComputableInSpace D enc eDesc S) (hB : ComputableInSpace B enc encUnary S) (hlog : ∀ (a : α), (enc a).length.log2 + 1 ≤ S a) :
∃ (k : ℕ) (State : Type) (_ : Finite State) (ntm : MultiTapeNTM k Bool State) (c : ℕ), ntm.RecognizesInSpace enc {a : α | BAccepts (D a) (List.map (⇑eBit) (enc a)) (B a)} fun (a : α) => c * S a

A native nondeterministic recognizer of acceptance within a budget, in space O(S): for a description D a and a budget B a computed from the input a within the space S a ≥ log₂ |a|, the inputs a on which D a accepts a within the budget B a.