Documentation

CslibFrontier.Computability.BranchingProgram.Space

Native visited-space computations as branching programs (after Arora–Barak Theorem 13.15) #

Every deterministic multi-tape Turing machine running within visited work-tape space s (Turing.MultiTapeTM.RunsInSpace) on inputs of length n for T steps compiles into a deterministic branching program (Turing.MultiTapeTM.toBranchingProgram) over the n input bits. The program is the one of a graph (Turing.MultiTapeTM.spaceConfigGraph) whose nodes (Turing.MultiTapeTM.SpaceConfigNode) are input-independent timed configuration cores:

When the input head lies on the input word (1 ≤ inputPos ≤ n), the node queries input bit inputPos - 1 and transitions to the next timed configuration core on both outcomes; when the input head lies on the left or right boundary blank (0 or n + 1), the transition reads none independently of the input bit. On any input x : Fin n → Bool on which the machine stays within visited space s, evaluating the branching program yields the first output bit of the T-step run (Turing.MultiTapeTM.eval_toBranchingProgram).

Taking T = (n + 2) * storageBound Bool State k s (the configuration-counting halting bound of Turing.MultiTapeTM.haltsAt_le_card) yields the native visited-space version of Arora and Barak, Theorem 13.15 (with the max (S n) 1 zero-space boundary correction): for every problem A ∈ Cslib.Complexity.DSPACE enc S with S n ≥ Nat.log 2 n, there is an explicit constant c (Turing.MultiTapeTM.spaceBranchingProgramBase, depending on the machine's tape count k, state count Fintype.card State, binary work-tape alphabet Bool, and linear space constants c₁, c₂ under enc) such that for every input length n, a branching program of size at most c ^ max (S n) 1 (and at most c ^ S n whenever 1 ≤ S n, in particular for all n ≥ 2 or under the positive logarithmic convention S n ≥ Nat.log 2 n + 1) computes the length-n slice of A (Cslib.Complexity.DSPACE.exists_branchingProgram_of_log_le, Cslib.Complexity.DSPACE.exists_branchingProgram_of_log_add_one_le, Cslib.Complexity.DSPACE.exists_branchingProgram_slice).

Boundary at n = 1, S(1) = 0. The exponent max (S n) 1 (or the positiveness condition 1 ≤ S n) is necessary when S n = 0: at n = 1, Nat.log 2 1 = 0, so S(n) = ⌈log₂ n⌉ satisfies S(1) = 0 ≥ log₂ 1, whereas FirstBit = {x | x₁ = 1} ∈ DSPACE 0 is nonconstant on {0, 1}¹ and requires at least 3 > 1 = c ^ S(1) branching-program nodes (one query node and two distinct sinks) for every base c > 1.

Space-measure qualification. Space in Cslib.Complexity.DSPACE counts distinct visited work-tape cells (Turing.MultiTapeNTM.RunPath.space), the library's native convention, whereas Arora and Barak's draft counts ever-nonblank cells (a weaker premise when a machine scans blank cells without writing, so the draft's ever-nonblank SPACE(S(n)) convention remains an open model difference).

Main definitions #

Main results #

References #

def Turing.Storage.init {k : ℕ} {Symbol : Type u_1} {State : Type u_2} (q₀ : State) :
Storage Symbol State k

The initial storage of a machine starting in state q₀: all work tapes blank and all work heads at 0.

def Turing.Storage.ofBounded {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {w : Fin k → ℕ} :
BoundedStorage Symbol State w → Storage Symbol State k

Reconstruct a Storage from a BoundedStorage on windows w, padding cells outside [-(w j), w j] with none.

theorem Turing.Storage.ofBounded_toBounded {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {x : Storage Symbol State k} {w : Fin k → ℕ} (hx : x.FitsIn w) :

Reconstructing a storage that fits in the windows w from its bounded restriction recovers the original storage.

theorem Turing.Storage.fitsIn_init {k : ℕ} {Symbol : Type u_1} {State : Type u_2} (q₀ : State) (w : Fin k → ℕ) :
(init q₀).FitsIn w

The initial storage fits in every window w.

def Turing.Action.applyStorage {k : ℕ} {Symbol : Type u_1} {State : Type u_2} (action : Action k Symbol State) (st : Storage Symbol State k) :
Storage Symbol State k

The effect of a machine Action on the state and work-tape Storage.

@[simp]
theorem Turing.Action.storage_apply {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {input : List Symbol} (action : Action k Symbol State) (cfg : Cfg k Symbol State input) :
(action.apply cfg).storage = action.applyStorage cfg.storage
theorem Turing.MultiTapeTM.fitsIn_runFrom {k : ℕ} {Symbol : Type u_1} {State : Type u_2} {tm : MultiTapeTM k Symbol State} {input : List Symbol} {s : ℕ} (hs : tm.RunsInSpace input s) (t : ℕ) :
(runFrom (tm.initCfg input) t).storage.FitsIn fun (x : Fin k) => s

Along a space-s run on input, the storage at every step t fits in the uniform per-tape window fun _ => s.

Timed configuration cores and branching-program compilation #

structure Turing.MultiTapeTM.SpaceConfigNode (k : ℕ) (State : Type u_3) (n s T : ℕ) :
Type u_3

A timed configuration core of a k-tape binary machine with state type State, for inputs of length n, work-tape window s, and step horizon T. Its fields are independent of the input word x : Fin n → Bool.

  • step : Fin (T + 1)

    The current step counter (0 ≤ step ≤ T), providing the topological rank T - step.

  • inputPos : Fin (n + 2)

    The input-head position (0 and n + 1 are the left and right boundary blanks).

  • storage : BoundedStorage Bool State fun (x : Fin k) => s

    The control state and work-tape configuration restricted to [-s, s] on each tape.

  • firstOutput : Option Bool

    The first output symbol emitted so far, if any.

Instances For
    theorem Turing.MultiTapeTM.SpaceConfigNode.ext_iff {k : ℕ} {State : Type u_3} {n s T : ℕ} {x y : SpaceConfigNode k State n s T} :
    theorem Turing.MultiTapeTM.SpaceConfigNode.ext {k : ℕ} {State : Type u_3} {n s T : ℕ} {x y : SpaceConfigNode k State n s T} (step : x.step = y.step) (inputPos : x.inputPos = y.inputPos) (storage : x.storage = y.storage) (firstOutput : x.firstOutput = y.firstOutput) :
    x = y
    def Turing.MultiTapeTM.SpaceConfigNode.equivProd (k : ℕ) (State : Type u_3) (n s T : ℕ) :
    SpaceConfigNode k State n s T ≃ Fin (T + 1) × Fin (n + 2) × (BoundedStorage Bool State fun (x : Fin k) => s) × Option Bool

    Equivalence between SpaceConfigNode and the product of its four fields.

    @[instance_reducible]
    instance Turing.MultiTapeTM.SpaceConfigNode.instFintype {k : ℕ} {State : Type u_2} {n s T : ℕ} [Fintype State] :
    Fintype (SpaceConfigNode k State n s T)
    theorem Turing.MultiTapeTM.SpaceConfigNode.card_eq {k : ℕ} {State : Type u_2} {n s T : ℕ} [Fintype State] :
    Fintype.card (SpaceConfigNode k State n s T) = (T + 1) * (n + 2) * Fintype.card (BoundedStorage Bool State fun (x : Fin k) => s) * 3
    def Turing.MultiTapeTM.SpaceConfigNode.init {k : ℕ} {State : Type u_2} (tm : MultiTapeTM k Bool State) (n s T : ℕ) :
    SpaceConfigNode k State n s T

    The initial timed configuration core at step 0.

    noncomputable def Turing.MultiTapeTM.SpaceConfigNode.stepNode {k : ℕ} {State : Type u_2} {n s T : ℕ} (tm : MultiTapeTM k Bool State) (v : SpaceConfigNode k State n s T) (inp : Option Bool) (ht : ↑v.step < T) :
    SpaceConfigNode k State n s T

    Advance a timed configuration core by one step of tm on reading inp : Option Bool under the input head.

    noncomputable def Turing.MultiTapeTM.SpaceConfigNode.ofCfg {k : ℕ} {State : Type u_2} {n T : ℕ} {x : Fin n → Bool} (s : ℕ) (t : Fin (T + 1)) (c : Cfg k Bool State (List.ofFn x)) :
    SpaceConfigNode k State n s T

    The timed configuration core extracted from a machine configuration c at step t.

    theorem Turing.MultiTapeTM.SpaceConfigNode.stepNode_ofCfg {k : ℕ} {State : Type u_2} {n s T : ℕ} {tm : MultiTapeTM k Bool State} {x : Fin n → Bool} {t : Fin (T + 1)} {c : Cfg k Bool State (List.ofFn x)} (ht : ↑t < T) (hc : c.storage.FitsIn fun (x : Fin k) => s) :
    stepNode tm (ofCfg s t c) c.inputSymbol ht = ofCfg s ⟨↑t + 1, ⋯⟩ (MultiTapeTM.step c)

    When the configuration c fits in the uniform window [-s, s], stepNode on c.inputSymbol advances ofCfg s t c to ofCfg s (t + 1) (tm.step c).

    noncomputable def Turing.MultiTapeTM.spaceConfigGraph {k : ℕ} {State : Type u_2} (tm : MultiTapeTM k Bool State) (n s T : ℕ) :

    The graph on timed configuration cores, over inputs Fin n → Bool, that simulates T steps of tm within work-tape window s. Its rank is the number T - v.step.val of remaining steps.

    noncomputable def Turing.MultiTapeTM.toBranchingProgram {k : ℕ} {State : Type u_2} [Fintype State] (tm : MultiTapeTM k Bool State) (n s T : ℕ) :

    The deterministic branching program over Fin n → Bool that simulates T steps of tm within work-tape window s: the program of tm.spaceConfigGraph n s T, with one node for each timed configuration core.

    theorem Turing.MultiTapeTM.evalNode_spaceConfigGraph_ofCfg {k : ℕ} {State : Type u_2} [Fintype State] {tm : MultiTapeTM k Bool State} {n s T : ℕ} (hn : 0 < n) {x : Fin n → Bool} (hs : tm.RunsInSpace (List.ofFn x) s) (rem : ℕ) (t : Fin (T + 1)) :
    T - ↑t = rem → (tm.spaceConfigGraph n s T).evalNode x (SpaceConfigNode.ofCfg s t (runFrom (tm.initCfg (List.ofFn x)) ↑t)) = (runFrom (tm.initCfg (List.ofFn x)) T).output.head?.getD false

    From the node of the t-th configuration on an input x (for 0 < n), the graph tm.spaceConfigGraph n s T reaches the first output bit of the T-step configuration.

    theorem Turing.MultiTapeTM.eval_toBranchingProgram {k : ℕ} {State : Type u_2} [Fintype State] {tm : MultiTapeTM k Bool State} {n s T : ℕ} {x : Fin n → Bool} (hs : tm.RunsInSpace (List.ofFn x) s) :

    Correctness of the branching-program compiler: on every input x : Fin n → Bool on which tm runs within space s, tm.toBranchingProgram n s T evaluates to the first output bit of the T-step run of tm on List.ofFn x.

    Explicit node-count bounds (2 ^ O(S)) #

    def Turing.MultiTapeTM.spaceBranchingProgramBase (k : ℕ) (State : Type u_3) [Fintype State] (c₁ c₂ : ℕ) :

    The explicit base c of the exponential size bound c ^ S n for the branching programs simulating a k-tape deterministic machine with state type State running within space c₁ * S n + c₂ on inputs of length n. It depends on the tape count k, the state count Fintype.card State, the fixed binary work-tape alphabet Bool (via storageBoundBase and storageBoundExp), and the linear space constants c₁, c₂.

    theorem Turing.MultiTapeTM.two_le_spaceBranchingProgramBase {k : ℕ} {State : Type u_2} [Fintype State] (c₁ c₂ : ℕ) :
    2 ≤ spaceBranchingProgramBase k State c₁ c₂

    The branching-program size base spaceBranchingProgramBase k State c₁ c₂ is at least 2.

    theorem Turing.MultiTapeTM.size_toBranchingProgram_le_pow_max {k : ℕ} {State : Type u_2} [Fintype State] (tm : MultiTapeTM k Bool State) {n s S c₁ c₂ : ℕ} (hs : s ≤ c₁ * S + c₂) (hlog : Nat.log 2 n ≤ S) :
    (tm.toBranchingProgram n s ((n + 2) * storageBound Bool State k s)).size ≤ spaceBranchingProgramBase k State c₁ c₂ ^ max S 1

    For s ≤ c₁ * S + c₂ and Nat.log 2 n ≤ S, the branching program simulating tm up to the configuration-counting step bound T = (n + 2) * storageBound Bool State k s has size at most (spaceBranchingProgramBase k State c₁ c₂) ^ max S 1.

    theorem Turing.MultiTapeTM.size_toBranchingProgram_le_pow {k : ℕ} {State : Type u_2} [Fintype State] (tm : MultiTapeTM k Bool State) {n s S c₁ c₂ : ℕ} (hs : s ≤ c₁ * S + c₂) (hlog : Nat.log 2 n ≤ S) (hS : 1 ≤ S) :
    (tm.toBranchingProgram n s ((n + 2) * storageBound Bool State k s)).size ≤ spaceBranchingProgramBase k State c₁ c₂ ^ S

    When 1 ≤ S (in particular for n ≥ 2 or when S ≥ Nat.log 2 n + 1), the size of the branching program is at most (spaceBranchingProgramBase k State c₁ c₂) ^ S.

    Native visited-space branching-program simulation (after Arora–Barak Theorem 13.15) #

    theorem Cslib.Complexity.DSPACE.exists_branchingProgram_of_log_le {α : Type} {enc : α ↪ List Bool} {A : Set α} {S : ℕ → ℕ} (hA : A ∈ DSPACE enc S) (hS : ∀ (n : ℕ), Nat.log 2 n ≤ S n) :
    ∃ c ≥ 2, ∀ (n : ℕ), ∃ (P : BranchingPrograms.BranchingProgram (Fin n) Bool), P.size ≤ c ^ max (S n) 1 ∧ (∀ x ∈ Language.encodes enc n, P.eval x = Language.encodesMember enc A n x) ∧ ∀ (a : α) (h : (enc a).length = n), (P.eval fun (i : Fin n) => (enc a)[↑i]) = Turing.MultiTapeTM.indicator A a

    Native visited-space branching-program simulation (after Arora–Barak Theorem 13.15, general S n ≥ Nat.log 2 n form). For every problem A ∈ DSPACE enc S (where DSPACE measures distinct visited work-tape cells) with ∀ n, Nat.log 2 n ≤ S n, there is a constant c ≥ 2 (depending on the deciding machine's tape count, state count, binary work-tape alphabet Bool, and linear space constants under enc) such that for every input length n, there is a deterministic branching program P : BranchingProgram (Fin n) Bool of size at most c ^ max (S n) 1 (hence ≤ c ^ S n whenever 1 ≤ S n, and ≤ c ^ (S n + 1) for all n) that computes encodesMember enc A n on all encoded instances of length n. The max (S n) 1 floor is needed at n = 1, S 1 = 0, where a nonconstant 1-bit language in DSPACE 0 requires at least 3 > 1 = c ^ 0 nodes.

    theorem Cslib.Complexity.DSPACE.exists_branchingProgram {α : Type} {enc : α ↪ List Bool} {A : Set α} {S : ℕ → ℕ} (hA : A ∈ DSPACE enc S) (hS : ∀ (n : ℕ), Nat.log 2 n ≤ S n) (hpos : ∀ (n : ℕ), 1 ≤ S n) :
    ∃ c ≥ 2, ∀ (n : ℕ), ∃ (P : BranchingPrograms.BranchingProgram (Fin n) Bool), P.size ≤ c ^ S n ∧ (∀ x ∈ Language.encodes enc n, P.eval x = Language.encodesMember enc A n x) ∧ ∀ (a : α) (h : (enc a).length = n), (P.eval fun (i : Fin n) => (enc a)[↑i]) = Turing.MultiTapeTM.indicator A a

    Native visited-space branching-program simulation (after Arora–Barak Theorem 13.15, c ^ S n form for positive space bounds S n ≥ 1). When ∀ n, Nat.log 2 n ≤ S n and ∀ n, 1 ≤ S n (in particular under the repository's standard logarithmic convention S n ≥ Nat.log 2 n + 1), every length-n slice of A ∈ DSPACE enc S is computed on encoded instances by a branching program of size at most c ^ S n.

    theorem Cslib.Complexity.DSPACE.exists_branchingProgram_of_log_add_one_le {α : Type} {enc : α ↪ List Bool} {A : Set α} {S : ℕ → ℕ} (hA : A ∈ DSPACE enc S) (hS : ∀ (n : ℕ), Nat.log 2 n + 1 ≤ S n) :
    ∃ c ≥ 2, ∀ (n : ℕ), ∃ (P : BranchingPrograms.BranchingProgram (Fin n) Bool), P.size ≤ c ^ S n ∧ (∀ x ∈ Language.encodes enc n, P.eval x = Language.encodesMember enc A n x) ∧ ∀ (a : α) (h : (enc a).length = n), (P.eval fun (i : Fin n) => (enc a)[↑i]) = Turing.MultiTapeTM.indicator A a

    Native visited-space branching-program simulation (after Arora–Barak Theorem 13.15) under S n ≥ Nat.log 2 n + 1.

    theorem Cslib.Complexity.DSPACE.exists_branchingProgram_slice {S : ℕ → ℕ} {L : Language Bool} (hL : L ∈ DSPACE Turing.MultiTapeTM.encBits S) (hS : ∀ (n : ℕ), Nat.log 2 n ≤ S n) :
    ∃ c ≥ 2, ∀ (n : ℕ), ∃ (P : BranchingPrograms.BranchingProgram (Fin n) Bool), P.size ≤ c ^ max (S n) 1 ∧ P.eval = L.slice n

    Native visited-space branching-program simulation (after Arora–Barak Theorem 13.15) for boolean languages (enc = encBits). For every language L ∈ DSPACE encBits S with ∀ n, Nat.log 2 n ≤ S n, there is a constant c ≥ 2 such that for every n, the slice L.slice n : (Fin n → Bool) → Bool is computed on all 2 ^ n inputs by a deterministic branching program of size at most c ^ max (S n) 1 (and at most c ^ S n whenever 1 ≤ S n).

    theorem Cslib.Complexity.L.exists_branchingProgram {α : Type} {enc : α ↪ List Bool} {A : Set α} (hA : A ∈ L enc) :
    ∃ c ≥ 2, ∀ (n : ℕ), ∃ (P : BranchingPrograms.BranchingProgram (Fin n) Bool), P.size ≤ c ^ (Nat.log 2 n + 1) ∧ (∀ x ∈ Language.encodes enc n, P.eval x = Language.encodesMember enc A n x) ∧ ∀ (a : α) (h : (enc a).length = n), (P.eval fun (i : Fin n) => (enc a)[↑i]) = Turing.MultiTapeTM.indicator A a

    Native deterministic logarithmic space L has polynomial-size branching programs of size at most c ^ (Nat.log 2 n + 1) at every input length n (via the visited-space simulation after Arora–Barak Theorem 13.15).

    For a boolean language L₀ ∈ L encBits, every length-n slice L₀.slice n has a deterministic branching program of size at most c ^ (Nat.log 2 n + 1) (under native visited logarithmic space).