theory-of-computation-note-2

Time complexity·

Definition·

  • Let M be a deterministic Turing machine that halts on all input. The running time or time complexity of MM is the function f:NNf: N\rightarrow N, where f(n)f(n) is the maximum number of steps that MM uses on any input of length nn.

Time complexity class·

  • TIME(t(n)): languages decidable by O(t(n))O(t(n)) time deterministic TM
  • NTIME(t(n)): languages decidable by O(t(n))O(t(n)) time nondeterministic TM
  • image-20220426134109416
  • NP=kNTIME(nk)NP = \cup_k NTIME(n ^ k) 的理解
    • NP 是能在多项式时间内验证答案正确性那么可以用 非确定性图灵机 猜一个答案 然后多项式时间内验证他 猜的时候可以保证如果有答案就能猜到答案 所以 NP \Leftrightarrow NTIME

The Cobham-Edmonds thesis·

  • For any realistic models of computation M1M_1 and M2M_2, M1M_1 can be simulated on M2M_2 with at most polynomial slowdown.
  • 只有多项式复杂度的东西才能够在实际计算机上计算

Space complexity·

Space complexity class·

  • For any function f:NNf:N \rightarrow N, we define:

    • SPACE(f(n)) = { L : L is decidable by a deterministic TM M which scans O(f(n))O(f(n)) tape cells}
    • NSPACE(f(n)) = { L : L is decidable by a non-deterministic TM M which scans O(f(n))O(f(n)) tape cells on any branch of its computation}
    • NTIME(f(n)) 就是说 模拟的步骤 时间是 f(n)
    • NSPACE(f(n)) 就是说 模拟的步骤 空间是 f(n)
  • Example:

    • SAT \in SPACE(n)

      can be solved in linear space

Low Space classes·

  • L = SPACE(logn\log n)
  • NL = NSPACE(logn\log n)
  • PSPACE = k\cup_k SPACE(nkn^k)
  • NPSPACE = k\cup_k NSPACE(nkn^k)

3-TAPE machines·

  • image-20220426135707701
  • Configuration
    • the state O(c)O(c)
    • the content of the work tape O(gf(n))O(g ^ {f(n)})
    • the head position of input tape O(n)O(n)
    • the head position of work tape O(f(n))O(f(n))
    • total number = O(cnf(n)gf(n))=O(n2f(n))O(cnf(n)g^{f(n)}) = O(n\cdot 2^{f(n)})
      • If f(n)=O(logn)f(n) = O(\log n), configuration 的总数 O(n)O(n)
  • 消耗 空间 O(f(n))O(f(n)) 的 图灵机 在 时间 n2O(f(n))n 2 ^ {O(f(n))} 内运行

Some observations·

  • TIME(f(n))SPACE(f(n))TIME(f(n))⊆SPACE(f(n))

    • a machine uses f(n) time can use at most f(n) space
  • SPACE(f(n))TIME(f(n)2O(f(n)))SPACE(f(n))⊆TIME(f(n)·2^{O(f(n))})

    • a machine uses O(f(n))O(f(n)) space can have at most 2O(f(n))2^{O(f(n))} configurations

    • a TM that halts may not repeat a configuration

    • the total time to list all configurations is f(n)2O(f(n))f(n)·2^{O(f(n))}

  • NTIME(f(n))SPACE(f(n))NTIME(f(n)) \subset SPACE(f(n))

    • we can enumerate all O(f(n))O(f(n)) guesses in O(f(n))O(f(n)) space
  • $ L⊆P⊆NP⊆PSPACE=NPSPACE⊆EXPTIME$

NL Completeness·

Log-space reduction·

  • AA is log-space reducible to BB, written ALBA \leq _L B, if there exists a log space TM MM that, given input ww, outputs f(w)f(w) s.t. wAw\in A iff f(w)Bf(w) \in B.

Definition·

  • A language BB is NL-complete if
    • BNLB \in NL
    • ANL,ALB\forall A \in NL, A \leq_L B
  • Thm: If ALBA\leq_L B and BLB \in L, then ALA \in L.
    • 直接考虑 对于 AA 的输入 wwMM 计算 f(w)f(w) 不可行因为虽然计算的过程是 log space 但是输出 f(w)f(w) 可能会很大
    • 我们不计算整个 f(w)f(w)只在 BB 需要用到 f(w)f(w) 的某个 bit 的时候去计算那个字符f(w)f(w) 的长度 is bounded by poly(n) 故我们只要 O(logn)O(\log n) bits.
    • wwf(w)f(w) 和从 f(w)f(w) 到最终的 output 都是 log space输入是 poly(n)poly(n) 所以空间开销是 O(logn)O(\log n)
  • More generally, if ff and gg are log-space computable functions, fgf \circ g is also log-space computable. 就等 g 的结果的第 i 位算出来在用到 f 里面
  • log space 可以让输出和输入的长度是poly关系 在log 意义下同阶

PATHPATH·

  • Graph Connevtivity

    • PATHPATH 有向图两个点 s,ts,t 的连通性
      • in NLNL and in PP
    • USTCONUSTCON 无向图两个点 s,ts,t 的连通性
      • in LL
  • PATHNLPATH \in NL

    • image-20220426140928942
  • PATHPPATH \in P

    • ss 出发 bfs

Savitch’s Theorem·

  • NLSPACE(log2n)NL \subset SPACE(\log ^ 2n)
  • Proof:
    • First prove PATHPATH is NL-complete
    • Then show an algorithm for PATHPATH that uses log2n\log ^ 2 n space

PATHPATH is NL-complete·

  • 已经证明了 PATHNLPATH \in NL下面证明任何 NLNL 都可以对数空间规约到 PATHPATH
  • 对于一个语言 AA存在一个 NTM MMO(logn)O(\log n) 的空间内能 decide AA不妨设 MM 只有一个 accept configuration
  • For input ww, we construct a directed graph $\langle G, s, t\rangle $ in 对数空间内s.t. GG contains a path from ss to tt iff MM accepts ww.
  • MM 的每个 configuration 视作一个节点如果 c1c_1 出发下一个能到 c2c_2那么 (c1,c2)(c_1, c_2)GG 的一条边ss 是一个初始 configurationt 是 accept configuration
  • wwG,s,t\langle G, s, t\rangle 的转换也是 log-space
    • 列举所有的 nodes nodes就对应 configuration 所以是log space
    • For every two nodes, check whether connected 这只需要看一下head指向的位置

NLPNL \subset P·

  • a simple corollary
  • PATHPPATH \in P
  • all NLNL language is log-space reducible to PATHPATH
    • -> all NLNL language is poly-time reducible to PATHPATH
  • any NLNL language is in PP

Then show PATHPATH can be decided by a deterministic TM in O(log2n)O(\log ^ 2n) space·

  • image-20220426154810334
  • S(n)=S(n/2)+O(logn)S(n) = S(n / 2) + O(\log n)

So we have proven NLSPACE(log2n)NL \subset SPACE (\log ^ 2 n)

Padding argument – Example·

  • Claim: If P=NPP = NP, then EXP=NEXPEXP = NEXP.

  • Proof.

    Since EXPNEXPEXP \subset NEXP is by definition, we only need to show NEXPEXPNEXP \subset EXP.

    考虑 NEXPNEXP 中的某个语言 LL存在某个自动机 MM 能够在 2nc{2 ^ {n ^ c}} 的时间内 decide LL. 我们定义

    L={x12xcxL}L' = \left\{x 1 ^ {2 ^ {|x| ^ c}} \mid x \in L\right\}

    其中 1 表示一个不在 LL 中的符号.

    首先我们证明 LL' is in NPNP, 然后我们通过 NP=PNP= P, 我们证明 LL is in EXP.

    首先证明 LL' is in NPNP.

    给定输入 xx' 我们需要判断 xLx' \in L' or not. 我们先看 xx' 的形式. 如果 xx' 符合 LL' 的形式, 就是说存在一个xx, x=x{x12xcxL}x' = x \left\{x 1 ^ {2 ^ {|x| ^ c}} \mid x \in L\right\}, simulate M(x)M(x). 这个 simulation 的时间 是 2xc2 ^ {|x| ^ c}, 关于 xx' 的长度是线性的. 自然也是多项式的. 这整个过程就能 decide xx' is in LL' or not. 并且是 NPNP 的. 因此, LL' is in NPNP.

    由于假设 P=NPP=NP, LL' is in PP. Then, 存在一个确定自动机, 能够在 poly time 内decide LL'. 这个自动机关于 x|x| 的复杂度就是 EXPEXP. 因此 LEXPL \in EXP.

  • padding 指的就是在 xx 后面加许多个 11 的操作. 这有时用于不同复杂度类型的转换.

Savitch’s Theorem ---- Generalized form·

  • Theorem:

    S(n)log(n)\forall S(n) \geq \log (n), NSPACE(S(n))SPACE(S(n)2)NSPACE (S(n)) \subset SPACE(S(n) ^ 2)

  • NLSPACE(log2n)NL \subset SPACE(\log ^ 2 n) 证明

Definition·

  • A function f:NNf: N \rightarrow N, where f(n)lognf(n) \geq \log n, is called space constructable, if the function that maps 1n1 ^ n to the binary representation of f(n)f(n) is computable in space O(f(n))O(f(n)).

  • A function f:NNf: N \rightarrow N, where f(n)nlognf(n) \geq n \log n, is called time constructable if the function that maps 1n1^n to the binary representation of f(n)f(n) is computable in time O(f(n))O(f(n)).

  • All commonly used functions are space/time constructable.

Claim·

  • For any two space constructable functions s1(n),s2(n)logn,f(n)ns_1(n), s_2(n) \geq \log n, f(n) \geq n:

    NSPACE(s1(n))SPACE(s2(n))NSPACE(s_1(n)) \subset SPACE(s_2(n)) can derive that NSPACE(s1(f(n)))SPACE(s2(f(n)))NSPACE(s_1(f(n))) \subset SPACE(s_2(f(n)))

Proof·

我们也用 padding 的方式去证明 Savitch’s Theorem.

假设 LNSPACE(s1(f(n)))L \in NSPACE(s_1(f(n)))

就是有一个 s1(f(n))s_1(f(n)) 空间复杂度的 NTM MLM_L 能够 decide LL.

我们想要转化到一个 NSPACE(s1(n))NSPACE(s_1(n)) 的问题 就是把输入长度变成 f(n)f(n)

我们将输入 xx 从长度 nn 补到 f(n)f(n)

L={x@0f(n)nxL}L'=\{x \text{@} 0 ^ {f(n) -n} \mid x \in L\} , 那么 我们考虑这样一个 NTM

  1. 数最后的 00 的数量, check 是否有某个 nn 满足 00 的数量 等于 f(n)nf(n)-n
  2. 假如找到了这样的 nn, 我们相当于得到了输入 xx, 然后 run MLM_L on xx

之前那个 MLM_L 的空间复杂度是 s1(f(n))s_1(f(n)) 其中 nn 指的是 xx 的长度, 所以现在这个 NTMNTM 的复杂度就是 s1(n)s_1(n). 那么 LNSPACE(s1(n))L' \in NSPACE(s_1(n)). 于是, 根据条件, LSPACE(s2(n))L' \in SPACE(s_2(n)), 再做一个从 LLL' \rightarrow L 的转换, 我们就得到了一个 确定性图灵机, works in O(s2(f(n)))O(s_2(f(n))) space.

原始定理的证明·

  • 只要 s1(n)=log(n)s_1(n) = \log(n), s2(n)=log2(n)s_2(n) = \log^2(n), 我们已经有 NSPACE(s1(n))SPACE(s2(n))NSPACE(s_1(n)) \subset SPACE(s_2(n)), 那么我们就有 NSPACE(s1(f(n)))SPACE(s2(f(n)))NSPACE(s_1(f(n))) \subset SPACE(s_2(f(n))) 对任意的 f(n)nf(n) \geq n. 代入就是 NSPACE(log(f(n)))SPACE(log2(f(n)))NSPACE(\log(f(n))) \subset SPACE(\log ^ 2(f(n))). 令 g(n)=log(f(n))g(n) = \log (f(n)), 那么就是 NSPACE(g(n))SPACE(g2(n))NSPACE(g(n)) \subset SPACE(g^2(n)), g(n)g(n) 的限制条件只有 g(n)logng(n) \geq \log n.

Corollary·

  • PSPACE=NPSPACEPSPACE = NPSPACE

  • Clearly, PSPACENPSPACEPSPACE \subset NPSPACE. By Savitch’s theorem, NPSPACEPSPACENPSPACE \subset PSPACE.

Remark·

可以看到, 时间复杂度和空间复杂度有很大不同. NP 和 P 差距极大, 而 NSPACE 和 PSPACE 并没有太大的差别.

PSPACE·

  • 在多项式空间内能被 确定图灵机 decide 的语言
  • e.g. SAT is in PSPACE 只需要顺序枚举每一个 xix_i 的值 也因此 NPPSPACENP \subset PSPACE

TQBF (true quantified Boolean formula)·

  • complete for PSPACE

Problem statement·

  • Instance: a fully quantified Boolean formula ϕ\phi
  • fully quantified 就是对于 formula 中的每个变量, 都有一个 \exists 或者 \forall 去限定他 -> quantifier
  • Problem: to decide if ϕ\phi is true

TQBF is in PSPACE·

  • We describe a poly-space algorithm for evaluating ϕ\phi
  • If ϕ\phi has no quantifiers: 那么式子里所有变量取值都确定了, 直接算
  • If ϕ=x(ψ(x))\phi = \forall x (\psi(x)): 那么把 x=0x=0x=1x=1 都带进去算, 都 accept 才 accept
  • If ϕ=x(ψ(x))\phi = \exists x (\psi(x)): 把 x=0x=0x=1x=1 带进去算, 只要有一个 accept 就 accept
  • 空间是线性的

PSPACE Completeness·

Definition·

  • A language BB is PSPACE-complete iff
    • BPSPACEB \in PSPACE
    • APSPACE,APB\forall A \in PSPACE, A \leq_P B
      • 这里的 P\leq_P 就是多项式时间的归约

TQBF is PSPACE-complete·

  • 已经证明了 TQBF is in PSPACE
  • 需要证明 TQBF is PSPACE-hard
  • 给定一个图灵机 MM for a language LPSPACEL \in PSPACE, 给定一个输入 xx, 需要将 MM 是否 accept xx 多项式时间内归约到 TQBFTQBF
  • construct a QBF ϕ\phi of polynomial size s.t. ϕ\phi is true 等价于 MM accepts xx
  • 对所有的 configuration 编码, for configurations u,vu, v and an integer tt, define ϕ(u,v,t)=true\phi(u, v, t) = \text{true} iff vv is reachable from uu in tt steps
  • 下面用 分治
  • 首先考虑 ϕ(u,v,1)\phi(u,v,1) 就是说 uuvv 一步就到达, 那么他们最多在三个位置上能不同, 其他位置都相同, 非常好判断
  • 对于 t>1t > 1, 我们有 ϕ(u,v,t)=m[ϕ(u,m,t/2) and ϕ(m,v,t/2)]\phi(u,v,t) = \exists m [\phi(u, m, t / 2) \mathbf{\ and \ } \phi(m, v, t / 2)]
  • 问题在于 tt 并不一定是 poly(|x|) 的
  • change the previous 递推式 to

ϕ(u,v,t)=(m)((a,b){(u,m),(m,v)}[ϕ(a,b,t/2)])ϕ(u,v,t)=(m)(a)(b)[((a=u&b=m) or (a=m&b=v))ϕ(a,b,t/2)]\phi(u, v, t) = (\exist m) (\forall (a, b) \in \{(u, m), (m, v)\} [\phi(a, b, t / 2)]) \\ \phi(u, v, t) = (\exist m) (\forall a) (\forall b) [((a = u \& b = m) \text{ or } (a = m \& b = v)) \rightarrow \phi(a, b, t / 2)]

  • size: S(t)=S(t/2)+poly(x)S(t) = S(t / 2) + poly(|x|), thus S(t)S(t) is poly(x)poly(|x|)
  • ϕM,x=ϕ(cstart,caccept,h)\phi_{M, x} = \phi(c_{start}, c_{accept}, h) is TRUE 当且仅当 MM accepts xx in hh steps
  • ϕ\phi is constructible in poly-time
  • 证毕

Formula Game·

Description·
  • 一个 formula ψ\psi with variables x1,x2,,xnx_1, x_2, \cdots, x_n
  • 两个人轮流选择 xix_i 的取值, 第一个人 AA 想要 ψ\psi 为真, 第二个人 EE 想要 ψ\psi 为假
  • FORMULA-GAME = {ψ 在 ψ 的 formula game 中 E 有必胜策略 }\{\langle \psi \rangle \mid \text{ 在 } \psi \text{ 的 formula game 中 E 有必胜策略 } \}
  • 这个问题等价于 TQBF

Generalized Geography game·

Description·
  • 一个有向图 GG 起点 ss
  • 两个人轮流选择一条边往下走 走不了的输
  • GG={G,bPlayer I has a winning strategy on G starting from b}GG = \{\langle G, b \rangle \mid \text{Player I has a winning strategy on G starting from b}\}
  • GGGG is PSPACE-complete
    • GGGG is PSPACE

      image-20220520154644261

    • 把 Formula Game 规约到他

      • Unfinished·

Hierarchy theorem (层次定理)·

Time Hierarchy Theorem·

  • For any time constructable function f:NNf: N \rightarrow N, 存在语言 LL that is decidable in time O(f(n))O(f(n)), but not in time O(f(n)logf(n))O\left(\frac {f(n)} {\log f(n)} \right)

Space Hierarchy Theorem·

  • For any space constructable function f:NNf:N \rightarrow N, 存在语言 LL that is decidable in space O(f(n))O(f(n)) but not in space o(f(n))o(f(n))

证明思路·

  • 采用跟证明 ATMA_{TM} 不可解时用的 对角线法
  • 我们想要一个函数 DD, 他对应的语言 LL, 有 DDO(f(n))O(f(n)) 空间内运行, 并且 LL 不同于任何在 o(f(n))o(f(n)) 内能判定的语言
  • 不同于任何这样的语言 -> 有至少一个输入结果不同 -> 对于 M, 在输入 <M> 上不同

Proof·

image-20220521113553392

对于所有的 o(f(n))o(f(n)) 空间内能判定的语言, 在第四步的判定中能够运行完, 因为模拟一个 g(n)g(n) 空间内运行的图灵机 MM 只需要 dg(n)dg(n) 空间, 其中 dd 是依赖于 MM 的常数. 所以可以找到一个充分大的 n0n_0, dg(n0)<f(n0)dg(n_0) < f(n_0). 我们在 M\langle M \rangle 后面补上 10n010 ^ {n_0}, 让长度足够, 所以第四步就能运行完.

这样, 运行的结果一定与 M(M)M(\langle M \rangle) 本身的结果相反, 所以 DD 不能判定 AA.

Corollary·

image-20220521114222944

image-20220521114246555

image-20220521114304575

The polynomial Hierarchy (PH)·

For i1i\geq 1, a language LL is in Σip\Sigma_{i^p} if there exists a polynomial time TM MM and a polynomial qq s.t.

xLu1{0,1}q(x)u2{0,1}q(x)Qiui{0,1}q(x)M(x,u1,,ui)=1x \in L \Leftrightarrow \exists u_{1} \in\{0,1\}^{q(|x|)} \forall u_{2} \in\{0,1\}^{q(|x|)} \ldots Q_{i} u_{i} \in\{0,1\}^{q(|x|)} M\left(x, u_{1}, \ldots, u_{i}\right)=1

where QiQ_i is \exists when i is odd; is \forall when i is even. (sometimes we can omit superscript “p”)

  • Theorem: Any wf. AA 等价于 wf. BB in prenex form.

  • Σ0=P\Sigma_0 = P

    • Σ0\Sigma_0 就是 xLM(x)=1x\in L \Leftrightarrow M(x)=1 就是一个多项式时间内能 decide 的 TM
  • Σ1=NP\Sigma_1 = NP

    • Σ1\Sigma_1 就是 xLu,M(x,u)=1x\in L \Leftrightarrow \exists u, M(x,u)=1 就是先猜一个解然后多项式时间内判断是否正确
  • 定义 PH=iΣiPH=\cup_i \Sigma_i

  • 定义 Πip=coΣip\Pi_{i^p} = co\Sigma_{i^p}, which is

    xLu1{0,1}q(x)u2{0,1}q(x)Qiui{0,1}q(x)M(x,u1,,ui)=1x \in L \Leftrightarrow \forall u_{1} \in\{0,1\}^{q(|x|)} \exists u_{2} \in\{0,1\}^{q(|x|)} \ldots Q_{i} u_{i} \in\{0,1\}^{q(|x|)} M\left(x, u_{1}, \ldots, u_{i}\right)=1

  • 跟之前 Σ\SigmaΠ\Pi prenex form 差不多

  • Note that ΣipΠi+1pΣi+2p\Sigma_{i^p}\subset \Pi_{\\{i+1}^p}\subset \Sigma_{\\{i+2}^p}, 所以 PH=iΠiPH = \cup_i \Pi_i

Oracle Turing Machine (OTM)·

Definition·

  • 针对一个语言 AA 的 oracle 是一个能判断 ww 是否属于 AA 的黑盒子. Oracle Turing Machine MAM^A 指的是在一个通常的图灵机上增加查询 AA 的 oracle 的能力. 有三个特殊的状态 qquery,qyes,qnoq_{query}, q_{yes}, q_{no}. 每当进入到 qqueryq_{query} 态的时候, 就可以在一步之内查询在询问纸带上的 yy 是否属于 AA 并且依照结果进入到 qyesq_{yes} 或者 qnoq_{no} 状态.
  • 我们可以类似地定义 Nondeterministic OTM

一些记号·

  • image-20220521152929685

  • image-20220521152954350

  • Both together: CDC^D = languages decided by OTM in CC with oracle language from DD

    • e.g. PSAT=PNPP^{SAT}=P^{NP}
  • Σ2=NPNP\Sigma_2 = NP^{NP}

  • Π2=coNPNP\Pi_2 = co{NP}^{NP}

  • image-20220521154542700

Relativization·

  • Many proofs and techniques we have seen are relativize
    • they hold after replacing all TMs with oracle TMs that have access to an oracle AA
    • including diagonalization
  • 我们想要说明 PP 是否等于 NPNP 的问题不是简单的对角化就能解决的
    • 只要说明 加了某个 oracle 之后 PA=NPAP^{A}= NP^{A}, 加了另一个 oracle 之后 PBNPBP^B \neq NP^B

PA=NPAP^A = NP^A·

  • 这需要 AA 很牛逼
  • A=TQBFA=TQBF works
  • PSPACEPTQBFNPTQBFNPSPACEPSPACE ⊆P^{TQBF} ⊆NP^{TQBF} ⊆NPSPACE
  • we also know PSPACE=NPSPACEPSPACE=NPSPACE

PBNPBP^B \neq NP^B·

  • 定义 L(B)={1k:xB,s.t.x=k}L(B) = \{1^k : \exists x \in B, s.t. |x|=k\}

  • we will find BB such that L(B)NPBPBL(B) \in NP^B - P^B

  • 首先, L(B)NPBL(B) \in NP^B

    • 对于任意 ww 我们想判断是否属于 L(B)L(B)
    • 只需要猜一个 xBx \in B 然后让 x=w|x|=|w|
  • 其次, find BB such that L(B)PBL(B) \notin P^B

    • unfinished·

Randomized Computation·