Documentation

CslibFrontier.Computability.Machines.Turing.MultiTape.Internal.RiceDispatch

Internal description dispatch for Rice's self-reference construction #

This is the existing dispatch program and its native run proof, moved unchanged from Halting.Rice. It buffers the output of a normalized total machine, branches on its first bit, and runs the selected description on the remaining word. The clean input/work-tape premise is essential: Universal.Desc.computes_dispatch retains it explicitly. The public Rice facade imports this module only for its proof; ordinary clients need no machine normal-form contract.

Finding transitions #

Dispatching on a computed bit #

The action on the virtual input tape writing there the symbol o emitted by a transition.

The number of work tapes of the two descriptions.

What the work tapes after the virtual input tape read before and after the run of tm.

Writing the marker, in the state 0.

noncomputable def Turing.MultiTapeTM.Universal.Dispatch.runEntries {k : ℕ} {S : Type} [Fintype S] (eS : S ↪ ℕ) (tm : MultiTapeTM k Bool S) (d : Bool → Desc) :

The transitions of tm, in the states 4 * q + 1, writing its output on the virtual input tape, and moving to the state 4 when tm halts.

Rewinding the virtual input tape, in the state 4, and branching on its first symbol in the state 8: the symbol becomes the marker, and the input head moves onto the blank left of the input.

The transitions of d b, reading the input from the virtual input tape.

noncomputable def Turing.MultiTapeTM.Universal.dispatch {k : ℕ} {S : Type} [Fintype S] (eS : S ↪ ℕ) (tm : MultiTapeTM k Bool S) (d : Bool → Desc) :

Dispatching on a computed bit. The description runs the machine tm, buffering its output on a new first work tape, the virtual input tape; when tm halts with output b :: v and blank work tapes, as after a tidy computation, it runs the description d b on v, reading it from the virtual input tape (Turing.MultiTapeTM.Universal.Desc.computes_dispatch).

The transitions of dispatch eS tm d #

def Turing.MultiTapeTM.Universal.Dispatch.prepAct {k : ℕ} {S : Type} (eS : S ↪ ℕ) (tm : MultiTapeTM k Bool S) (d : Bool → Desc) (key : Key) :

The action of the transitions writing the marker, rewinding and branching, as a function of their keys.

theorem Turing.MultiTapeTM.Universal.Dispatch.prep_spec {k : ℕ} {S : Type} (eS : S ↪ ℕ) (tm : MultiTapeTM k Bool S) (d : Bool → Desc) {e : Key × Act} (he : e ∈ markerEntries eS tm d ++ branchEntries d k) :
(e.1.state = 0 ∨ e.1.state = 4 ∨ e.1.state = 8) ∧ e.2 = prepAct eS tm d e.1
theorem Turing.MultiTapeTM.Universal.Dispatch.state_runEntries {k : ℕ} {S : Type} [Fintype S] (eS : S ↪ ℕ) (tm : MultiTapeTM k Bool S) (d : Bool → Desc) {e : Key × Act} (he : e ∈ runEntries eS tm d) :
e.1.state % 4 = 1
theorem Turing.MultiTapeTM.Universal.Dispatch.find?_prep {k : ℕ} {S : Type} [Fintype S] (eS : S ↪ ℕ) (tm : MultiTapeTM k Bool S) (d : Bool → Desc) {e : Key × Act} (he : e ∈ markerEntries eS tm d ++ branchEntries d k) :
List.find? (fun (x : Key × Act) => decide (x.1 = e.1)) (dispatch eS tm d).table = some e

Each transition writing the marker, rewinding or branching is the one found for its key.

theorem Turing.MultiTapeTM.Universal.Dispatch.find?_run {k : ℕ} {S : Type} [Fintype S] (eS : S ↪ ℕ) (tm : MultiTapeTM k Bool S) (d : Bool → Desc) (q : ℕ) (i : Option ℕ) (ws : List (Option ℕ)) :
List.find? (fun (x : Key × Act) => decide (x.1 = { state := 4 * q + 1, input := i, work := none :: (ws ++ List.replicate (width d) none) })) (dispatch eS tm d).table = Option.map (fun (e : Key × Act) => ({ state := 4 * e.1.state + 1, input := e.1.input, work := none :: (e.1.work ++ List.replicate (width d) none) }, { inputTape := e.2.inputTape, workTapes := outAct e.2.output :: e.2.workTapes, output := none, state := some (e.2.state.elim 4 fun (q : ℕ) => 4 * q + 1) })) (List.find? (fun (x : Key × Act) => decide (x.1 = { state := q, input := i, work := ws })) (desc eS eBit tm).table)

For the states of tm, the transitions found are those of tm, writing the output on the virtual input tape.

theorem Turing.MultiTapeTM.Universal.Dispatch.find?_redirectEntries {k : ℕ} {S : Type} [Fintype S] (eS : S ↪ ℕ) (tm : MultiTapeTM k Bool S) (d : Bool → Desc) (b : Bool) (q : ℕ) (ws : List (Option ℕ)) :
List.find? (fun (x : Key × Act) => decide (x.1 = { state := dstate b q, input := none, work := ws })) (dispatch eS tm d).table = List.find? (fun (x : Key × Act) => decide (x.1 = { state := dstate b q, input := none, work := ws })) (redirectEntries d k b)

For the states of d b and an input head reading a blank, the transitions found are those of d b, redirected.

Running tm #

The configuration of dispatch eS tm d standing for the configuration c of the description of tm, with the output out so far written on the virtual input tape.

theorem Turing.MultiTapeTM.Universal.Dispatch.stepOut_runCfg {k : ℕ} {S : Type} [Fintype S] (eS : S ↪ ℕ) (tm : MultiTapeTM k Bool S) (d : Bool → Desc) {X : List ℕ} {c : SCfg} {q : ℕ} (hq : c.state = some q) {e : Key × Act} (he : List.find? (fun (x : Key × Act) => decide (x.1 = c.key X q)) (desc eS eBit tm).table = some e) (hlen : e.2.workTapes.length ≤ c.workTapes.length) (out : List ℕ) :
stepOut (dispatch eS tm d) X (runCfg d c out, []) = (runCfg d (step (desc eS eBit tm) X c).1 (out ++ (step (desc eS eBit tm) X c).2.toList), [])

A step of tm is a step of dispatch eS tm d, which emits nothing.

noncomputable def Turing.MultiTapeTM.Universal.Dispatch.descRun {k : ℕ} {S : Type} [Fintype S] (eS : S ↪ ℕ) (tm : MultiTapeTM k Bool S) (x : List ℕ) (t : ℕ) :

The run of the description of tm on the input x, with its output.

theorem Turing.MultiTapeTM.Universal.Dispatch.iterate_runCfg {k : ℕ} {S : Type} [Fintype S] (eS : S ↪ ℕ) (tm : MultiTapeTM k Bool S) (d : Bool → Desc) {x : List ℕ} (hx : inputSymbol x 1 ∈ Redirect.bitSyms) {u : ℕ} (hrun : ∀ t < u, ∃ (q : ℕ) (e : Key × Act), (descRun eS tm x t).1.state = some q ∧ List.find? (fun (x_1 : Key × Act) => decide (x_1.1 = (descRun eS tm x t).1.key x q)) (desc eS eBit tm).table = some e ∧ e.2.workTapes.length ≤ (descRun eS tm x t).1.workTapes.length) (t : ℕ) :
t ≤ u → (stepOut (dispatch eS tm d) x)^[t + 1] (init (dispatch eS tm d), []) = (runCfg d (descRun eS tm x t).1 (descRun eS tm x t).2, [])

While the description of tm runs, dispatch eS tm d runs it after writing the marker.

theorem Turing.MultiTapeTM.Universal.Dispatch.exists_run_of_computesTidily {k : ℕ} {S : Type} [Fintype S] (eS : S ↪ ℕ) (tm : MultiTapeTM k Bool S) {w o : List Bool} {t₀ s₀ : ℕ} (htm : tm.ComputesTidilyInTimeAndSpace w o t₀ s₀) :
∃ (u : ℕ), (∀ t < u, ∃ (q : ℕ) (e : Key × Act), (descRun eS tm (List.map (⇑eBit) w) t).1.state = some q ∧ List.find? (fun (x : Key × Act) => decide (x.1 = (descRun eS tm (List.map (⇑eBit) w) t).1.key (List.map (⇑eBit) w) q)) (desc eS eBit tm).table = some e ∧ e.2.workTapes.length ≤ (descRun eS tm (List.map (⇑eBit) w) t).1.workTapes.length) ∧ (descRun eS tm (List.map (⇑eBit) w) u).1.state = none ∧ (descRun eS tm (List.map (⇑eBit) w) u).1.inputPos = 1 ∧ List.map Tape.read (descRun eS tm (List.map (⇑eBit) w) u).1.workTapes = List.replicate k none ∧ (descRun eS tm (List.map (⇑eBit) w) u).2 = List.map (⇑eBit) o

The run of tm on w, from a tidy computation: the description of tm runs, with a transition for every key it meets, until it halts with the input head on the first symbol, blank work tapes and the output b :: v.

theorem Turing.MultiTapeTM.Universal.Desc.computes_dispatch {k : ℕ} {S : Type} [Fintype S] (eS : S ↪ ℕ) (tm : MultiTapeTM k Bool S) (d : Bool → Desc) {w : List Bool} {b : Bool} {v : List Bool} {t₀ s₀ : ℕ} (htm : tm.ComputesTidilyInTimeAndSpace w (b :: v) t₀ s₀) (o : List ℕ) :
(dispatch eS tm d).Computes (List.map (⇑eBit) w) o ↔ (d b).Computes (List.map (⇑eBit) v) o

Dispatching on a computed bit: if tm computes b :: v from w tidily, then dispatch eS tm d halts on w with output o exactly when d b halts on v with output o.