During 2019.92020.12019.9 \sim 2020.1,I was involved in the Theory-of-Computation class guided by Yingchun Yang.

Mrs. Yang do not teach well, so I had to learn by myself and tried to summary something.

Set and Language

  • The Diagonalization Principle
    • RR is the binary relation on set AA.
    • DD is the diagonal set for RR: {a:aA(a,a)R}\{ a:a \in A \wedge (a,a) \notin R \}.
    • Let Ra={b:bA(a,b)R}R_a = \{ b: b \in A \wedge (a,b) \in R \}
    • Then D is distinct from each RaR_a.
  • if σ\sigma is a finite alphabet, then σ\sigma^\ast is countably infinite set (Lexicographically).
  • Kleene Star: $$\begin{aligned} L^{\ast} &={w \in \Sigma^{*}: w=w_{1} \cdots w_{k}, k \geq 0, w_{1}, \cdots, w_{k} \in L} \ &=L^{0} \cup L^{1} \cup L^{2} \cup \cdots \ L^{+}&=L^{1} \cup L^{2} \cup L^{3} \cup \cdots \end{aligned}$$

Regular Language \leftrightarrow Finite Automata

  • Definition: The Regular Expressions are all strings over the alphabet {(,),,}\sum \cup\{(,), \cup, \star\} that can be obtained as follows:
    1. Θ\Theta and {x}(xΣ)\{x\}(\forall x \in \Sigma) is a regular expression.
    2. If α\alpha and β\beta are regular expressions, then so are (αβ)(\alpha \beta) (αβ),α(\alpha \cup \beta), \alpha^{\star}.
    3. Nothing is regular expression unless it follows from 1 through 2.
  • The function L\mathscr{L} is defined as follows:
    1. L(Θ)=,\mathscr{L}(\Theta)=\emptyset, and L(a)={a}\mathscr{L}(a)=\{a\} for each aΣa \in \Sigma
    2. If α\alpha and β\beta are regular expressions, then
      • L(αβ)=L(α)L(β){\mathscr{L}(\alpha \beta)=\mathscr{L}(\alpha) \mathscr{L}(\beta)}
      • L(αβ)=L(α)L(β){\mathscr{L}(\alpha \cup \beta)=\mathscr{L}(\alpha) \cup \mathscr{L}(\beta)}
      • L(α)=L(α){\mathscr{L}(\alpha^{\star})=\mathscr{L}(\alpha)^{*}}

    Example: L(((ab)a))=({a,b}){a}\mathscr{L}(((a \cup b)^{\star} a))=(\{a, b\})^{\ast}\{a\}

  • Definition: The class of regular languages over an alphabet Σ\Sigma is defined to consist of all languages LL such that L=L(a)L=L(a) for some regular expression a over Σ.\Sigma . i.e. the class of regular languages over an alphabet Σ\Sigma is precisely the closure of the set of languages: ${ { \sigma }: \sigma \in \Sigma } \cup { \emptyset } $.
  • Definition: A Deterministic Finite Automata is a quintuple (K,Σ,δ,s,F),(K, \Sigma, \delta, s, F), where
    • KK is a finite set of states
    • Σ\Sigma is an alphabet
    • sKs \in K is the initial state
    • FKF \subseteq K is the set of final states
    • δ:\delta: transition function K×KK \times \sum \rightarrow K
  • Definition: A Nondeterministic Finite Automata is a quintuple (K,Σ,Δ,s,F),(K, \Sigma, \Delta, s, F), where
    • KK is a finite set of states
    • Σ\Sigma is an alphabet
    • sKs \in K is the initial state FK-F \subseteq K is the set of final states.
    • Δ,\Delta, transition relation, is a subset of K×({e})×KK \times(\sum \cup\{e\}) \times K
  • Theorem: For each NFA, there is an equivalent DFA.
    • Key idea: Every subset of KK becomes a single state in the new machine.
    • Construction: For any NFA M=(K,Σ,Δ,s,F)M=(K, \Sigma, \Delta, s, F), construct an equivalent DFA M=(K,Σ,δ,s,F)M^{\prime}=(K^{\prime}, \Sigma, \delta, s^{\prime}, F^{\prime}):
      • K=2KK^{\prime}=2^{K}
      • s=E(s)s^{\prime}=E(s)
      • F={QQK,QF}F^{\prime}=\{Q | Q \subseteq K, Q \cap F \neq \emptyset\}
      • For each QKQ \subseteq K and aΣ\forall a \in \Sigma, let δ(Q,a)={E(p)pK\delta(Q, a)=\cup\{E(p) | p \in K and (q,a,p)Δ(q, a, p) \in \Delta for some qQ}q \in Q\}
    • Claim: For any string ww \in \sum^{\ast} and any states p,qKp, q \in K, (q,w)M(p,e)(E(q),w)M(P,e)(q, w) \vdash_{M}^{\ast}(p, e) \Leftrightarrow(E(q), w) \vdash_{M^{\prime}}^{\ast}(P, e) (for some set PP containing pp).

      Use Mathematical Induction to prove this claim.

  • Closure Properties of Regular Languages: The class of languages accepted by FA is closed under:
    • Union
      • use NFA to simply prove it.
      • Note: Any finite union of regular sets is regular. Infinite unions may not be regular.
    • Concatenation
    • Kleene star
    • Complementation
      • Simply reverse the Final State.
    • Intersection
      • Prove1: L(M1)L(M2)=(L(M1))(L(M2))L (M_{1}) \cap L(M_{2})=\sum^{\ast}-(\sum^{\ast}-L(M_{1})) \cup(\sum^{\ast}-L(M_{2}))
      • Prove2: K=K1×K2,F=F1×F2K = K_1 \times K_2, F = F_1 \times F_2\dots
    • Example: Show L={w{a,b}:w has an equal number of as and bs}L=\{w \in\{a, b\}^{\ast}: w \text { has an equal number of } a^{\prime} s \text { and } b^{\prime} s\} is not regular.
    • Proof: If LL is regular, then so would be LabL \cap a^{\ast} b^{\ast} But Lab={anbn:n0}L \cap a^{\ast} b^{\ast}=\{a^{n} b^{n}: n \geq 0\} is not regular language.
  • Theorem: A language is regular iff it is accepted by a FA\mathrm{FA} .
    • RLFA\mathrm{RL}\rightarrow \mathrm{FA}: Simply use the above properties.
    • FARL\mathrm{FA}\rightarrow \mathrm{RL}
      • Definition: For i,j=1,,ni, j=1, \cdots, n and k=0,,nk=0, \cdots, n, define R(i,j,k)={ww,δ(qi,w)=qj}R(i, j, k)=\{w | w \in \sum^{\ast}, \delta(q_i, w)=q_j \} and for any prefix xx of ww, xex \neq e, δ(qi,x)=ql(lk)\delta (q_{i}, x)=q_{l} \wedge (l \leq k).
      • i.e. Each string ww which satisfies that qiq_i use ww to reach qjq_j just with the help of q1qkq_1\dots q_k.
      • Lemma: R(i,j,k)R(i, j, k) are regular languages.
      • Construct the new equivalent FA K=K{s,f}K'=K \cup \{s',f'\} that has the only initial state and the only final state. R(s,f,n)R(s',f',n) is the regular language we construct.
  • Theorem: (Pumping Theorem) Let LL be a regular language. Exist an integer n1n \geq 1 such that any string wLw \in L with wn|w| \geq n can be written as w=xyzw=x y z such that:
    • yey \neq e
    • xyn|xy| \leq n
    • for each i0,xyizLi \geq 0, xy^{i}z \in L
      Example: Show L={ann is prime }L=\{a^{n} | n \text { is prime }\} is not regular.
      Proof:
      • Assume LL regular. w=xyz,\exists w=x y z, and x=ap,y=aqx=a^{p}, y=a^{q} and z=ar,z=a^{r}, where p,r0p, r \geq 0 and q>0q>0 (any p,q,rp,q,r as long meets the condition).
      • By Pumping theorem, xynzLx y^{n} z \in L for each n0;n \geq 0 ; that is, p+nq+rp+n q+r is prime for each n0n \geq 0.
      • However, let n=p+2q+r+2;n=p+2 q+r+2 ; then p+nq+r=(q+1)(p+2q+r)p+n q+r=(q+1) \cdot(p+2 q+r)

Context-Free Language \leftrightarrow PushDown Automata

  • Definition: A Context-Free Grammar is a quadruple G=(V,Σ,R,S),G=(V, \Sigma, R, S), where
    • VV is an alphabet;
    • ΣV\Sigma \subseteq V is the set of terminal symbols;
    • SVS \in V-\sum is the start symbol;
    • RR is the set of rules, a finite subset of (VΣ)×V(V-\Sigma) \times V^{*}
      Example: Let G=({S,a,b},{a,b},R={Se,SSS,SaSb,SbSa},S)G=(\{S, a, b\},\{a, b\}, R=\{S \rightarrow e, S \rightarrow S S, S \rightarrow a S b, S \rightarrow b S a\}, S), then L(G)={w{a,b}:w has the same number of as and bs}L(G)=\{w \in\{a, b\}^{\ast}: w \text { has the same number of } a^{\prime} s \text { and } b^{\prime} s\}
  • Definition: A PushDown Automata is a sextuple M=(K,,Γ,Δ,s,F)M=\left(K, \sum, \Gamma, \Delta, s, F\right), where
    • KK is a finite set of states
    • \sum is an alphabet (the input symbols)
    • Γ\Gamma is an alphabet (the stack symbols)
    • sKs \in K is the initial state
    • FKF \subseteq K is the set of final states
    • Δ,\Delta, transition relation, is a subset of (K×({e})×Γ)×(K×Γ)(K \times(\sum \cup\{e\}) \times \Gamma^{\ast}) \times(K \times \Gamma^{\ast}).
  • PDA\mathrm{PDA} execution: reading a symbol
    Consider ((p,α,β),(q,γ))Δ,((p, \alpha, \beta),(q, \gamma)) \in \Delta, Then the PDA can:
    • enter some state qq
    • replace β\beta by γ\gamma on the top of the stack
    • advance the tape head
      Note:
      1. If β=abc\beta=abc, then aa is the top and cc is the bottom.
      2. PDA receives strings when reach the final state and its stack is empty.
  • Theorem: The class of languages accepted by PDA is exactly the class of CFL.
    • CFLPDA\mathrm{CFL} \rightarrow \mathrm{PDA}
      • Build 22-state PDA and simply change each grammar to each transition relation.
    • PDACFL\mathrm{PDA} \rightarrow \mathrm{CFL}
      • Definition: A PDA is simple if the following is true: Whenever ((q,a,β),(p,γ))((q, a, \beta),(p, \gamma)) is a transition of the PDA and qq is not the start state, then βΓ\beta \in \Gamma and γ2|\gamma| \leq 2.
      • PDAsimple PDACFL\mathrm{PDA} \rightarrow \mathrm{simple~PDA} \rightarrow \mathrm{CFL}
  • Closure Properties: The CFL are closed under Union, Concatenation, and Kleene star.
  • Theorem: The Intersection of a CFL with a regular language is a CFL.
  • Pumping Theorem for CFL.
    • Lemma: The yield of any parse tree of G of height hh has length at most ϕ(G)h\phi(G)^{h}.
    • Theorem: Let G=(V,Σ,R,S)G=(V, \Sigma, R, S) be a CFG. Then any string wL(G)w \in L(G) of length greater than ϕ(G)VΣ\phi(G)|V-\Sigma| can be rewritten as w=uvxyzw=u v x y z in such way that
      • vy1|v y| \geq 1
      • uvnxynzL(G) for every n0{u v^{n} x y^{n} z \in L(G) \text { for every } n \geq 0}
    • Example: Show that L={anbncn:n0}L=\{a^{n} b^{n} c^{n}: n \geq 0\} is not CFL.
    • Proof:
      • Case 11: v,yv, y contains occurrences of all three symbols a,b,ca, b, c \Rightarrow at least one of v,yv, y must contain at least two of them \Rightarrow order error in uv2xy2zu v^{2} x y^{2} z.
      • Case 22: v,yv, y contains occurrences of some but not all of them uv2xy2z\Rightarrow u v^{2} x y^{2} z has unequal number of as,bsa^{\prime} s, b^{\prime} s and csc^{\prime} s

Turing Machine

  • Definition: A Turing Machine is a quintuple (K,,δ,s,H)(K, \sum, \delta, s, H) where
    • KK is a finite set of states
    • Σ\Sigma is an alphabet containing (blank symbol)\cup (\text {blank symbol}) and (left end)\rhd(\text {left end}) but not containing the symbols \leftarrow and \rightarrow
    • sKs \in K is the initial state
    • HKH \subseteq K is the set of halting states
    • δ:(KH)×K×({,})\delta:(K-H) \times \sum \rightarrow K \times (\sum \cup\{\leftarrow, \rightarrow\}) be the transition function:
      • qKH\forall q \in K-H if δ(q,)=(p,b),\delta(q, \rhd)=(p, b), then b=b=\rightarrow
      • qKH\forall q \in K-H and a,a \in \sum, if δ(q,a)=(p,b),\delta(q, a)=(p, b), then bb \neq \rhd

  • Notation for Turing Machine

    • MaM_a (or simply a): The machine with two states that only to write aa on the tape.
    • MM_\leftarrow and MM_\rightarrow (or simply L and R): The machine with two states that only move left or right.
    • Machine Combination: M1aM2M_1 \stackrel{a}{\longrightarrow} M_2. If the scanned symbol when halting is aa, M2M_2 starts up.
  • Example

  • Multiple tapes Turing Machine

    • Definition: Let k1k \geq 1 be an integer. A kk -tape TM is a quintuple (K,,δ,s,H)(K, \sum, \delta, s, H). The transition function $ \delta:(K-H) \times \sum^{k} \rightarrow K \times(\sum \cup{\leftarrow, \rightarrow})^{k}$.
    • Conventionally, the input string is placed on the first tape, as well as the output string.
    • Example:2-tapes copy machine:
    • Theorem: Any kk- tapes TM MM has a corresponding standard machine MM \prime so that:
      • xσ\forall x \in \sigma \ast, they halt in the same state and output same string.
      • If MM halts on input xx after tt steps, then MM^{\prime} halts on input xx after a number of steps which is O(t(x+t))\mathscr{O}(t \cdot(|x|+t))

More concepts

  • Recursive

    • MM decides LΣL \subseteq \Sigma^{\ast} if wΣ\forall w \in \Sigma^{\ast} the following is true:
      • wLw \in L iff MM accepts ww (ends in the yesyes configuration)
      • wLw \notin L iff MM rejects ww (ends in the nono configuration)
    • A language LL is recursive if \exists a TM\mathrm{TM} that decides LL.
    • Example: L={anbncn:n0}.L=\{a^{n} b^{n} c^{n}: n \geq 0\} . The Turing Machine shown below decides LL.
    • Definition: Let ff be a function f:Σ0Σ0f: \Sigma_{0}^{\ast} \rightarrow \Sigma_{0}^{\ast} . MM computes function ff if wΣ0,M(w)=f(w)\forall w \in \Sigma_{0}^{\ast}, M(w)=f(w).
      • A function ff is recursive if \exists a TM MM computes ff.
      • Example: succ(n)=n+1succ(n)=n+1.
    • Properties:
      • The recursive language is are closed under Union, Intersection, and Complement.
      • .The recursive language is recursive enumerable.
  • Recursive Enumerable

    • Definition: Let M=(K,Σ,δ,s,H)M=(K, \Sigma, \delta, s, H) is a TM. Let Σ0\Sigma_{0} \subseteq Σ{,}\Sigma-\{\rhd, \sqcup\} be an alphabet and LΣ0L \subseteq \Sigma_{0}^{*}
      • MM semidecides LL if for wΣ\forall w \in \Sigma^{*} the following is true: wLMw \in L \Leftrightarrow M halts on input ww.
      • A language LL is recursively enumerable(r.e.), iff a\exists a TM MM that semidecides LL
      • MM \uparrow means MM can not halt.
  • grammar

    • Definition: A grammar (or unrestricted grammar) is a quadruple G=(V,Σ,R,S),G=(V, \Sigma, R, S), where
      • VV is an alphabet;
      • ΣV\Sigma \subseteq V is the set of terminal symbols (VV-\sum is called the set of nonterminal symbols).
      • SVS \in V-\sum is the start symbol
      • RR is the set of rules, a finite subset of (V(VΣ)V)×V(V^{\ast}(V-\Sigma) V^{\ast}) \times V^{\ast}
    • Theorem: A language is generated by a grammar if and only if it is recursively enumerable.
    • Definition: Let G=(V,Σ,R,S)G=(V, \Sigma, R, S) be a grammar, and let f:ΣΣf: \Sigma^{\ast} \rightarrow \Sigma^{\ast} be a function. GG computes ff, if for all w,vΣ,w, v \in \Sigma^{\ast}, the following is true: SwSGv iff v=f(w)S w S \Rightarrow_{G}^{\ast} v \text { iff } v=f(w)
    • A function f:ΣΣf: \Sigma^{\ast} \rightarrow \Sigma^{\ast} is called grammatically computable iff there is a grammar GG that computes it.
    • Theorem: A function f:ΣΣf: \Sigma^{\ast} \rightarrow \Sigma^{\ast} is recursive iff and only if it is grammatically computable.
  • primitive recursive function

    • The primitive recursive functions are all basic functions (the kk-ary zero function, the jj-th kk-ary identity function, the successor function), and all functions that can be obtained by them by any number of successive applications of composition and recursive definition.
    • Example
      • plus(m,0)=m,plus(m,n+1)=succ(plus(m,n))\mathrm{plus(m, 0)=m, plus(m, n+1)=succ(plus(m, n))}
      • mult(m,0)=zero(m),mult(m,n+1)=plus(m,mult(m,n))\mathrm{mult(m, 0)=zero(m),mult(m, n+1)=plus(m, mult(m, n))}
      • exp(m,0)=succ(zero(m)),exp(m,n+1)=mult(m,exp(m,n))\mathrm{exp (m, 0)=succ(zero(m)),exp(m, n+1)=mult(m, exp (m, n))}
      • nm=max(nm,0)n \sim m = \max(n-m,0)
    • Definition: A primitive recursive predicate is a primitive recursive function that only takes values 0 and 11.
      • f(x)=g(x) if c(x) otherwise h(x)f(\pmb{x})=g(\pmb{x}) \text{ if } c(x) \text{ otherwise } h(\pmb{x}). f(x)f(\pmb{x}) is also primitive recursive if others are.
      • If p(n1,,nk,m)p\left(n_{1}, \ldots, n_{k}, m\right) is primitive recursive predicate, then t(m)p(n1,,nk,t) and t(m)p(n1,,nk,t)\exists t_{(\leq m)} p\left(n_{1}, \ldots, n_{k}, t\right) \text { and } \forall t_{(\leq m)} p\left(n_{1}, \ldots, n_{k}, t\right) are primitive recursive predicates.
    • Example:
      • rem,div\mathrm{rem, div}
      • digit(m,n,p)=div(rem(n,pm),p(m1))\operatorname{digit}(m, n, p)=\operatorname{div}(\operatorname{rem}(n, p \uparrow m), p \uparrow(m \sim 1))
      • yxt(x)(yt=x)y | x \Leftrightarrow \exists t_{(\leq x)}(y \cdot t=x)
      • prime(x)(x>1)t(<x)[t=1¬(tx)]\mathrm{prime}(x) \Leftrightarrow(x>1) \wedge \forall t_{(<x)}[t=1 \vee \neg(t | x)]
    • Note: The set of primitive recursive function is proper subset of the set of recursive function.
      • Prove: List all the primitive recursive function fif_i. Assume g(n)=fn(n)+1g(n)=f_n(n)+1, so gg is computable but not primitive recursive.
    • Definition: A function is μ\mu-recursive if it can be obtained from the basic functions by the operations of composition, recursive definition, and minimalization of minimalizable functions.
      • log(m,n)=μ p[greater-than-or-equal( (m+2)p,n+1)]\log (m, n)=\mu ~ p[\text {greater-than-or-equal( }(m+2) \uparrow p, n+1)]
    • Theorem: A function f:NkNf: \mathbb{N}^{k} \rightarrow \mathbb{N} is μ\mu -recursive iff it is recursive (that is, computable by a TM).

Undecidability

  • Church - Turing thesis: Intuitive notation of “computable” = Formal notation of “computable functions by TM” .

    • A problem is decidable iff it is recursive.
  • There is no program, no algorithm for solving the halting problem.

  • Theorem: Let H={M w: TM M halts on input string w}H=\{''M''~''w'': \text { TM } M \text { halts on input string } w \} The language HH is not recursive (but r.e.).

    • Therefore, the class of recursive languages is a strict subset of the class of recursively enumerable languages.
    • Proof:
      • HH recursive H1\Rightarrow H_{1} recursive, where H1={M:M halts on input "M" }H_{1}=\{''M^{\prime \prime}: M \text { halts on input "M" }\}
        MM Who decides HH surely decides H1H_1.
      • H1H_{1} recursive H1\Rightarrow \overline{H_{1}} recursive.
        The class of recursive languages is closed under complement.
      • H1\overline{H_{1}} is not even a r.e. language.
    • Note that H1H_1 is r.e.
  • Properties of Recursive Languages
    • LL is recursive iff LL and L^\hat{L} are both r.e…
      • Left \rightarrow Right: Simple.
      • Right \rightarrow Left: Left two TMTM run simultaneously, either of them will stop finally.
  • Definition: We say that a Turing machine MM enumerates the language LL iff for some fixed state qq of MM, L={w:(s,,)M(q,,w)}L=\{w:(s, \rhd, \underline \sqcup) \vdash_{M}(q, \rhd, \underline \sqcup w)\}. A language is Turing-enumerable iff there is a Turing machine that enumerates it.
    • A language is recursively enumerable iff it is Turing-enumerable.
    • A language is recursively iff it is lexicographically Turing-enumerable.
  • Rice Theorem: If SS is a class of recursively enumerable languages such that I(S)\mathscr{I}(S) is neither empty nor the set of all indices, then I(S)\mathscr{I}(S) is undecidable.