Lecture 5
Lecture 5
Adnane Saoud
1
Summary of lecture 4
Lecture 4
§ Context free languages (CFLs)
§ Pushdown automata (PDA)
§ Converting CFGs to PDAs
Lecture 5
§ Proving languages not Context Free
§ Turing machines
2
Pumping Lemma for
Context-free
Languages
3
Proving languages not Context Free
∈𝐴
𝑢 𝑣 𝑣 𝑥 𝑦 𝑦 𝑧
≤𝑝 4
Pumping Lemma – Sketch of Proof
Pumping Lemma for CFLs: For every CFL 𝐴, there is a 𝑝
such that if 𝑠 ∈ 𝐴 and 𝑠 ≥ 𝑝 then 𝑠 = 𝑢𝑣𝑥𝑦𝑧 where
1) 𝑢𝑣 ! 𝑥𝑦 ! 𝑧 ∈ 𝐴 for all 𝑖 ≥ 0
2) 𝑣𝑦 ≠ ε
3) 𝑣𝑥𝑦 ≤ 𝑝
Proof by picture: E
𝑠= 𝑣 𝑦 𝑧
𝑢 𝑥 Long 𝑠 →
tall parse tree
5
Pumping Lemma – Sketch of Proof
Pumping Lemma for CFLs: For every CFL 𝐴, there is a 𝑝
such that if 𝑠 ∈ 𝐴 and 𝑠 ≥ 𝑝 then 𝑠 = 𝑢𝑣𝑥𝑦𝑧 where
1) 𝑢𝑣 ! 𝑥𝑦 ! 𝑧 ∈ 𝐴 for all 𝑖 ≥ 0
2) 𝑣𝑦 ≠ ε
3) 𝑣𝑥𝑦 ≤ 𝑝
Proof by picture: E
R
E
R
𝑢 𝑣 𝑦 𝑧 R
R
𝑥
𝑣 𝑥 𝑦
Generates 𝑢𝑣𝑣𝑥𝑦𝑦𝑧 𝑢 𝑧
Generates 𝑢𝑥𝑧
= 𝑢𝑣 ! 𝑥𝑦 ! 𝑧
= 𝑢𝑣 " 𝑥𝑦 " 𝑧
want
R ℎ> 𝑉
𝑠= 𝑢 𝑣 𝑥 𝑦 𝑧
use 𝑠 > 𝑏 # set 𝑝 = 𝑏 # + 1
want
R ℎ> 𝑉
𝑠= 𝑢 𝑣 𝑥 𝑦 𝑧
use 𝑠 > 𝑏 #
set 𝑝 = 𝑏 # + 1 8
Example 1 of Proving Non-CF
Pumping Lemma for CFLs: For every CFL 𝐴, there is a 𝑝
such that if 𝑠 ∈ 𝐴 and 𝑠 ≥ 𝑝 then 𝑠 = 𝑢𝑣𝑥𝑦𝑧 where
1) 𝑢𝑣 ! 𝑥𝑦 ! 𝑧 ∈ 𝐴 for all 𝑖 ≥ 0
2) 𝑣𝑦 ≠ ε
3) 𝑣𝑥𝑦 ≤ 𝑝
Let 𝐵 = 0! 1! 2! 𝑘 ≥ 0}
Show: 𝐵 is not a CFL 𝑠 = 00 ⋯ 0011 ⋯ 1122 ⋯ 22
Proof by Contradiction: 𝑢 𝑣 𝑥 𝑦 𝑧
≤𝑝
Assume (to get a contradiction) that 𝐵 is a CFL .
The CFL pumping lemma gives 𝑝 as above. Let 𝑠 = 0$ 1$ 2$ ∈ 𝐵.
Pumping lemma says that can divide 𝑠 = 𝑢𝑣𝑥𝑦𝑧 satisfying the 3 conditions.
Condition 3 ( 𝑣𝑥𝑦 ≤ 𝑝) implies that 𝑣𝑥𝑦 cannot contain both 0s and 2s.
So 𝑢𝑣 % 𝑥𝑦 % 𝑧 has unequal numbers of 0s, 1s, and 2s.
Thus 𝑢𝑣 % 𝑥𝑦 % 𝑧 ∉ 𝐵, violating Condition 1. Contradiction!
Therefore our assumption (𝐵 is a CFL) is false. We conclude that 𝐵 is not a CFL .
9
Example 2 of Proving Non-CF
Pumping Lemma for CFLs: For every CFL 𝐴, there is a 𝑝
such that if 𝑠 ∈ 𝐴 and 𝑠 ≥ 𝑝 then 𝑠 = 𝑢𝑣𝑥𝑦𝑧 where
1) 𝑢𝑣 ! 𝑥𝑦 ! 𝑧 ∈ 𝐴 for all 𝑖 ≥ 0
2) 𝑣𝑦 ≠ ε
3) 𝑣𝑥𝑦 ≤ 𝑝
Let 𝐹 = 𝑤𝑤 𝑤 ∈ Σ ∗ } . Σ = {0,1}.
Show: 𝐹 is not a CFL.
𝑠% = 0 ⋯ 01 ⋯ 10 ⋯ 01 ⋯ 1
Assume (for contradiction) that 𝐹 is a CFL. 𝑢 𝑣 𝑥 𝑦 𝑧
The CFL pumping lemma gives 𝑝 as above.
Need to choose 𝑠 ∈ 𝐹. Which 𝑠?
Try 𝑠% = 0$ 1$ 0$ 1$ ∈ 𝐹.
Show 𝑠% cannot be pumped 𝑠% = 𝑢𝑣𝑥𝑦𝑧 satisfying the 3 conditions.
Condition 3 implies that 𝑣𝑥𝑦 does not overlap two runs of 0s or two runs of 1s.
Therefore, in 𝑢𝑣 % 𝑥𝑦 % 𝑧, two runs of 0s or two runs of 1s have unequal length.
So 𝑢𝑣 % 𝑥𝑦 % 𝑧 ∉ 𝐹 violating Condition 1. Contradiction! Thus 𝐹 is not a CFL.
10
CFG are not Closed Under Union
11
Turing machines
12
Turing Machines (TMs)
head
a b a b b ˽ ˽ ...
Finite
control read/write input tape
13
TM – example
TM recognizing 𝐵 = a! b! c! 𝑘 ≥ 0
1) Scan right until ˽ while checking if input is in a∗b∗c∗, reject if not.
2) Return head to left end.
3) Scan right, crossing off single a, b, and c.
4) If the last one of each symbol, accept.
5) If the last one of some symbol but not others, reject.
6) If all symbols remain, return to left end and repeat from (3).
head
input tape
Finite a a a b b b c c c ˽ ˽
control
accept
14
TM – example
Exercise:
How do we get the effect of “crossing off” with a Turing machine?
a) We add that feature to the model.
b) We use a tape alphabet Γ = {a, b, c, a, b, c, ˽ }.
c) All Turing machines come with an eraser.
15
TM – Formal Definition
16
TM Recognizers and Deciders
input tape
Finite
control
} work tapes, initially blank
...
all tapes read/write
18
Multi-tape Turing machines
a a b b a ˽ ˽ ...
multi-tape 𝑀 1 0 1 ˽ ...
...
c c c a ˽ ...
single tape 𝑆 a a b b a # 1 0 1 # … # c c c a ˽ ˽
19
Summary
20
Summary
21