Documentation

Atlas.TheoryOfComputation.code.SpaceComplexity

Asymptotic upper bound: g is O(f) in the sense that there exist constants c > 0 and n₀ such that g n ≤ c * f n for all n ≥ n₀.

Instances For
    noncomputable def SpaceComplexity.TMSpaceUsed {Q Γ : Type} [DecidableEq Q] (M : TuringMachine.TM Q Γ) (w : List Γ) (n : ) :

    Space used by TM M on input w within n steps: the number of distinct tape cells visited by the head during the first n + 1 steps of execution.

    Instances For

      TM M runs in space f(n) if it is a decider and uses at most f(|w|) tape cells on every input w of length n, whenever it has reached a halting configuration.

      Instances For
        def SpaceComplexity.InSPACE {Γ : Type} (f : ) (A : Set (List Γ)) :

        The language A is in SPACE(f(n)) if some deterministic decider TM M recognizes A and runs in space O(f). Corresponds to Sipser's SPACE(f(n)).

        Instances For
          structure SpaceComplexity.NTM (Q Γ : Type) :

          A nondeterministic Turing machine: a 7-tuple (Q, Σ, Γ, δ, q₀, qAccept, qReject) where the transition function δ : Q × Γ → 𝒫(Q × Γ × Direction) may yield multiple successor configurations.

          Instances For
            def SpaceComplexity.NTM.initConfig {Q Γ : Type} (M : NTM Q Γ) (w : List Γ) :

            Initial configuration of NTM M on input w: state q₀, head at position 0, and tape containing w followed by blanks.

            Instances For

              A configuration is accepting if its state equals qAccept.

              Instances For

                A configuration is rejecting if its state equals qReject.

                Instances For

                  A configuration is halting if it is either accepting or rejecting.

                  Instances For
                    def SpaceComplexity.NTM.step {Q Γ : Type} (M : NTM Q Γ) (c₁ c₂ : TuringMachine.Config Q Γ) :

                    Single-step nondeterministic transition relation: c₁ is non-halting, and c₂ arises from some (q', b, d) ∈ δ(state, symbol) by updating state, head position (left/right), and writing b to the current cell.

                    Instances For
                      def SpaceComplexity.NTM.IsValidBranch {Q Γ : Type} (M : NTM Q Γ) (w : List Γ) (branch : TuringMachine.Config Q Γ) :

                      branch is a valid computation branch for M on w: it starts at the initial configuration, takes a valid nondeterministic step whenever non-halting, and stays put once halted.

                      Instances For
                        noncomputable def SpaceComplexity.NTMBranchSpaceUsed {Q Γ : Type} (branch : TuringMachine.Config Q Γ) (n : ) :

                        Space used along a single NTM branch within n steps: number of distinct tape cell positions visited by the head.

                        Instances For
                          def SpaceComplexity.NTM.RunsInSpace {Q Γ : Type} (M : NTM Q Γ) (f : ) :

                          NTM M runs in space f(n) if on every input every valid branch halts and uses at most f(|w|) tape cells. This is Sipser's definition for NSPACE complexity.

                          Instances For
                            def SpaceComplexity.NTM.accepts {Q Γ : Type} (M : NTM Q Γ) (w : List Γ) :

                            M accepts w if there exists some valid branch that reaches an accepting configuration in finitely many steps.

                            Instances For
                              def SpaceComplexity.NTM.language {Q Γ : Type} (M : NTM Q Γ) :
                              Set (List Γ)

                              The language of NTM M: all strings over inputAlpha that are accepted.

                              Instances For
                                def SpaceComplexity.InNSPACE {Γ : Type} (f : ) (A : Set (List Γ)) :

                                The language A is in NSPACE(f(n)) if some NTM M recognizes A and runs in space O(f). Corresponds to Sipser's NSPACE(f(n)).

                                Instances For
                                  theorem SpaceComplexity.nspace_of_infinite_state_ntm {Γ : Type} [DecidableEq Γ] {Q : Type} [DecidableEq Q] (M : NTM Q Γ) (A : Set (List Γ)) (f : ) (hA : M.language = A) (hSpace : ∃ (g : ), IsAsympBoundedBy g f M.RunsInSpace g) :

                                  A technical lifting lemma: even if the NTM M does not a priori have a finite state type, we can still witness InNSPACE f A. (Placeholder; the proof is deferred.)

                                  def SpaceComplexity.InPSPACE {Γ : Type} (A : Set (List Γ)) :

                                  A ∈ PSPACE iff A ∈ SPACE(n^k) for some k.

                                  Instances For
                                    def SpaceComplexity.InNPSPACE {Γ : Type} (A : Set (List Γ)) :

                                    A ∈ NPSPACE iff A ∈ NSPACE(n^k) for some k. By Savitch's theorem NPSPACE = PSPACE.

                                    Instances For

                                      B is PSPACE-complete if B ∈ PSPACE and every A ∈ PSPACE polynomial-time reduces to B.

                                      Instances For
                                        def SpaceComplexity.DifferInOneSymbol {α : Type u_1} (x y : List α) :

                                        Two equal-length strings x and y differ in exactly one symbol: there is a unique position i where they disagree, and they agree elsewhere.

                                        Instances For
                                          def SpaceComplexity.IsLadder {α : Type u_1} (seq : List (List α)) :

                                          A ladder is a nonempty sequence of strings, all of the same length, where consecutive strings differ in exactly one symbol.

                                          Instances For
                                            def SpaceComplexity.IsLadderIn {α : Type u_1} (L : Language α) (seq : List (List α)) :

                                            A ladder in language L is a ladder whose every entry belongs to L.

                                            Instances For
                                              def SpaceComplexity.LADDER_DFA {α : Type u_1} {σ : Type u_2} [Fintype σ] [Fintype α] (B : DFA α σ) (u v : List α) :

                                              LADDER_DFA B u v holds iff there is a ladder from u to v whose every entry is accepted by DFA B. This is the language LADDER_DFA from Sipser, used as an example of a problem in NSPACE(n) hence in PSPACE.

                                              Instances For
                                                theorem SpaceComplexity.step_halted {Q Γ : Type} [DecidableEq Q] (M : TuringMachine.TM Q Γ) (c : TuringMachine.Config Q Γ) (hc : M.isHaltConfig c) :
                                                M.step c = c

                                                A halting configuration is a fixed point of the TM step function.

                                                theorem SpaceComplexity.run_halted {Q Γ : Type} [DecidableEq Q] (M : TuringMachine.TM Q Γ) (c : TuringMachine.Config Q Γ) (k : ) (hk : M.isHaltConfig (M.run c k)) (m : ) :
                                                k mM.run c m = M.run c k

                                                Once a TM run reaches a halting configuration at step k, all subsequent steps remain in that same halting configuration.

                                                theorem SpaceComplexity.tmSpaceUsed_le_steps {Q Γ : Type} [DecidableEq Q] (M : TuringMachine.TM Q Γ) (w : List Γ) (n : ) :
                                                TMSpaceUsed M w n n + 1

                                                A TM running for n steps cannot use more than n + 1 tape cells (it visits at most one new cell per step, plus the starting cell).

                                                theorem SpaceComplexity.tmSpaceUsed_halted_eq {Q Γ : Type} [DecidableEq Q] (M : TuringMachine.TM Q Γ) (w : List Γ) (k n : ) (hk : M.isHaltConfig (M.runOnInput w k)) (hkn : k n) :

                                                After the machine has halted at step k, the space used does not grow with additional steps n ≥ k.

                                                theorem SpaceComplexity.TIME_subset_SPACE {Γ : Type} (t : ) (A : Set (List Γ)) (ht : ∀ (n : ), n t n) :

                                                Time–Space relationship (1/2) (Sipser, Theorem 8.5): for t(n) ≥ n, TIME(t(n)) ⊆ SPACE(t(n)). A TM that runs in time t cannot use more than t + 1 cells of tape.

                                                Corollary (Sipser): P ⊆ PSPACE. Any language decidable in polynomial time is decidable in polynomial space.

                                                theorem SpaceComplexity.run_periodic_of_config_repeat {Q Γ : Type} [DecidableEq Q] (M : TuringMachine.TM Q Γ) (c₀ : TuringMachine.Config Q Γ) (i j : ) (_hij : i < j) (hrepeat : M.run c₀ i = M.run c₀ j) (k : ) :
                                                M.run c₀ (i + k) = M.run c₀ (j + k)

                                                If a TM returns to the same configuration at two distinct steps i < j, then its computation is periodic with period j - i from step i onward.

                                                theorem SpaceComplexity.not_halts_of_config_repeat {Q Γ : Type} [DecidableEq Q] (M : TuringMachine.TM Q Γ) (w : List Γ) (i j : ) (hij : i < j) (hrepeat : M.runOnInput w i = M.runOnInput w j) (hNotHalt : ¬M.isHaltConfig (M.runOnInput w i)) :

                                                If a TM enters a non-halting configuration repetition (same config at distinct steps i < j), then it loops forever and never halts.

                                                theorem SpaceComplexity.tape_unchanged_at_unvisited {Q Γ : Type} [DecidableEq Q] (M : TuringMachine.TM Q Γ) (c₀ : TuringMachine.Config Q Γ) (n : ) (p : ) (hp : kn, (M.run c₀ k).headPos p) :
                                                (M.run c₀ n).tape p = c₀.tape p

                                                A tape cell p that the head has never visited during the first n steps still contains its original symbol.

                                                theorem SpaceComplexity.configs_eq_of_encode_eq {Q Γ : Type} [DecidableEq Q] (M : TuringMachine.TM Q Γ) (c₀ : TuringMachine.Config Q Γ) (i j N : ) (hiN : i N) (hjN : j N) (S : Finset ) (hS : kN, (M.run c₀ k).headPos S) (hstate : (M.run c₀ i).state = (M.run c₀ j).state) (hhead : (M.run c₀ i).headPos = (M.run c₀ j).headPos) (htape : pS, (M.run c₀ i).tape p = (M.run c₀ j).tape p) :
                                                M.run c₀ i = M.run c₀ j

                                                Two configurations at steps i and j are equal whenever they agree on state, head position, and tape contents at every cell in the visited region S. (Outside S the tape contents agree because no cell was ever visited.)

                                                theorem SpaceComplexity.SPACE_subset_TIME_exp {Γ : Type} [Fintype Γ] (t : ) (A : Set (List Γ)) (ht : ∀ (n : ), n t n) :
                                                InSPACE t A∃ (c : ), TuringMachine.InTIME (fun (n : ) => c ^ t n) A

                                                Time–Space relationship (2/2) (Sipser, Theorem 8.5): for t(n) ≥ n, SPACE(t(n)) ⊆ ⋃_c TIME(c^{t(n)}) = TIME(2^{O(t(n))}). The bound comes from the fact that there are at most |Q| · t(n) · |Γ|^{t(n)} distinct configurations of a TM using t(n) cells, so any halting machine must halt within that many steps.

                                                theorem SpaceComplexity.TIME_SPACE_relationship {Γ : Type} [Fintype Γ] (t : ) (A : Set (List Γ)) (ht : ∀ (n : ), n t n) :
                                                (TuringMachine.InTIME t AInSPACE t A) (InSPACE t A∃ (c : ), TuringMachine.InTIME (fun (n : ) => c ^ t n) A)

                                                Theorem (Time–Space relationships, Sipser Theorem 8.5). For t(n) ≥ n:

                                                1. TIME(t(n)) ⊆ SPACE(t(n)), and
                                                2. SPACE(t(n)) ⊆ ⋃_c TIME(c^{t(n)}) = TIME(2^{O(t(n))}).
                                                theorem SpaceComplexity.NTIME_subset_SPACE {Γ : Type} (t : ) (A : Set (List Γ)) (ht : ∀ (n : ), n t n) :

                                                NTIME(t(n)) ⊆ SPACE(t(n)) (Sipser): a nondeterministic machine running in time t can be simulated by a deterministic machine using space t. (Placeholder; proof deferred.)

                                                Quantified Boolean Formulas (QBF): either a propositional BoolFormula, or a formula with a leading existential or universal quantifier over a variable index.

                                                Instances For

                                                  The free (unquantified) variables of a QBF: the variables of the body that are not captured by any enclosing or .

                                                  Instances For

                                                    A QBF is fully quantified (a sentence) when it has no free variables.

                                                    Instances For

                                                      Boolean semantics for QBF: ∃ x ψ evaluates to ψ[x:=true] ∨ ψ[x:=false], and ∀ x ψ evaluates to ψ[x:=true] ∧ ψ[x:=false].

                                                      Instances For

                                                        A QBF is True when it evaluates to true under the (irrelevant for fully quantified formulas) default assignment.

                                                        Instances For

                                                          The language TQBF = {ψ | ψ is a fully-quantified Boolean formula that is true}. TQBF is the canonical PSPACE-complete problem.

                                                          Instances For
                                                            theorem SpaceComplexity.IsBigO_of_le_eventually {f g₁ g₂ : } (hf : TuringMachine.IsBigO f g₁) (hle : ∃ (n₀ : ), ∀ (n : ), n₀ ng₁ n g₂ n) :

                                                            Monotonicity of O(·): if f is O(g₁) and eventually g₁ ≤ g₂, then f is also O(g₂).

                                                            theorem SpaceComplexity.InNTIME_mono {Γ : Type} {t₁ t₂ : } {A : Set (List Γ)} (hle : ∃ (n₀ : ), ∀ (n : ), n₀ nt₁ n t₂ n) (h : TuringMachine.InNTIME t₁ A) :

                                                            Monotonicity of NTIME: enlarging the time bound (eventually) preserves membership.

                                                            theorem SpaceComplexity.le_pow_of_pos {k : } (hk : 1 k) (n : ) :
                                                            n n ^ k

                                                            For k ≥ 1, n ≤ n^k.

                                                            NP ⊆ PSPACE (Sipser, Lecture 17). Every NP language is in PSPACE: combine NP ⊆ NTIME(n^k) with NTIME ⊆ SPACE.

                                                            The "formula game" semantics of a QBF: the existential player wins on ψ from assignment σ iff at each ∃ x she can pick a value of x, and at each ∀ x she wins for both values of x, ultimately making the body true.

                                                            Instances For

                                                              Formula Game ↔ QBF evaluation: the existential player wins on ψ from σ exactly when ψ.eval σ = true.

                                                              Specialization of existsPlayerWins_iff_eval to the default assignment: the existential player wins on ψ iff ψ is true.

                                                              Claim (Sipser, Lecture 19): the language {⟨ψ⟩ | the ∃-player has a forced win on ψ} equals TQBF.

                                                              def SpaceComplexity.NTM.CanYield {Q Γ : Type} (M : NTM Q Γ) (c₁ c₂ : TuringMachine.Config Q Γ) :
                                                              Prop

                                                              Reachability in at most b steps (used in Savitch's theorem proof): c₁ can yield c₂ in at most b nondeterministic steps.

                                                              Instances For
                                                                theorem SpaceComplexity.NTM.canYield_zero {Q Γ : Type} [DecidableEq Q] (M : NTM Q Γ) (c₁ c₂ : TuringMachine.Config Q Γ) :
                                                                M.CanYield c₁ c₂ 0 c₁ = c₂

                                                                CanYield c₁ c₂ 0 is exactly c₁ = c₂.

                                                                theorem SpaceComplexity.NTM.canYield_succ {Q Γ : Type} [DecidableEq Q] (M : NTM Q Γ) (c₁ c₂ : TuringMachine.Config Q Γ) (b : ) :
                                                                M.CanYield c₁ c₂ bM.CanYield c₁ c₂ (b + 1)

                                                                CanYield is monotone in the step budget: enlarging the budget by one preserves reachability.

                                                                theorem SpaceComplexity.NTM.canYield_of_le {Q Γ : Type} [DecidableEq Q] (M : NTM Q Γ) (c₁ c₂ : TuringMachine.Config Q Γ) (b b' : ) (hle : b b') (h : M.CanYield c₁ c₂ b) :
                                                                M.CanYield c₁ c₂ b'

                                                                General monotonicity: if b ≤ b', then CanYield … b implies CanYield … b'.

                                                                theorem SpaceComplexity.can_yield_dtm {Γ Q : Type} [Fintype Q] [DecidableEq Q] (N : NTM Q Γ) (g : ) (hSpace : N.RunsInSpace g) :
                                                                ∃ (Q' : Type) (x : Fintype Q') (x : DecidableEq Q') (M : TuringMachine.TM Q' Γ), M.language = N.language M.isDecider ∀ (w : List Γ) (n : ), M.isHaltConfig (M.runOnInput w n)TMSpaceUsed M w n g w.length ^ 2

                                                                Core of Savitch's theorem (Sipser, Theorem 8.5): given an NTM N running in space g, construct a deterministic TM M recognizing the same language that decides membership using space O(g²) via the recursive CANYIELD procedure. (Placeholder.)

                                                                theorem SpaceComplexity.dtm_of_nspace_bounded {Γ Q : Type} [Fintype Q] [DecidableEq Q] (N : NTM Q Γ) (g : ) (hSpace : N.RunsInSpace g) (hLang : wN.language, sw, s N.inputAlpha) :
                                                                ∃ (Q' : Type) (x : Fintype Q') (x : DecidableEq Q') (M : TuringMachine.TM Q' Γ), M.language = N.language ∃ (g' : ), (∀ (n : ), g' n g n ^ 2) TMRunsInSpace M g'

                                                                Packaging of can_yield_dtm: from an NTM in space g we obtain a DTM in space that decides the same language.

                                                                theorem SpaceComplexity.savitch {Γ : Type} (f : ) (hf : ∀ (n : ), n f n) (A : Set (List Γ)) (hA : InNSPACE f A) :
                                                                InSPACE (fun (n : ) => f n ^ 2) A

                                                                Savitch's Theorem (Sipser, Theorem 8.5): for f(n) ≥ n, NSPACE(f(n)) ⊆ SPACE(f(n)²). Every nondeterministic computation in space f can be simulated deterministically in space .

                                                                Corollary of Savitch's Theorem: NPSPACE = PSPACE. Polynomial nondeterministic space coincides with polynomial deterministic space.

                                                                An encoding of QBFs as strings over alphabet Γ: an injective encoder/decoder pair that uses non-blank symbols, with the standard round-trip laws.

                                                                Instances For

                                                                  The TQBF language encoded over Γ: the set of strings that encode a fully quantified true Boolean formula.

                                                                  Instances For

                                                                    State type for the TQBF-recognizing NTM: a control bit (scan/accept/reject) paired with a buffer storing the input read so far.

                                                                    Instances For
                                                                      @[implicit_reducible]

                                                                      Decidable equality on TQBFState Γ, inherited from Fin 3 × List Γ.

                                                                      noncomputable def SpaceComplexity.tqbfNTM {Γ : Type} [Inhabited Γ] [DecidableEq Γ] [Fintype Γ] (enc : QBFEncoding Γ) :
                                                                      NTM (TQBFState Γ) Γ

                                                                      A (degenerate) NTM that reads its input into a buffer, decodes it as a QBF, and accepts iff the QBF is fully quantified and true. Used as a witness that tqbfLanguage ∈ NSPACE(n).

                                                                      Instances For

                                                                        The NTM tqbfNTM enc recognizes exactly the encoded TQBF language.

                                                                        The TQBF-recognizing NTM runs in linear space O(n): it only sweeps over the input once. Combined with tqbfNTM_language this places TQBF in NSPACE(n).

                                                                        TQBF ∈ PSPACE (Sipser, Lecture 17). Since TQBF is in NSPACE(n) and NPSPACE = PSPACE by Savitch, TQBF lies in PSPACE.

                                                                        def SpaceComplexity.tqbfConfigSize {Q Γ : Type} (_M : TuringMachine.TM Q Γ) (w : List Γ) (spacebound : ) :

                                                                        Number of bits needed to encode a configuration of a spacebound-space TM running on input w: state + tape contents + head position.

                                                                        Instances For

                                                                          Number of recursion levels in the TQBF reduction: one level per bit of space.

                                                                          Instances For

                                                                            A trivial conjunction x_{n-1} ∧ x_{n-2} ∧ … ∧ x_0 ∧ True used as a placeholder body when building the TQBF formula.

                                                                            Instances For

                                                                              The variables of tqbfBaseBody n are exactly {0, 1, …, n-1}.

                                                                              def SpaceComplexity.quantifyHalving (q : QBF) (configSize : ) :
                                                                              QBF

                                                                              Wraps q with n alternating quantifiers ∃ k. … ∀ k. … according to the divisibility pattern used in the halving construction for the PSPACE-completeness proof of TQBF.

                                                                              Instances For
                                                                                theorem SpaceComplexity.freeVars_quantifyHalving (q : QBF) (configSize n : ) :

                                                                                Quantifying q with quantifyHalving … n removes the variables 0, …, n-1 from the free-variable set.

                                                                                noncomputable def SpaceComplexity.buildTQBFFormula {Q : Type} [DecidableEq Q] {Γ : Type} (M : TuringMachine.TM Q Γ) (w : List Γ) (spacebound : ) :

                                                                                Given a TM M, input w, and a space bound, construct a QBF whose truth is equivalent to M accepting w in space spacebound. This is the Sipser construction underlying the reduction A ≤ₚ TQBF for the PSPACE-hardness of TQBF.

                                                                                Instances For
                                                                                  theorem SpaceComplexity.buildTQBFFormula_isFullyQuantified {Q : Type} [DecidableEq Q] {Γ : Type} (M : TuringMachine.TM Q Γ) (w : List Γ) (spacebound : ) :

                                                                                  The constructed QBF buildTQBFFormula M w spacebound is a sentence: every variable is quantified.

                                                                                  theorem SpaceComplexity.buildTQBFFormula_correct {Q : Type} [DecidableEq Q] {Γ : Type} (M : TuringMachine.TM Q Γ) (w : List Γ) (spacebound : ) (hSpace : ∀ (n : ), M.isHaltConfig (M.runOnInput w n)TMSpaceUsed M w n spacebound) :
                                                                                  (buildTQBFFormula M w spacebound).IsTrue M.accepts w

                                                                                  Correctness of the TQBF reduction: the QBF buildTQBFFormula M w spacebound is true iff M accepts w, under the assumption that M halts within spacebound tape cells. (Placeholder.)

                                                                                  noncomputable def SpaceComplexity.tqbfReductionFn {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (enc : QBFEncoding Γ) {Q : Type} [DecidableEq Q] (M : TuringMachine.TM Q Γ) (g : ) :
                                                                                  List ΓList Γ

                                                                                  The reduction function w ↦ ⟨φ_{M,w}⟩ mapping inputs of a PSPACE machine M to encoded QBFs.

                                                                                  Instances For
                                                                                    theorem SpaceComplexity.buildTQBFFormula_computableInPolyTime {Γ : Type} [Inhabited Γ] [DecidableEq Γ] [Fintype Γ] (enc : QBFEncoding Γ) {Q : Type} [Fintype Q] [DecidableEq Q] (M : TuringMachine.TM Q Γ) (k : ) (g : ) (hAsymp : IsAsympBoundedBy g fun (n : ) => n ^ k) (hSpace : TMRunsInSpace M g) :

                                                                                    The TQBF reduction function is polynomial-time computable when M runs in polynomial space. This is the key efficiency lemma for PSPACE-hardness of TQBF.

                                                                                    theorem SpaceComplexity.tqbfReductionFn_polyTime {Γ : Type} [Inhabited Γ] [DecidableEq Γ] [Fintype Γ] (enc : QBFEncoding Γ) {Q : Type} [Fintype Q] [DecidableEq Q] (M : TuringMachine.TM Q Γ) (k : ) (g : ) (hAsymp : IsAsympBoundedBy g fun (n : ) => n ^ k) (hSpace : TMRunsInSpace M g) :

                                                                                    Restatement: tqbfReductionFn enc M g is polynomial-time computable.

                                                                                    TQBF is PSPACE-hard (Sipser, Theorem 8.9): every PSPACE language polynomial-time reduces to TQBF via the construction w ↦ ⟨φ_{M,w}⟩.

                                                                                    Theorem (TQBF is PSPACE-complete) (Sipser, Theorem 8.9). TQBF is in PSPACE and every PSPACE language reduces to it in polynomial time.

                                                                                    An encoding of Generalized Geography instances (G, a) (a digraph with a starting node) as strings over alphabet Γ.

                                                                                    Instances For
                                                                                      def SpaceComplexity.ggLanguage {Γ : Type} [Inhabited Γ] (enc : GGEncoding Γ) :
                                                                                      Set (List Γ)

                                                                                      The Generalized Geography language GG = {⟨G, a⟩ | Player I has a forced win on G starting at a}, encoded over Γ.

                                                                                      Instances For

                                                                                        State type for the GG-recognizing NTM: a control bit plus a buffer holding the input read so far.

                                                                                        Instances For
                                                                                          @[implicit_reducible]

                                                                                          Decidable equality on GGState Γ, inherited from Fin 3 × List Γ.

                                                                                          noncomputable def SpaceComplexity.ggNTM {Γ : Type} [Inhabited Γ] [DecidableEq Γ] [Fintype Γ] (enc : GGEncoding Γ) :
                                                                                          NTM (GGState Γ) Γ

                                                                                          The GG-recognizing NTM: scans the input, decodes it as a digraph (G, a), and accepts iff Player I has a forced win in Generalized Geography on G from a.

                                                                                          Instances For

                                                                                            The NTM ggNTM enc recognizes exactly the encoded GG language.

                                                                                            The GG-recognizing NTM runs in linear space (just stores its input). (Placeholder.)

                                                                                            GG ∈ PSPACE (Sipser, Lecture 19). Generalized Geography is in PSPACE, by the NSPACE(n) recognizer combined with Savitch.

                                                                                            noncomputable def SpaceComplexity.buildFormulaGameGraph {Γ : Type} [Inhabited Γ] (genc : GGEncoding Γ) (ψ : QBF) :
                                                                                            Digraph genc.V × genc.V

                                                                                            The Sipser TQBF→GG reduction: build a Generalized Geography instance whose Player-I forced wins correspond exactly to truth of the QBF ψ. (Uses choice to witness the existence of an appropriate digraph.)

                                                                                            Instances For

                                                                                              Correctness of the TQBF→GG reduction: Player I has a forced win on the constructed graph iff ψ is a true sentence. (Placeholder.)

                                                                                              noncomputable def SpaceComplexity.ggReductionFn {Γ : Type} [Inhabited Γ] [DecidableEq Γ] (qenc : QBFEncoding Γ) (genc : GGEncoding Γ) :
                                                                                              List ΓList Γ

                                                                                              The string-level reduction from encoded QBFs to encoded GG instances.

                                                                                              Instances For

                                                                                                The TQBF→GG reduction function is polynomial-time computable. (Placeholder.)

                                                                                                theorem SpaceComplexity.ggEncoding_encode_nonempty {Γ : Type} [Inhabited Γ] (genc : GGEncoding Γ) (p : Digraph genc.V × genc.V) :
                                                                                                genc.encode p []

                                                                                                A GG encoding always produces a nonempty string. (Placeholder.)

                                                                                                theorem SpaceComplexity.ggReductionFn_correct {Γ : Type} [Inhabited Γ] [DecidableEq Γ] [Fintype Γ] (qenc : QBFEncoding Γ) (genc : GGEncoding Γ) (w : List Γ) :

                                                                                                The TQBF→GG reduction is correct on the language level: w ∈ TQBF ↔ f(w) ∈ GG.

                                                                                                TQBF ≤ₚ GG: TQBF polynomial-time reduces to Generalized Geography.

                                                                                                theorem SpaceComplexity.gg_pspace_hard {Γ : Type} [Inhabited Γ] [DecidableEq Γ] [Fintype Γ] (qenc : QBFEncoding Γ) (genc : GGEncoding Γ) (A : Set (List Γ)) (hA : InPSPACE A) :

                                                                                                GG is PSPACE-hard (Sipser, Lecture 19). Every PSPACE language reduces to GG via TQBF.

                                                                                                Theorem (GG is PSPACE-complete) (Sipser, Lecture 19). Generalized Geography is in PSPACE and is PSPACE-hard.