Documentation

CslibFrontier.Computability.Machines.Turing.MultiTape.Universal.PolySpace

Polynomial-space simulation and configuration-count clocks #

This module provides general configuration-count clock theorems and polynomial-space simulation certificates for Turing.MultiTapeTM.Universal:

Main definitions #

Main results #

Halting and space stabilization for run, universal, and simSpace #

theorem Turing.MultiTapeTM.Universal.step_fst_iterate_run (d : Desc) (x : List ℕ) (j m : ℕ) :
(fun (c : SCfg) => (step d x c).1)^[m] (run d x j) = run d x (j + m)

Iterating fun c => (step d x c).1 from run d x j advances run d x by m steps.

A halted simulated configuration is a fixed point of step, emitting no output.

theorem Turing.MultiTapeTM.Universal.stepOut_iterate_eq_of_state_eq_none (d : Desc) (x : List ℕ) {t T : ℕ} (hhalt : (run d x t).state = none) (hT : t ≤ T) :

Once run d x t has halted, stepOut d x is a fixed point at all later steps T ≥ t.

theorem Turing.MultiTapeTM.Universal.run_eq_of_state_eq_none (d : Desc) (x : List ℕ) {t T : ℕ} (hhalt : (run d x t).state = none) (hT : t ≤ T) :
run d x T = run d x t

Once run d x t has halted, run d x T = run d x t for all T ≥ t.

theorem Turing.MultiTapeTM.Universal.universal_eq_of_snd (d : Desc) (x : List ℕ) {t T : ℕ} (hhalt : (universal (d, x, t)).2 = true) (hT : t ≤ T) :

Once universal (d, x, t) reports halting, increasing the step count t ≤ T leaves its result unchanged.

theorem Turing.MultiTapeTM.Universal.visited_eq_of_state_eq_none (d : Desc) (x : List ℕ) {t T : ℕ} (hhalt : (run d x t).state = none) (hT : t ≤ T) (i : ℕ) :
visited d x T i = visited d x t i

Once run d x t has halted, the visited positions of each tape stabilize for all T ≥ t.

theorem Turing.MultiTapeTM.Universal.simSpace_eq_of_state_eq_none (d : Desc) (x : List ℕ) {t T : ℕ} (hhalt : (run d x t).state = none) (hT : t ≤ T) :
simSpace d x T = simSpace d x t

Once run d x t has halted, simSpace d x T = simSpace d x t for all T ≥ t.

theorem Turing.MultiTapeTM.Universal.exists_simSpace_le_and_universal_le_two_pow (d : Desc) (x : List ℕ) {t s b : ℕ} (hsp : simSpace d x t ≤ s) (hhalt : (universal (d, x, t)).2 = true) (hb : cfgSpaceBound (descLen d) x.length d.tapes s ≤ b) :
∃ t₀ ≤ 2 ^ (b + 1), simSpace d x t₀ ≤ s ∧ universal (d, x, t₀) = universal (d, x, t)

Configuration-count clock for visited-space simulations: if universal (d, x, t) halts at some step t with simSpace d x t ≤ s, then for any b ≥ cfgSpaceBound (descLen d) x.length d.tapes s, it already halts with the same output at some step t₀ ≤ 2 ^ (b + 1) with simSpace d x t₀ ≤ s.

theorem Turing.MultiTapeTM.Universal.exists_simSpace_le_and_universal_eq_true_iff (d : Desc) (x : List ℕ) (s : ℕ) (out : List ℕ) {b T : ℕ} (hb : cfgSpaceBound (descLen d) x.length d.tapes s ≤ b) (hT : 2 ^ (b + 1) ≤ T) :
(∃ (t : ℕ), simSpace d x t ≤ s ∧ universal (d, x, t) = (out, true)) ↔ simSpace d x T ≤ s ∧ universal (d, x, T) = (out, true)

Clocked equivalence for visited-space simulations: for any b ≥ cfgSpaceBound (descLen d) x.length d.tapes s and any step count T ≥ 2 ^ (b + 1), there exists a step t with simSpace d x t ≤ s and universal (d, x, t) = (out, true) if and only if simSpace d x T ≤ s and universal (d, x, T) = (out, true).

Configuration-count clock and polynomial-space certificate for budgetedUniversal #

theorem Turing.MultiTapeTM.Universal.budgetStep_of_state_eq_none (d : Desc) (x : List ℕ) (b : ℕ) {p : SCfg × List ℕ} (hstate : p.1.state = none) (hlen : p.2.length ≤ 2) :
budgetStep d x b p = p

Once budgetStep reaches a halted configuration with at most 2 output symbols, it is a fixed point.

theorem Turing.MultiTapeTM.Universal.budgetStep_iterate_eq_of_le (d : Desc) (x : List ℕ) (b : ℕ) {t T : ℕ} (hhalt : ((budgetStep d x b)^[t] (init d, [])).1.state.isNone = true) (hT : t ≤ T) :

Once the budgeted run from (init d, []) halts at step t, it remains at the same pair at every later step T ≥ t.

Once budgetedUniversal (d, x, t, b) reports halting, increasing the step count t ≤ T leaves its result unchanged.

theorem Turing.MultiTapeTM.Universal.exists_budgetedUniversal_le_two_pow (d : Desc) (x : List ℕ) (b : ℕ) {t : ℕ} (hhalt : (budgetedUniversal (d, x, t, b)).2 = true) :
∃ t₀ ≤ 2 ^ (b + 1), budgetedUniversal (d, x, t₀, b) = budgetedUniversal (d, x, t, b)

Configuration-count clock for budgetedUniversal: if budgetedUniversal (d, x, t, b) halts at some step t, then it already halts with the same output at some step t₀ ≤ 2 ^ (b + 1). Before the first halting step t₀, every step must fit within the b-bit configuration budget and visit a distinct configuration in shortWords b.

theorem Turing.MultiTapeTM.Universal.exists_budgetedUniversal_eq_true_iff (d : Desc) (x : List ℕ) (b : ℕ) (out : List ℕ) {T : ℕ} (hT : 2 ^ (b + 1) ≤ T) :
(∃ (t : ℕ), budgetedUniversal (d, x, t, b) = (out, true)) ↔ budgetedUniversal (d, x, T, b) = (out, true)

Clocked equivalence for budgetedUniversal: for any step count T ≥ 2 ^ (b + 1), there exists a step t at which budgetedUniversal (d, x, t, b) = (out, true) if and only if budgetedUniversal (d, x, T, b) = (out, true).

budgetedUniversal is computable in polynomial space (in fact linear space) with respect to eInS and eOut.

Visited-cell-budgeted universal simulation (spaceBoundedUniversal) #

@[reducible, inline]

Canonical encoding of per-tape head excursion bounds List (ℕ × ℕ).

Initial per-tape head excursion bounds (leftMax, rightMax) = (0, 0) for each of d.tapes work tapes.

Update per-tape head excursion bounds (leftMax, rightMax) from the current work-tape head positions.

Total number of visited work-tape cells represented by per-tape excursion bounds bounds : List (ℕ × ℕ), where an excursion interval [ -l, r ] covers l + r + 1 cells.

The per-tape head excursion bounds along the simulated run run d x after j steps.

theorem Turing.MultiTapeTM.Universal.boundsSpace_eq_sum_map (bounds : List (ℕ × ℕ)) :
boundsSpace bounds = (List.map (fun (p : ℕ × ℕ) => p.1 + p.2 + 1) bounds).sum
theorem Turing.MultiTapeTM.Universal.visited_eq_Icc_boundsAt (d : Desc) (x : List ℕ) (j : ℕ) {i : ℕ} (hi : i < d.tapes) :
visited d x j i = Finset.Icc (-↑((boundsAt d x j).getD i (0, 0)).1) ↑((boundsAt d x j).getD i (0, 0)).2 ∧ -↑((boundsAt d x j).getD i (0, 0)).1 ≤ headAt d x j i ∧ headAt d x j i ≤ ↑((boundsAt d x j).getD i (0, 0)).2

At step j, for every work tape i < d.tapes, the visited positions visited d x j i form the integer interval [ -l, r ] where (l, r) = (boundsAt d x j).getD i (0, 0), and the current head headAt d x j i lies in [ -l, r ].

theorem Turing.MultiTapeTM.Universal.card_visited_eq_boundsAt (d : Desc) (x : List ℕ) (j : ℕ) {i : ℕ} (hi : i < d.tapes) :
(visited d x j i).card = ((boundsAt d x j).getD i (0, 0)).1 + ((boundsAt d x j).getD i (0, 0)).2 + 1

boundsSpace (boundsAt d x j) equals simSpace d x j.

At step 0, simSpace d x 0 = d.tapes.

Loop state for visited-space bounded universal simulation.

  • desc : Desc

    Description of the simulated machine.

  • input : List ℕ

    Simulated input symbols.

  • space : ℕ

    Visited work-tape cell budget.

  • cfg : SCfg

    Current simulated configuration.

  • output : List ℕ

    First two output symbols emitted so far.

  • bounds : List (ℕ × ℕ)

    Per-tape head excursion bounds (leftMax, rightMax).

  • withinSpace : Bool

    Whether every step up to the current configuration stayed within space visited cells.

Instances For
    theorem Turing.MultiTapeTM.Universal.eSpaceLoopState_mk_polyTime {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → Desc} {x1 : γ → List ℕ} {x2 : γ → ℕ} {x3 : γ → SCfg} {x4 : γ → List ℕ} {x5 : γ → List (ℕ × ℕ)} {x6 : γ → Bool} (h0 : ComputableInPolyTime x0 encIn eDesc) (h1 : ComputableInPolyTime x1 encIn (encList encUnary)) (h2 : ComputableInPolyTime x2 encIn encUnary) (h3 : ComputableInPolyTime x3 encIn eCfg) (h4 : ComputableInPolyTime x4 encIn (encList encUnary)) (h5 : ComputableInPolyTime x5 encIn eBounds) (h6 : ComputableInPolyTime x6 encIn encBool) :
    ComputableInPolyTime (fun (x : γ) => { desc := x0 x, input := x1 x, space := x2 x, cfg := x3 x, output := x4 x, bounds := x5 x, withinSpace := x6 x }) encIn eSpaceLoopState
    theorem Turing.MultiTapeTM.Universal.eSpaceLoopState_cfg_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → SpaceLoopState} :
    ComputableInSpace g✝ encIn✝ eSpaceLoopState S✝ → ComputableInSpace (fun (c : γ✝) => (g✝ c).cfg) encIn✝ eCfg S✝
    theorem Turing.MultiTapeTM.Universal.eSpaceLoopState_input_polyTime {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → SpaceLoopState} :
    ComputableInPolyTime g✝ encIn✝ eSpaceLoopState → ComputableInPolyTime (fun (c : γ✝) => (g✝ c).input) encIn✝ (encList encUnary)
    theorem Turing.MultiTapeTM.Universal.eSpaceLoopState_bounds_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → SpaceLoopState} :
    ComputableInSpace g✝ encIn✝ eSpaceLoopState S✝ → ComputableInSpace (fun (c : γ✝) => (g✝ c).bounds) encIn✝ eBounds S✝
    theorem Turing.MultiTapeTM.Universal.eSpaceLoopState_desc_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → SpaceLoopState} :
    ComputableInSpace g✝ encIn✝ eSpaceLoopState S✝ → ComputableInSpace (fun (c : γ✝) => (g✝ c).desc) encIn✝ eDesc S✝
    theorem Turing.MultiTapeTM.Universal.eSpaceLoopState_space_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → SpaceLoopState} :
    ComputableInSpace g✝ encIn✝ eSpaceLoopState S✝ → ComputableInSpace (fun (c : γ✝) => (g✝ c).space) encIn✝ encUnary S✝
    theorem Turing.MultiTapeTM.Universal.eSpaceLoopState_input_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → SpaceLoopState} :
    ComputableInSpace g✝ encIn✝ eSpaceLoopState S✝ → ComputableInSpace (fun (c : γ✝) => (g✝ c).input) encIn✝ (encList encUnary) S✝
    theorem Turing.MultiTapeTM.Universal.eSpaceLoopState_mk_budget {γ : Type} {encIn : γ ↪ List Bool} {budget : γ → ℕ} {x0 : γ → Desc} {x1 : γ → List ℕ} {x2 : γ → ℕ} {x3 : γ → SCfg} {x4 : γ → List ℕ} {x5 : γ → List (ℕ × ℕ)} {x6 : γ → Bool} (h0 : ComputableInSpace x0 encIn eDesc budget) (h1 : ComputableInSpace x1 encIn (encList encUnary) budget) (h2 : ComputableInSpace x2 encIn encUnary budget) (h3 : ComputableInSpace x3 encIn eCfg budget) (h4 : ComputableInSpace x4 encIn (encList encUnary) budget) (h5 : ComputableInSpace x5 encIn eBounds budget) (h6 : ComputableInSpace x6 encIn encBool budget) :
    ComputableInSpace (fun (x : γ) => { desc := x0 x, input := x1 x, space := x2 x, cfg := x3 x, output := x4 x, bounds := x5 x, withinSpace := x6 x }) encIn eSpaceLoopState budget
    theorem Turing.MultiTapeTM.Universal.eSpaceLoopState_cfg_polyTime {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → SpaceLoopState} :
    ComputableInPolyTime g✝ encIn✝ eSpaceLoopState → ComputableInPolyTime (fun (c : γ✝) => (g✝ c).cfg) encIn✝ eCfg
    theorem Turing.MultiTapeTM.Universal.eSpaceLoopState_space_polyTime {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → SpaceLoopState} :
    ComputableInPolyTime g✝ encIn✝ eSpaceLoopState → ComputableInPolyTime (fun (c : γ✝) => (g✝ c).space) encIn✝ encUnary
    theorem Turing.MultiTapeTM.Universal.eSpaceLoopState_output_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → SpaceLoopState} :
    ComputableInSpace g✝ encIn✝ eSpaceLoopState S✝ → ComputableInSpace (fun (c : γ✝) => (g✝ c).output) encIn✝ (encList encUnary) S✝
    theorem Turing.MultiTapeTM.Universal.eSpaceLoopState_desc_polyTime {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → SpaceLoopState} :
    ComputableInPolyTime g✝ encIn✝ eSpaceLoopState → ComputableInPolyTime (fun (c : γ✝) => (g✝ c).desc) encIn✝ eDesc
    theorem Turing.MultiTapeTM.Universal.eSpaceLoopState_mk_inO {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → Desc} {T0 S0 : γ → ℕ} {x1 : γ → List ℕ} {T1 S1 x2 T2 S2 : γ → ℕ} {x3 : γ → SCfg} {T3 S3 : γ → ℕ} {x4 : γ → List ℕ} {T4 S4 : γ → ℕ} {x5 : γ → List (ℕ × ℕ)} {T5 S5 : γ → ℕ} {x6 : γ → Bool} {T6 S6 : γ → ℕ} (h0 : ComputableInO x0 encIn eDesc T0 S0) (h1 : ComputableInO x1 encIn (encList encUnary) T1 S1) (h2 : ComputableInO x2 encIn encUnary T2 S2) (h3 : ComputableInO x3 encIn eCfg T3 S3) (h4 : ComputableInO x4 encIn (encList encUnary) T4 S4) (h5 : ComputableInO x5 encIn eBounds T5 S5) (h6 : ComputableInO x6 encIn encBool T6 S6) :
    ComputableInO (fun (x : γ) => { desc := x0 x, input := x1 x, space := x2 x, cfg := x3 x, output := x4 x, bounds := x5 x, withinSpace := x6 x }) encIn eSpaceLoopState (fun (x : γ) => T0 x + (T1 x + (T2 x + (T3 x + (T4 x + (T5 x + T6 x)))))) fun (x : γ) => S0 x + (S1 x + (S2 x + (S3 x + (S4 x + (S5 x + S6 x)))))
    theorem Turing.MultiTapeTM.Universal.eSpaceLoopState_withinSpace_polyTime {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → SpaceLoopState} :
    ComputableInPolyTime g✝ encIn✝ eSpaceLoopState → ComputableInPolyTime (fun (c : γ✝) => (g✝ c).withinSpace) encIn✝ encBool
    theorem Turing.MultiTapeTM.Universal.eSpaceLoopState_withinSpace_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → SpaceLoopState} :
    ComputableInSpace g✝ encIn✝ eSpaceLoopState S✝ → ComputableInSpace (fun (c : γ✝) => (g✝ c).withinSpace) encIn✝ encBool S✝
    theorem Turing.MultiTapeTM.Universal.eSpaceLoopState_output_polyTime {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → SpaceLoopState} :
    ComputableInPolyTime g✝ encIn✝ eSpaceLoopState → ComputableInPolyTime (fun (c : γ✝) => (g✝ c).output) encIn✝ (encList encUnary)
    theorem Turing.MultiTapeTM.Universal.eSpaceLoopState_mk_deg :
    ComputableInDegree (fun (p : Desc × List ℕ × ℕ × SCfg × List ℕ × List (ℕ × ℕ) × Bool) => { desc := p.1, input := p.2.1, space := p.2.2.1, cfg := p.2.2.2.1, output := p.2.2.2.2.1, bounds := p.2.2.2.2.2.1, withinSpace := p.2.2.2.2.2.2 }) eSpaceLoopStateFields eSpaceLoopState 1 1
    theorem Turing.MultiTapeTM.Universal.eSpaceLoopState_bounds_polyTime {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → SpaceLoopState} :
    ComputableInPolyTime g✝ encIn✝ eSpaceLoopState → ComputableInPolyTime (fun (c : γ✝) => (g✝ c).bounds) encIn✝ eBounds

    One step of visited-space bounded simulation: if st.withinSpace holds, compute the next simulated configuration and updated excursion bounds; if the resulting visited cell count boundsSpace bounds' stays within st.space, advance to the new configuration and bounds, otherwise freeze the state and record withinSpace := false.

    Visited-cell-budgeted universal simulation: run spaceLoopStep for t steps on spaceLoopInit i and return the first two output symbols together with whether the run stayed within s visited work-tape cells and halted.

    theorem Turing.MultiTapeTM.Universal.spaceLoopStep_iterate (d : Desc) (x : List ℕ) (t s k : ℕ) :
    (simSpace d x k ≤ s → spaceLoopStep^[k] (spaceLoopInit (d, x, t, s)) = { desc := d, input := x, space := s, cfg := run d x k, output := List.take 2 ((stepOut d x)^[k] (init d, [])).2, bounds := boundsAt d x k, withinSpace := true }) ∧ (¬simSpace d x k ≤ s → ∃ j ≤ k, (j = 0 ∨ simSpace d x j ≤ s) ∧ spaceLoopStep^[k] (spaceLoopInit (d, x, t, s)) = { desc := d, input := x, space := s, cfg := run d x j, output := List.take 2 ((stepOut d x)^[j] (init d, [])).2, bounds := boundsAt d x j, withinSpace := false })

    Characterization of spaceLoopStep^[k] (spaceLoopInit (d, x, t, s)):

    • when simSpace d x k ≤ s, the loop state is at step k of run d x with withinSpace = true;
    • when ¬ simSpace d x k ≤ s, withinSpace = false and the loop state is frozen at some step j ≤ k with j = 0 ∨ simSpace d x j ≤ s.
    theorem Turing.MultiTapeTM.Universal.exists_spaceLoopStep_iterate (d : Desc) (x : List ℕ) (t s k : ℕ) :
    ∃ j ≤ k, ∃ (ok : Bool), (j = 0 ∨ simSpace d x j ≤ s) ∧ spaceLoopStep^[k] (spaceLoopInit (d, x, t, s)) = { desc := d, input := x, space := s, cfg := run d x j, output := List.take 2 ((stepOut d x)^[j] (init d, [])).2, bounds := boundsAt d x j, withinSpace := ok }

    Every reachable state of spaceLoopStep from spaceLoopInit (d, x, t, s) is at some step j ≤ k of run d x with j = 0 ∨ simSpace d x j ≤ s.

    When simSpace d x t ≤ s, spaceBoundedUniversal (d, x, t, s) returns the first two output symbols of universal (d, x, t) and whether it has halted.

    When ¬ simSpace d x t ≤ s, spaceBoundedUniversal (d, x, t, s) reports false in its second component.

    Characterization of spaceBoundedUniversal acceptance: spaceBoundedUniversal (d, x, t, s) = (out, true) holds if and only if simSpace d x t ≤ s, (universal (d, x, t)).1.take 2 = out, and (universal (d, x, t)).2 = true.

    theorem Turing.MultiTapeTM.Universal.take_two_eq_singleton_iff {α : Type u_1} {l : List α} {a : α} :
    List.take 2 l = [a] ↔ l = [a]

    Taking the first 2 elements of a list equals a singleton [a] if and only if the list itself equals [a].

    Singleton-output characterization of spaceBoundedUniversal: spaceBoundedUniversal (d, x, t, s) = ([n], true) holds if and only if simSpace d x t ≤ s and universal (d, x, t) = ([n], true).

    Clocked equivalence for spaceBoundedUniversal with singleton output: for any b ≥ cfgSpaceBound (descLen d) x.length d.tapes s and T ≥ 2 ^ (b + 1), there exists a step t at which spaceBoundedUniversal (d, x, t, s) = ([n], true) if and only if spaceBoundedUniversal (d, x, T, s) = ([n], true).

    Polynomial-time step and polynomial-space certificate for spaceBoundedUniversal #

    step is computable in polynomial time on contexts eCtx.

    Keeping the first two output symbols after appending an optional symbol is computable in polynomial time.