Set and Language

  • The Diagonalization Principle
    • RR is the binary relation on set AA.
    • DD is the diagonal set for RR: {a:a∈A∧(a,a)∉R}\{ a:a \in A \wedge (a,a) \notin R \}.
    • Let Ra={b:b∈A∧(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(((a∪b)⋆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
    • s∈Ks \in K is the initial state
    • F⊆KF \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
    • s∈Ks \in K is the initial state −F⊆K-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′={Q∣Q⊆K,Q∩F≠∅}F^{\prime}=\{Q | Q \subseteq K, Q \cap F \neq \emptyset\}
      • For each Q⊆KQ \subseteq K and ∀a∈Σ\forall a \in \Sigma, let δ(Q,a)=∪{E(p)∣p∈K\delta(Q, a)=\cup\{E(p) | p \in K and (q,a,p)∈Δ(q, a, p) \in \Delta for some q∈Q}q \in Q\}
    • Claim: For any string w∈∑∗w \in \sum^{\ast} and any states p,q∈Kp, 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×F2…K = K_1 \times K_2, F = F_1 \times F_2\dots
    • Example: Show L={w∈{a,b}∗:w has an equal number of a′s and b′s}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 L∩a∗b∗L \cap a^{\ast} b^{\ast} But L∩a∗b∗={anbn:n≥0}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} .
    • RL→FA\mathrm{RL}\rightarrow \mathrm{FA}: Simply use the above properties.
    • FA→RL\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)={w∣w∈∑∗,δ(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, x≠ex \neq e, δ(qi,x)=ql∧(l≤k)\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 q1…qkq_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 n≥1n \geq 1 such that any string w∈Lw \in L with ∣w∣≥n|w| \geq n can be written as w=xyzw=x y z such that:
    • y≠ey \neq e
    • ∣xy∣≤n|xy| \leq n
    • for each i≥0,xyiz∈Li \geq 0, xy^{i}z \in L
      Example: Show L={an∣n 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,r≥0p, r \geq 0 and q>0q>0 (any p,q,rp,q,r as long meets the condition).
      • By Pumping theorem, xynz∈Lx y^{n} z \in L for each n≥0;n \geq 0 ; that is, p+nq+rp+n q+r is prime for each n≥0n \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;
    • S∈V−∑S \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={S→e,S→SS,S→aSb,S→bSa},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 a′s and b′s}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)
    • s∈Ks \in K is the initial state
    • F⊆KF \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.
    • CFL→PDA\mathrm{CFL} \rightarrow \mathrm{PDA}
      • Build 2−2-state PDA and simply change each grammar to each transition relation.
    • PDA→CFL\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.
      • PDA→simple PDA→CFL\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 w∈L(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
      • ∣vy∣≥1|v y| \geq 1
      • uvnxynz∈L(G) for every n≥0{u v^{n} x y^{n} z \in L(G) \text { for every } n \geq 0}
    • Example: Show that L={anbncn:n≥0}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 a′s,b′sa^{\prime} s, b^{\prime} s and c′sc^{\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
    • s∈Ks \in K is the initial state
    • H⊆KH \subseteq K is the set of halting states
    • δ:(K−H)×∑→K×(∑∪{←,→})\delta:(K-H) \times \sum \rightarrow K \times (\sum \cup\{\leftarrow, \rightarrow\}) be the transition function:
      • ∀q∈K−H\forall q \in K-H if δ(q,⊳)=(p,b),\delta(q, \rhd)=(p, b), then b=→b=\rightarrow
      • ∀q∈K−H\forall q \in K-H and a∈∑,a \in \sum, if δ(q,a)=(p,b),\delta(q, a)=(p, b), then b≠⊳b \neq \rhd

  • Notation for Turing Machine

    • MaM_a (or simply a): The machine with two states that only to write aa on the tape.
    • M←M_\leftarrow and M→M_\rightarrow (or simply L and R): The machine with two states that only move left or right.
    • Machine Combination: M1⟶aM2M_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 k≥1k \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 k−k- tapes TM MM has a corresponding standard machine M′M \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 M′M^{\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:
      • w∈Lw \in L iff MM accepts ww (ends in the yesyes configuration)
      • w∉Lw \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:n≥0}.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∗→Σ0∗f: \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⊆Σ0∗L \subseteq \Sigma_{0}^{*}
      • MM semidecides LL if for ∀w∈Σ∗\forall w \in \Sigma^{*} the following is true: w∈L⇔Mw \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
      • M↑M \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 (V−∑V-\sum is called the set of nonterminal symbols).
      • S∈V−∑S \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: SwS⇒G∗v 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))}
      • n∼m=max⁡(n−m,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,p↑m),p↑(m∼1))\operatorname{digit}(m, n, p)=\operatorname{div}(\operatorname{rem}(n, p \uparrow m), p \uparrow(m \sim 1))
      • y∣x⇔∃t(≤x)(y⋅t=x)y | x \Leftrightarrow \exists t_{(\leq x)}(y \cdot t=x)
      • prime(x)⇔(x>1)∧∀t(<x)[t=1∨¬(t∣x)]\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:Nk→Nf: \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.