Documentation

CslibFrontier.Computability.Complexity.Classes.Alternation.Savitch

AP = PSPACE #

Savitch's midpoint recursion (Cslib.Reachability.reach) is a game Chandra, Kozen and Stockmeyer: to show that v is reachable from u within 2 ^ (i + 1) steps, the existential player names a midpoint m, the universal player picks one of the two halves, from u to m or from m to v, and the game goes on at level i; at level 0, v must be u or one edge away. With single-bit moves (Cslib.Reachability.midpointGame), a level takes w rounds in which the existential player writes a midpoint of width w (Cslib.Reachability.midpointMoves; the universal player's moves there do not matter) and one round in which the universal player picks the half. The existential player wins the game of 2 * ((w + 1) * i) moves exactly when the recursion holds at level i (Cslib.Reachability.alternation_midpointGame_iff). The winning condition is a loop over the levels (Cslib.Reachability.midpointGame_eq_iterate), polynomial-time in the moves.

A problem in PSPACE is decided by a nondeterministic machine within polynomial space, and acceptance is Savitch's recursion on the codes of its finite views, at depth the width of the codes (Turing.MultiTapeNTM.savitchDecide_eq_true_iff). The midpoint game on these codes (Cslib.Complexity.savitchVerifier) is therefore a polynomial-time game verifier of the problem, once its number of moves is padded to a polynomial in the length of the instance; moves after those of the game do not matter (Cslib.Complexity.alternation_append_iff). The guess-then-verify machine plays the game (Cslib.Complexity.IsGameVerifier.mem_AP), so PSPACE ⊆ AP (Cslib.Complexity.PSPACE_subset_AP). With AP ⊆ PSPACE (Cslib.Complexity.AP_subset_PSPACE), this is AP = PSPACE (Cslib.Complexity.AP_eq_PSPACE) Chandra, Kozen and Stockmeyer Sipser, Section 10.3 Arora and Barak, Section 5.3: the problems with polynomial-time game verifiers are exactly those in PSPACE (Cslib.Complexity.mem_PSPACE_iff_exists_isGameVerifier). Like AP and PSPACE, the statements are relative to the encoding of instances.

The game characterization holds at any space bound: a machine whose reachable views have encodings of at most w bits accepts exactly when the existential player wins the midpoint game of 2 * ((2 * w + 3) * (2 * w + 2)) moves on their codes (Turing.MultiTapeNTM.accepts_iff_alternation_midpointGame), so every problem in NSPACE s is a midpoint game of O((n + s n) ^ 2) moves (Cslib.Complexity.exists_midpointGame_of_mem_NSPACE). This is the game behind NSPACE(s) ⊆ ATIME(s ^ 2) Chandra, Kozen and Stockmeyer; Cslib.Complexity.NSPACE_subset_ATIME_sq_of_timeConstructible plays it within time O((n + s n) ^ 2) for a time-constructible s (#4086 tracks removing time-constructibility).

Main definitions #

Main results #

References #

Blocks of moves #

theorem Cslib.Complexity.alternation_append_iff {q : Bool} {ns ms : List ℕ} {P : List Bool → Prop} (h : ∀ (z : List Bool), P z ↔ P (List.take ns.sum z)) :
Alternation q (ns ++ ms) P ↔ Alternation q ns P

Trailing moves that do not matter. If the predicate only reads the moves of the blocks ns, the further blocks ms do not change the game.

The midpoint game #

The midpoint chosen at a level of the game: the moves of the existential player in its first w rounds.

def Cslib.Reachability.midpointGame (edge : List Bool → List Bool → Bool) (w : ℕ) :
ℕ → List Bool → List Bool → List Bool → Bool

Savitch's midpoint game on words of width w, at level i, between u and v. At level 0 the existential player wins when v is u or one edge away. At level i + 1, in each of w rounds the existential player chooses one bit of a midpoint m, and the universal player's moves do not matter; in one more round the universal player chooses a half, and the game goes on at level i between u and m, or between m and v.

theorem Cslib.Reachability.alternation_midpointGame_iff {edge : List Bool → List Bool → Bool} {w : ℕ} (i : ℕ) (u v : List Bool) :
(Complexity.Alternation true (List.replicate (2 * ((w + 1) * i)) 1) fun (z : List Bool) => midpointGame edge w i u v z = true) ↔ reach edge w i u v = true

Savitch's midpoint game is reachability. The existential player wins the game at level i between u and v, of 2 * ((w + 1) * i) moves, exactly when v is reachable from u by Savitch's midpoint recursion at level i (Cslib.Reachability.reach).

The midpoint game in polynomial time #

One level of the midpoint game on the state (u, v, moves).

theorem Cslib.Reachability.midpointGame_eq_iterate {edge : List Bool → List Bool → Bool} {w : ℕ} (i : ℕ) (u v z : List Bool) :
midpointGame edge w i u v z = reach edge w 0 ((midpointStep w)^[i] (u, v, z)).1 ((midpointStep w)^[i] (u, v, z)).2.1

The midpoint game is a loop of its levels.

Nondeterministic machines as midpoint games #

theorem Turing.MultiTapeNTM.accepts_iff_alternation_midpointGame {k : ℕ} {State : Type} [Finite State] {ntm : MultiTapeNTM k Bool State} {input : List Bool} {w : ℕ} (hw : ∀ (finite : FiniteCfg k Bool State), Relation.ReflTransGen ntm.ViewStep (ntm.initView input) finite → (MultiTapeTM.encFiniteCfg finite).length ≤ w) :
ntm.Accepts input ↔ Cslib.Complexity.Alternation true (List.replicate (2 * ((2 * w + 2 + 1) * (2 * w + 2))) 1) fun (z : List Bool) => Cslib.Reachability.midpointGame ntm.codeEdge (2 * w + 2) (2 * w + 2) (viewCode w (ntm.initView input)) (acceptCode w) z = true

A machine is Savitch's midpoint game on the codes of its views. If every view reachable from the initial view of ntm on input has an encoding of at most w bits, ntm accepts input exactly when the existential player wins the midpoint game on the codes of 2 * w + 2 bits, at depth 2 * w + 2, from the code of the initial view to the accepting code: a game of 2 * ((2 * w + 3) * (2 * w + 2)) single-bit moves.

noncomputable def Cslib.Complexity.savitchVerifier {α : Type} {enc : α ↪ List Bool} {k : ℕ} {State : Type} [Finite State] (ntm : Turing.MultiTapeNTM k Bool State) (c d : ℕ) (x : α × List Bool) :

The verifier of Savitch's midpoint game on the codes of the views of ntm on enc a, from the code of the initial view to the accepting code, at depth the width of the codes.

Every problem in PSPACE has a polynomial-time game verifier: the verifier of Savitch's midpoint game on the codes of the views of a nondeterministic machine deciding it within polynomial space. The game has 2 * ((W + 1) * W) moves for the width W of the codes, padded to a polynomial number.

theorem Cslib.Complexity.PSPACE_subset_AP {α : Type} {enc : α ↪ List Bool} :
PSPACE enc ⊆ AP enc

PSPACE ⊆ AP Chandra, Kozen and Stockmeyer: a problem in PSPACE is Savitch's midpoint game on the views of a machine deciding it, which the guess-then-verify machine plays in polynomial time.

The problems with polynomial-time game verifiers are exactly those in PSPACE.

theorem Cslib.Complexity.exists_midpointGame_of_mem_NSPACE {α : Type} {enc : α ↪ List Bool} {A : Set α} {s : ℕ → ℕ} (h : A ∈ NSPACE enc s) :
∃ (k : ℕ) (State : Type) (x : Finite State) (ntm : Turing.MultiTapeNTM k Bool State) (K : ℕ), ∀ (a : α) (w : ℕ), K * ((enc a).length + s (enc a).length + 1) ≤ w → (a ∈ A ↔ Alternation true (List.replicate (2 * ((2 * w + 2 + 1) * (2 * w + 2))) 1) fun (z : List Bool) => Reachability.midpointGame ntm.codeEdge (2 * w + 2) (2 * w + 2) (Turing.MultiTapeNTM.viewCode w (ntm.initView (enc a))) (Turing.MultiTapeNTM.acceptCode w) z = true)

Every problem in NSPACE s is a midpoint game of O((n + s n) ^ 2) moves on the views of a nondeterministic machine deciding it: for some machine, some constant K and every width w ≥ K * (n + s n + 1), where n is the length of enc a, a ∈ A exactly when the existential player wins Savitch's midpoint game on the codes of 2 * w + 2 bits, at depth 2 * w + 2, from the code of the initial view to the accepting code, a game of 2 * ((2 * w + 3) * (2 * w + 2)) single-bit moves.

This is not NSPACE(s) ⊆ ATIME(s ^ 2) Chandra, Kozen and Stockmeyer; it is the game that the alternating machine of that simulation plays, which Cslib.Complexity.NSPACE_subset_ATIME_sq_of_timeConstructible does within time O((n + s n) ^ 2) for a time-constructible s (#4086). The views record the input, so the width of the codes is linear in n + s n rather than in s n, and the game has O(s n ^ 2) moves only when n = O(s n).