Turing Machine
- one-way infinite
- its head can move left and right
- can read and write
Turing Machine is a 5-tuple P=(K,Σ,δ,s,H)P=(K,\Sigma,\delta,s,H)P=(K,Σ,δ,s,H)
- KKK is a finite set of states
- Σ\SigmaΣ is a alphabet containing left end symbol ⊳\rhd⊳ and blank symbol ⊔\sqcup⊔
- s∈Ks\in Ks∈K is the initial state
- H⊆KH\subseteq KH⊆K is the set of halting states
- transition function δ:((K−H)×Σ→K×(Σ∪{←,→})\delta:((K-H)\times\Sigma\to K\times(\Sigma\cup\{\leftarrow,\rightarrow\})δ:((K−H)×Σ→K×(Σ∪{←,→})
- ∀q∈K−H\forall q\in K-H∀q∈K−H, if δ(q,⊳)=(p,b)\delta(q,\rhd)=(p,b)δ(q,⊳)=(p,b), then b=→b=\rightarrowb=→
- ∀q∈K−H,∀a∈Σ\forall q\in K-H,\forall a\in\Sigma∀q∈K−H,∀a∈Σ, if δ(q,a)=(p,b)\delta(q,a)=(p,b)δ(q,a)=(p,b), then b≠⊳b\neq\rhdb=⊳
A configuration is a member of K×⊳(Σ−{⊳})∗×((Σ−{⊳})∗(Σ−{⊳,⊔})∪{e})K\times\rhd(\Sigma-\{\rhd\})^*\times((\Sigma-\{\rhd\})^*(\Sigma-\{\rhd,\sqcup\})\cup\{e\})K×⊳(Σ−{⊳})∗×((Σ−{⊳})∗(Σ−{⊳,⊔})∪{e})
- (q,⊳b⊔a,a⊔⊔b)≡(q,⊳b⊔a‾a⊔⊔b)(q,\rhd b\sqcup a,a\sqcup\sqcup b)\equiv(q,\rhd b\sqcup\underline{a}a\sqcup\sqcup b)(q,⊳b⊔a,a⊔⊔b)≡(q,⊳b⊔aa⊔⊔b)
- halting configuration if q∈Hq\in Hq∈H
Yields in one step: (q1,⊳w1a1u1)⊢M(q2,⊳w2a2u2)(q_1,\rhd w_1a_1u_1)\vdash_M(q_2,\rhd w_2a_2u_2)(q1,⊳w1a1u1)⊢M(q2,⊳w2a2u2) if
- (writing) w1=w2,u1=u2,a2∈Σ−{⊳}w_1=w_2,u_1=u_2,a_2\in\Sigma-\{\rhd\}w1=w2,u1=u2,a2∈Σ−{⊳} and δ(q1,a1)=(q2,a2)\delta(q_1,a_1)=(q_2,a_2)δ(q1,a1)=(q2,a2)
- (moving left) δ(q1,a1)=(q2,←),w1=w2a2\delta(q_1,a_1)=(q_2,\leftarrow),w_1=w_2a_2δ(q1,a1)=(q2,←),w1=w2a2 and either
- u2=eu_2=eu2=e if u1=eu_1=eu1=e and a1=⊔a_1=\sqcupa1=⊔
- u2=a1u1u_2=a_1u_1u2=a1u1, otherwise
- (moving right) δ(q1,a1)=(q2,→),w2=w1a1\delta(q_1,a_1)=(q_2,\rightarrow),w_2=w_1a_1δ(q1,a1)=(q2,→),w2=w1a1 and
- u1=eu_1=eu1=e if u2=eu_2=eu2=e and a2=⊔a_2=\sqcupa2=⊔
- u1=a2u2u_1=a_2u_2u1=a2u2, otherwise
We say two configurations C⊢M∗C′C\vdash^*_MC'C⊢M∗C′ iff
- C=C′C=C'C=C′ or
- ∃C0,C1,…,Ck(k≥1)\exists C_0,C_1,\dots,C_k(k\ge1)∃C0,C1,…,Ck(k≥1) s.t. C=C0⊢MC1⊢M⋯⊢MCk=C′C=C_0\vdash_MC_1\vdash_M\dots\vdash_MC_k=C'C=C0⊢MC1⊢M⋯⊢MCk=C′
MMM halts whenever it reaches a halting configuration
Exercise
- for any a∈Σ−{⊳}a\in\Sigma-\{\rhd\}a∈Σ−{⊳}, symbol-writing machine Ma=({s,h},Σ,δ,s,{h})M_a=(\{s,h\},\Sigma,\delta,s,\{h\})Ma=({s,h},Σ,δ,s,{h})
- δ(s,⊳)=(s,→)\delta(s,\rhd)=(s,\rightarrow)δ(s,⊳)=(s,→)
- δ(s,b)=(h,a)\delta(s,b)=(h,a)δ(s,b)=(h,a) for each b∈Σ−{⊳}b\in\Sigma-\{\rhd\}b∈Σ−{⊳}
- left-head-moving machine M←M_\leftarrowM←
- δ(s,⊳)=(s,→)\delta(s,\rhd)=(s,\rightarrow)δ(s,⊳)=(s,→)
- δ(s,b)=(h,←)\delta(s,b)=(h,\leftarrow)δ(s,b)=(h,←) for each b∈Σ−{⊳}b\in\Sigma-\{\rhd\}b∈Σ−{⊳}
- right-head-moving machine M→M_\rightarrowM→
- δ(s,⊳)=(h,→)\delta(s,\rhd)=(h,\rightarrow)δ(s,⊳)=(h,→)
- δ(s,b)=(h,→)\delta(s,b)=(h,\rightarrow)δ(s,b)=(h,→) for each b∈Σ−{⊳}b\in\Sigma-\{\rhd\}b∈Σ−{⊳}
Combining of basic machines
- Mi=(Ki,Σ,δi,si,Hi),∀i=1,2,3M_i=(K_i,\Sigma,\delta_i,s_i,H_i),\forall i=1,2,3Mi=(Ki,Σ,δi,si,Hi),∀i=1,2,3
- Construct M=(K,Σ,δ,s,H)M=(K,\Sigma,\delta,s,H)M=(K,Σ,δ,s,H)
- K=K1∪K2∪K3∪{h}K=K_1\cup K_2\cup K_3\cup\{h\}K=K1∪K2∪K3∪{h}
- s=s1s=s_1s=s1
- H=H2∪H3∪{h}H=H_2\cup H_3\cup\{h\}H=H2∪H3∪{h}
- ∀q∈K−H,∀a∈Σ\forall q\in K-H,\forall a\in\Sigma∀q∈K−H,∀a∈Σ
- If q∈K1−H1q\in K_1-H_1q∈K1−H1
- δ(q,a)=δ1(q,a)\delta(q,a)=\delta_1(q,a)δ(q,a)=δ1(q,a)
- If q∈H1q\in H_1q∈H1
- δ(q,0)=(s2,0)\delta(q,0)=(s_2,0)δ(q,0)=(s2,0)
- δ(q,1)=(s3,1)\delta(q,1)=(s_3,1)δ(q,1)=(s3,1)
- δ(q,a)=(h,→),∀a∈Σ−{0,1}\delta(q,a)=(h,\rightarrow),\forall a\in\Sigma-\{0,1\}δ(q,a)=(h,→),∀a∈Σ−{0,1}
- If q∈K2−H2q\in K_2-H_2q∈K2−H2
- δ(q,a)=δ2(q,a)\delta(q,a)=\delta_2(q,a)δ(q,a)=δ2(q,a)
- If q∈K3−H3q\in K_3-H_3q∈K3−H3
- δ(q,a)=δ3(q,a)\delta(q,a)=\delta_3(q,a)δ(q,a)=δ3(q,a)
- If q∈K1−H1q\in K_1-H_1q∈K1−H1
left-shifting machine S←S_\leftarrowS←
- ∀w∈(Σ−{⊳,⊔})∗:⊳⊔⊔w⊔‾→⊳⊔w⊔‾\forall w\in(\Sigma-\{\rhd,\sqcup\})^*: \rhd\sqcup\sqcup w\underline{\sqcup}\to\rhd\sqcup w\underline{\sqcup}∀w∈(Σ−{⊳,⊔})∗:⊳⊔⊔w⊔→⊳⊔w⊔
copy machine
- ∀w∈(Σ−{⊳,⊔})∗:⊳⊔‾w⊔→⊳⊔‾w⊔w⊔\forall w\in(\Sigma-\{\rhd,\sqcup\})^*: \rhd\underline{\sqcup}w\sqcup\to\rhd\underline{\sqcup}w\sqcup w\sqcup∀w∈(Σ−{⊳,⊔})∗:⊳⊔w⊔→⊳⊔w⊔w⊔
Recognize language
- input alphabet: Σ0=Σ−{⊳,⊔}\Sigma_0=\Sigma-\{\rhd,\sqcup\}Σ0=Σ−{⊳,⊔}
- M=(K,Σ0,Σ,δ,S,H)M=(K,\Sigma_0,\Sigma,\delta,S,H)M=(K,Σ0,Σ,δ,S,H)
- initial configuration: given w∈Σ∗w\in\Sigma^*w∈Σ∗, MMM starts with (s,⊳⊔‾w)(s,\rhd\underline{\sqcup}w)(s,⊳⊔w)
- L(M)={w∈Σ0∗L(M)=\{w\in\Sigma_0^*L(M)={w∈Σ0∗: MMM halts on w}w\}w}, MMM semidecides L(M)L(M)L(M)
- Example: Fix some input alphabet Σ0∗\Sigma_0^*Σ0∗
- Let a∈Σ0a\in\Sigma_0a∈Σ0, RaR_aRa semidecides L={w∈Σ0∗L=\{w\in\Sigma_0^*L={w∈Σ0∗: www contains a}a\}a}
Let M=(K,Σ,δ,S,{y,n})M=(K,\Sigma,\delta,S,\{y,n\})M=(K,Σ,δ,S,{y,n}) be a TM with input alphabet Σ0\Sigma_0Σ0, we say MMM decides a language L⊆Σ0∗L\subseteq \Sigma_0^*L⊆Σ0∗ if
- For every w∈Lw\in Lw∈L, (s,⊳⊔‾w)⊢M∗(y,⊳ua‾v)(s,\rhd\underline{\sqcup}w)\vdash^*_M(y,\rhd u\underline{a}v)(s,⊳⊔w)⊢M∗(y,⊳uav) for some u,v∈Σ∗u,v\in\Sigma^*u,v∈Σ∗ and a∈Σa\in\Sigmaa∈Σ
- MMM accepts www
- For every w∈Lw\in Lw∈L, (s,⊳⊔‾w)⊢M∗(n,⊳ua‾v)(s,\rhd\underline{\sqcup}w)\vdash^*_M(n,\rhd u\underline{a}v)(s,⊳⊔w)⊢M∗(n,⊳uav) for some u,v∈Σ∗u,v\in\Sigma^*u,v∈Σ∗ and a∈Σa\in\Sigmaa∈Σ
- MMM rejects www
- A language is recursive/decidable if it is decided by a TM
Example: The following TM decides {anbncn:n≥0}\{a^nb^nc^n:n\ge0\}{anbncn:n≥0}
Theorem: If LLL is recursive, it must be recursively enumerable
- LLL is recursive ⇒∃M=(K,Σ,δ,S,{y,n})\Rightarrow \exists M=(K,\Sigma,\delta,S,\{y,n\})⇒∃M=(K,Σ,δ,S,{y,n}) decides LLL
- δ(n,a)=(n,a)\delta(n,a)=(n,a)δ(n,a)=(n,a) for any a∈Σ−{⊳}a\in\Sigma-\{\rhd\}a∈Σ−{⊳}
- δ(n,⊳)=(n,→)\delta(n,\rhd)=(n,\rightarrow)δ(n,⊳)=(n,→)
Theorem: If LLL is recursive, so is L‾\overline{L}L
- Exchange the role of yyy and nnn
- False generalization: If LLL is recursive enumerable, so is L‾\overline{L}L
Compute function
- Let M=(K,Σ,δ,S,H)M=(K,\Sigma,\delta,S,H)M=(K,Σ,δ,S,H) be a TM with input alphabet Σ0\Sigma_0Σ0, let w∈Σ0∗w\in\Sigma_0^*w∈Σ0∗, if (s,⊳⊔‾w)⊢M∗(h,⊳⊔‾y)(s,\rhd\underline{\sqcup}w)\vdash^*_M(h,\rhd\underline{\sqcup}y)(s,⊳⊔w)⊢M∗(h,⊳⊔y) for some h∈Hh\in Hh∈H and y∈Σ0∗y\in\Sigma_0^*y∈Σ0∗
- yyy: output of MMM on www
- Let f:Σ0∗→Σ0∗f:\Sigma_0^*\to\Sigma_0^*f:Σ0∗→Σ0∗, we say MMM computes fff if for any w∈Σ0∗w\in\Sigma_0^*w∈Σ0∗ M(w)=f(w)M(w)=f(w)M(w)=f(w), i.e. MMM halts with ⊳⊔‾f(w)\rhd \underline{\sqcup}f(w)⊳⊔f(w)
Example: f(w)=wwf(w)=wwf(w)=ww is computed by the following TM
Enumrator
- We say a TM MMM enumerates a language LLL if for some state qqq, L={w:(s,⊳⊔‾)⊢M∗(q,⊳⊔‾w)}L=\{w:(s,\rhd\underline{\sqcup})\vdash^*_M(q,\rhd\underline{\sqcup}w)\}L={w:(s,⊳⊔)⊢M∗(q,⊳⊔w)}
- qqq is called output state
- A language is Turing enumerable if some TM enumerates it
Extensions of TM
- K-tape TM
- δ:(K−H)×Σk→K×(Σ∪{←,→})k\delta:(K-H)\times\Sigma^k\to K\times(\Sigma\cup\{\leftarrow,\rightarrow\})^kδ:(K−H)×Σk→K×(Σ∪{←,→})k
- Theorem: Any k-tape TM can be simulated by a standard TM
- K-track(conceptually), Σ′=(Σ∪{a‾:a∈Σ})k\Sigma'=(\Sigma\cup\{\underline{a}:a\in\Sigma\})^kΣ′=(Σ∪{a:a∈Σ})k
- Two-way Infinite Tape
- Simulated by 2-tape TM, split indices to N+\mathbb{N^+}N+ and Z−N+\mathbb{Z-N^+}Z−N+
- K-head TM
- Two-dimensional Tape
- countable, because ∣N+×N+∣=∣N+∣|\mathbb{N^+\times N^+}|=|\mathbb{N^+}|∣N+×N+∣=∣N+∣
- Random Access
- Non-determinism
A non-deterministic TM(NTM) is 5-tuple M=(K,Σ,Δ,S,H)M=(K,\Sigma,\Delta,S,H)M=(K,Σ,Δ,S,H)
- Δ⊆((K−H)×Σ)×(K×(Σ∪{←,→}))\Delta\subseteq((K-H)\times\Sigma)\times(K\times(\Sigma\cup\{\leftarrow,\rightarrow\}))Δ⊆((K−H)×Σ)×(K×(Σ∪{←,→}))
A NTM NNN with input alphabet Σ0\Sigma_0Σ0 semidecides a language L⊆Σ0∗L\subseteq\Sigma_0^*L⊆Σ0∗ if for any w∈Σ0∗w\in\Sigma_0^*w∈Σ0∗, the following is true:
- w∈Lw\in Lw∈L iff (s,⊳⊔‾w)⊢M∗(h,⊳u⊔‾v)(s,\rhd\underline{\sqcup}w)\vdash^*_M(h,\rhd u\underline{\sqcup}v)(s,⊳⊔w)⊢M∗(h,⊳u⊔v) for some hhh
Let M=(K,Σ,Δ,S,{y,n})M=(K,\Sigma,\Delta,S,\{y,n\})M=(K,Σ,Δ,S,{y,n}) be a NTM with input alphabet Σ0\Sigma_0Σ0, we say MMM decides a language L⊆Σ0∗L\subseteq \Sigma_0^*L⊆Σ0∗ if
- There is a natural number NNN, depending on MMM and www, such that there is no configuration CCC satisfying (s,⊳⊔‾w)⊢MNC(s,\rhd\underline{\sqcup}w)\vdash^N_MC(s,⊳⊔w)⊢MNC
- w∈Lw\in Lw∈L iff (s,⊳⊔‾w)⊢M∗(y,⊳u⊔‾v)(s,\rhd\underline{\sqcup}w)\vdash^*_M(y,\rhd u\underline{\sqcup}v)(s,⊳⊔w)⊢M∗(y,⊳u⊔v)
Example: Let CCC be the set of binary strings representing composite number, design a NTM decides CCC
- ⊳⊔w⊔p⊔q\rhd\sqcup w\sqcup p\sqcup q⊳⊔w⊔p⊔q: non-deterministicly generates a binary string ppp with 2≤p‾≤w‾2\le\overline{p}\le\overline{w}2≤p≤w and then non-deterministicly generates a binary string qqq with 2≤q‾≤w‾2\le\overline{q}\le\overline{w}2≤q≤w
- Multiply p‾\overline{p}p with q‾\overline{q}q, compare the product with w‾\overline{w}w
- Halt with yyy if match, nnn if not
Theorem: A NTM NNN can be simulated by a DTM MMM
- Choices for every step of NTM is finite (fanout): ∣K×(Σ∪{←,→}∣=∣K∣×(∣Σ∣+2)=Δr|K\times(\Sigma\cup\{\leftarrow,\rightarrow\}|=|K|\times(|\Sigma|+2)\xlongequal{\Delta}r∣K×(Σ∪{←,→}∣=∣K∣×(∣Σ∣+2)Δr
- Construct 3-tap DTM to simulate NTM, by BFS
- 1st-tape: input
- 2nd-tape: simulate a branch of NTM on www
- 3rd-tape: enumerate strings over {1,2,…,r}\{1,2,\dots,r\}{1,2,…,r}, addressing one node to access
Church-Turing Thesis
- Intuitive notation of algorithms equals to Turing Machine that halt on every input
Description of TM
- Formal description: 5-tuple
- Implement-level description: diagram
- High-level description: pseudo code
Fact: Every object OOO can be encoded into a string “OOO”
Example: Every TM can be encoded into a string
- Encoding states
- i=minj{j:2j≥∣K∣}i=\displaystyle\min_j\{j:2^j\ge|K|\}i=jmin{j:2j≥∣K∣}
- “q{0,1}iq\{0,1\}^iq{0,1}i”
- s:q0is:q0^is:q0i
- Encoding alphabet
- t=minj{j:2j≥∣Σ∣+2}t=\displaystyle\min_j\{j:2^j\ge|\Sigma|+2\}t=jmin{j:2j≥∣Σ∣+2}
- “a{0,1}ta\{0,1\}^ta{0,1}t”
- ⊔:a0t\sqcup:a0^t⊔:a0t
- ⊳:a0t−11\rhd:a0^{t-1}1⊳:a0t−11
- ←:a0t−210\leftarrow:a0^{t-2}10←:a0t−210
- →:a0t−211\rightarrow:a0^{t-2}11→:a0t−211
- Encoding transition
- δ:(K−H)×Σ→K×(Σ∪{←,→})\delta: (K-H)\times\Sigma\to K\times(\Sigma\cup\{\leftarrow,\rightarrow\})δ:(K−H)×Σ→K×(Σ∪{←,→})
- in 4-tuple like (q00,a100,q01,a00)(q00,a100,q01,a00)(q00,a100,q01,a00)
Fact: Given a valid encoding object, a TM is always able to decode it
Example
- Problem: Given a graph GGG, is GGG connected?
- Language: L={L=\{L={“GGG”: GGG is a connected graph}\}}
- M=M=M= on input “GGG”
- select a node of GGG and mark it
- repeat the following until no new nodes are marked: for each marked node, mark all its neighbors
- if all nodes of GGG are marked, accept “GGG”
- else reject
Decidable problem/recursive language
- About DFA/NFA/regular languages
R1 Problem
- Given a DFA BBB and a string www, does BBB accept www?
- Language: ADFA={A_\mathrm{DFA}=\{ADFA={“BBB”“www”: BBB is a DFA that accepts w}w\}w}
- MR1=M_\mathrm{R1}=MR1= on input “BBB”“www”
- simulate BBB on www
- if BBB accepts www, accept “BBB”“www”
- else reject
R1* Problem, for a fixed DFA BBB
- Given a string www, does BBB accept www?
- Language: L(B)L(B)L(B)
- MR1∗=M_\mathrm{R1^*}=MR1∗= on input www
- run MR1M_\mathrm{R1}MR1 on “BBB”“www”
- if MR1M_\mathrm{R1}MR1 accepts “BBB”“www”, accept www
- else reject
R2 Problem
- Given a NFA BBB and a string www, does BBB accept www?
- Language: ANFA={A_\mathrm{NFA}=\{ANFA={“BBB”“www”: BBB is a NFA that accepts w}w\}w}
- MR2=M_\mathrm{R2}=MR2= on input “BBB”“www”
- convert BBB into an equivalent DFA DDD
- run MR1M_\mathrm{R1}MR1 on “DDD”“www”
- if MR1M_\mathrm{R1}MR1 accepts “DDD”“www”, accept “BBB”“www”
- else reject
R3 Problem
- Language: AREX={A_\mathrm{REX}=\{AREX={“RRR”“www”: RRR is a regex and w∈L(R)}w\in L(R)\}w∈L(R)}
- MR3=M_\mathrm{R3}=MR3= on input “RRR”“www”
- convert RRR into an equivalent NFA BBB
- run MR2M_\mathrm{R2}MR2 on “BBB”“www”
- if MR2M_\mathrm{R2}MR2 accepts “BBB”“www”, accept “RRR”“www”
- else reject
R4 Problem
- Given a DFA BBB and a string www, is L(B)=∅L(B)=\varnothingL(B)=∅?
- Language: EDFA={E_\mathrm{DFA}=\{EDFA={“BBB”: BBB is a DFA and L(B)=∅}L(B)=\varnothing\}L(B)=∅}
- MR4=M_\mathrm{R4}=MR4= on input “BBB”
- mark the initial state of BBB
- repeat the following until no new states are marked: for each marked state, mark all its successors by transition function
- if no final states are marked, accept “BBB”
- else reject
Symmetric difference
- L(A)⊕L(B)={w:w∈L(A)∪L(B)∧w∉L(A)∩L(B)}L(A)\oplus L(B)=\{w:w\in L(A)\cup L(B)\land w\notin L(A)\cap L(B)\}L(A)⊕L(B)={w:w∈L(A)∪L(B)∧w∈/L(A)∩L(B)}
- L(A)⊕L(B)=(L(A)∩L(B)‾)∪(L(A)‾∩L(B))L(A)\oplus L(B)=\left(L(A)\cap\overline{L(B)}\right)\cup\left(\overline{L(A)}\cap L(B)\right)L(A)⊕L(B)=(L(A)∩L(B))∪(L(A)∩L(B))
- L(A)=L(B) ⟺ L(A)⊕L(B)=∅L(A)=L(B)\iff L(A)\oplus L(B)=\varnothingL(A)=L(B)⟺L(A)⊕L(B)=∅
R5 Problem
- Language: EQDFA={EQ_\mathrm{DFA}=\{EQDFA={“AAA”“BBB”: AAA and BBB are two DFAs and L(A)=L(B)}L(A)=L(B)\}L(A)=L(B)}
- MR5=M_\mathrm{R5}=MR5= on input “AAA”“BBB”
- construct a DFA CCC s.t. L(C)=L(A)⊕L(B)L(C)=L(A)\oplus L(B)L(C)=L(A)⊕L(B)
- run MR4M_\mathrm{R4}MR4 on “CCC”
- if MR4M_\mathrm{R4}MR4 accepts “CCC”, accept “AAA”“BBB”
- else reject
CNF
- A CFG G=(V,Σ,S,R)G=(V,\Sigma,S,R)G=(V,Σ,S,R) is in Chomsky Normal Form(CNF) if every of its rules is in the following forms:
- A→BCA\to BCA→BC, for A,B,C∈(V−Σ)A,B,C\in(V-\Sigma)A,B,C∈(V−Σ)
- A→aA\to aA→a, for A∈(V−Σ)A\in(V-\Sigma)A∈(V−Σ) and a∈Σa\in\Sigmaa∈Σ
- S→eS\to eS→e
- SSS does no appear in the RHS of a rule
Theroem: Every CFG has an equivalent CFG in CNF
- Given a CFG G=(V,Σ,S,R)G=(V,\Sigma,S,R)G=(V,Σ,S,R), convert it into CNF
- add a new start symbol S0S_0S0 and a new rule S0→SS_0\to SS0→S
- fix eee-rules: A→eA\to eA→e with A≠S0A\ne S_0A=S0
- fix short rules: A→BA\to BA→B with A,B∈(V−Σ)A,B\in(V-\Sigma)A,B∈(V−Σ)
- fix long rules: A→uA\to uA→u with u∈V∗u\in V^*u∈V∗ and ∣u∣>2|u|>2∣u∣>2
- fix A→u1u2A\to u_1u_2A→u1u2 with u1u_1u1 or u2u_2u2 as terminal
Observation: If CFG in CNF generates a string length n(n≥1)n(n\ge1)n(n≥1), it must take exactly 2n−12n-12n−1 steps
- A→BCA\to BCA→BC takes n−1n-1n−1 steps
- A→aA\to aA→a takes nnn steps
C1 Problem
- Language: ACFG={A_\mathrm{CFG}=\{ACFG={“GGG”“www”: GGG is a CFG that generates w}w\}w}
- MC1=M_\mathrm{C1}=MC1= on input “GGG”“www”
- convert GGG into an equivalent CFG G′G'G′ in CNF
- if ∣w∣=0|w|=0∣w∣=0
- if G′G'G′ has rule S→eS\to eS→e, accept “GGG”“www”
- else reject
- if ∣w∣≥1|w|\ge1∣w∣≥1, list all the derivations(finite, ≤∣R∣2∣w∣−1\le|R|^{2|w|-1}≤∣R∣2∣w∣−1) of length 2∣w∣−12|w|-12∣w∣−1
- if any listed derivation generates www, accept “GGG”“www”
- else reject
C2 Problem
- Language: APDA={A_\mathrm{PDA}=\{APDA={“PPP”“www”: PPP is a PDA that accepts w}w\}w}
- MC2=M_\mathrm{C2}=MC2= on input “PPP”“www”
- convert PPP into an equivalent CFG GGG
- run MC1M_\mathrm{C1}MC1 on “GGG”“www”
- if MC1M_\mathrm{C1}MC1 accepts “GGG”“www”, accept “PPP”“www”
- else reject
C3 Problem
- Language: ECFG={E_\mathrm{CFG}=\{ECFG={“GGG”: GGG is a CFG and L(G)=∅}L(G)=\varnothing\}L(G)=∅}
- MC3=M_\mathrm{C3}=MC3= on input “GGG”
- mark all the terminals and eee
- repeat the following until no new symbols are marked: for each LHS symbol of a rule, mark it if all the RHS symbols are marked
- if SSS is not marked, accept “GGG”
- else reject
Let f:A→Bf:A\to Bf:A→B be a function
- fff is injective if f(a)≠f(a′)f(a)\ne f(a')f(a)=f(a′) for any a≠a′a\ne a'a=a′
- fff is surjective if for any b∈Bb\in Bb∈B, there exists a∈Aa\in Aa∈A satisfying f(a)=bf(a)=bf(a)=b
- fff is bijective if fff is injective and surjective
Equinumerous
- Two sets AAA and BBB are equinumerous if there exists a bijection f:A→Bf:A\to Bf:A→B
- A set is countable if it is finite or it is equinumerous with ℵ\alephℵ, and uncountable otherwise
- Collary: any subset of a countable set is countable
Theorem: Let AAA be a set, the following statements are equivalent:
- a) AAA is countable
- b) there exists an injection f:A→ℵf:A\to\alephf:A→ℵ
- c) there exists some way to enumerate the elements of AAA such that each element is listed within finite steps
- Proof:
- a) => c): there exists a bijection f:A→ℵf:A\to\alephf:A→ℵ, list the elements of AAA in increasing order of f(a)f(a)f(a), any element a∈Aa\in Aa∈A can be listed in f(a)f(a)f(a) steps
- c) => b): for each a∈Aa\in Aa∈A, let f(a)f(a)f(a) be # of steps used to list aaa for the first time
- b) => a): there exists a injection f:A→ℵf:A\to\alephf:A→ℵ, sort elements of AAA in increasing order of f(a)f(a)f(a), let g(a)g(a)g(a) be the rank of aaa, which is bijective from AAA to ℵ\alephℵ
Theorem: Let Σ\SigmaΣ be an alphabet, Σ∗\Sigma^*Σ∗ is countable
- If Σ=∅\Sigma=\varnothingΣ=∅, Σ∗={e}\Sigma^*=\{e\}Σ∗={e} is countable
- Suppose Σ≠∅\Sigma\ne\varnothingΣ=∅, enumerate all strings in Σ∗\Sigma^*Σ∗ by increasing order of length
- A string of length iii can be listed within ∣Σ∣0+∣Σ∣1+∣Σ∣2+⋯+∣Σ∣i|\Sigma|^0+|\Sigma|^1+|\Sigma|^2+\cdots+|\Sigma|^i∣Σ∣0+∣Σ∣1+∣Σ∣2+⋯+∣Σ∣i steps
- ∣Σ∣k|\Sigma|^k∣Σ∣k denotes # of strings with length kkk
- Therefore Σk\Sigma^kΣk is countable
- Collary: the set of all Turing machines is countable
Theorem: Let Σ\SigmaΣ be some non-empty alphabet and L\mathcal{L}L be the set of all languages over Σ\SigmaΣ, L\mathcal{L}L is uncountable
- Supposed L\mathcal{L}L is countable, the languages in L\mathcal{L}L can be listed as L1,L2,L3,…L_1,L_2,L_3,\dotsL1,L2,L3,…
- Since Σ∗\Sigma^*Σ∗ is countable, the strings in Σ∗\Sigma^*Σ∗ can be listed as s1,s2,s3,…s_1,s_2,s_3,\dotss1,s2,s3,…
- Diagonalization: D={si:si∉Li}D=\{s_i:s_i\notin L_i\}D={si:si∈/Li} is a language over Σ\SigmaΣ
- for any si∈Ds_i\in Dsi∈D iff si∉Lis_i\notin L_isi∈/Li, therefore D≠LiD\ne L_iD=Li, therefore D∉LD\notin\mathcal{L}D∈/L
Recursive ⊊\subsetneq⊊ R.E.
Theorem: Let Σ\SigmaΣ be an alphabet, Σ∗\Sigma^*Σ∗ is countable
- If Σ=∅\Sigma=\varnothingΣ=∅, Σ∗={e}\Sigma^*=\{e\}Σ∗={e} is countable
- Suppose Σ≠∅\Sigma\ne\varnothingΣ=∅, enumerate all strings in Σ∗\Sigma^*Σ∗ by increasing order of length
- A string of length iii can be listed within ∣Σ∣0+∣Σ∣1+∣Σ∣2+⋯+∣Σ∣i|\Sigma|^0+|\Sigma|^1+|\Sigma|^2+\cdots+|\Sigma|^i∣Σ∣0+∣Σ∣1+∣Σ∣2+⋯+∣Σ∣i steps
- ∣Σ∣k|\Sigma|^k∣Σ∣k denotes # of strings with length kkk
- Therefore Σk\Sigma^kΣk is countable
- Collary: the set of all Turing machines is countable
Theorem: Let Σ\SigmaΣ be some non-empty alphabet and L\mathcal{L}L be the set of all languages over Σ\SigmaΣ, L\mathcal{L}L is uncountable
- Supposed L\mathcal{L}L is countable, the languages in L\mathcal{L}L can be listed as L1,L2,L3,…L_1,L_2,L_3,\dotsL1,L2,L3,…
- Since Σ∗\Sigma^*Σ∗ is countable, the strings in Σ∗\Sigma^*Σ∗ can be listed as s1,s2,s3,…s_1,s_2,s_3,\dotss1,s2,s3,…
- Diagonalization: D={si:si∉Li}D=\{s_i:s_i\notin L_i\}D={si:si∈/Li} is a language over Σ\SigmaΣ
- for any si∈Ds_i\in Dsi∈D iff si∉Lis_i\notin L_isi∈/Li, therefore D≠LiD\ne L_iD=Li, therefore D∉LD\notin\mathcal{L}D∈/L
If AAA and BBB are recursive, so is A∪BA\cup BA∪B
- M∪=M_\cup=M∪= on input “www”
- run MAM_\mathrm{A}MA and MBM_\mathrm{B}MB on “www”
- if at least one of them accepts www, accept “www”
- else reject
If AAA and BBB are recursive, so is A∘BA\circ BA∘B
- M∘=M_\circ=M∘= on input “www”
- enumerate all possible division (u,v)(u,v)(u,v) with uv=wuv=wuv=w
- run MAM_\mathrm{A}MA on uuu and MBM_\mathrm{B}MB on vvv
- if both of them accepts uuu and vvv, accept “www”
- else reject
If AAA and BBB are R.E., so is A∪BA\cup BA∪B
- M∪=M_\cup=M∪= on input “www”
- run MAM_\mathrm{A}MA and MBM_\mathrm{B}MB on “www”
- if one of them halts, halt
If AAA and BBB are R.E., so is A∘BA\circ BA∘B
- M∘=M_\circ=M∘= on input “www”
- non-deterministically divide www into uvuvuv
- run MAM_\mathrm{A}MA on uuu and MBM_\mathrm{B}MB on vvv
- if both of them halt, halt