Lec 6
Lec 6
Last time:
- Context free grammars (CFGs)
- Context free languages (CFLs)
- Pushdown automata (PDA)
- Converting CFGs to PDAs
Today:
- Proving languages not Context Free
- Turing machines
- T-recognizable and T-decidable languages
1
Equivalence of CFGs and PDAs
Recall Theorem: is a CFL iff some PDA recognizes
Done.
Need to know the fact, not the proof
Corollaries:
1) Every regular language is a CFL.
2) If is a CFL and is regular then is a CFL.
Proof sketch of (2):
While reading the input, the finite control of the PDA for simulates the DFA for .
Note 1: If and are CFLs then may not be a CFL (will show today).
Therefore the class of CFLs is not closed under .
Note 2: The class of CFLs is closed under (see Pset 2).
2
Proving languages not Context Free
Let . We will show that isn’t a CFL.
3
Pumping Lemma – Proof
Pumping Lemma for CFLs: For every CFL , there is a
such that if and then where
1) for all
2)
3) E
Proof by picture: E R
E
R
𝑢
𝑣 R
𝑦 𝑧
R
R 𝑥
𝑣 𝑥 𝑦 𝑢 𝑧
R Generates Generates
𝑠=¿ 𝑦 𝑧
𝑢 𝑣 𝑥 Long “cutting and pasting” argument
tall parse tree
4
Pumping Lemma – Proof details
For where , we have where:
1) for all …cutting and pasting
2) …start with the smallest parse tree for
3) …pick the lowest repetition of a variable
Let the length of the longest right hand side of a rule (E E+T)
the max branching of the parse tree E
E
Let the height of the parse tree for . E+T
A tree of height and max branching has at most leaves. want
So . R
Let where # variables in the grammar.
So if then and so . R
Let
Show: is not a CFL
Proof by Contradiction:
Check-in
Assume (to 5.1
get a contradiction) that is a CFL .
LetCFL(equal
The pumping #s oflemma
0s andgives
1s) as above. Let . 𝑠=¿00 ⋯ 0011⋯ 1122⋯ 22
Let (equal #s of 1s that
and can
2s) divide satisfying the 3 conditions.
Pumping lemma says 𝑢 𝑣𝑥𝑦 𝑧
Observe 3that
Condition () PDAs
impliescan recognize
that and . What
cannot contain bothcan we now
0s and 2s. conclude? ≤𝑝
Soa) has
Theunequal
class ofnumbers
CFLs is not
of closed
0s, 1s, under
and 2s.intersection.
b) ,The
Thus Pumping
violating Lemma1.shows
Condition that is not a CFL .
Contradiction!
c) The class
Therefore of CFLs is closed
our assumption under
( is a CFL) is complement.
false. We conclude that is not a CFL .
6 Check-in 5.1
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
2)
3)
Let .
Show: is not a CFL.
𝑠1=¿
000 ⋯ 001000 ⋯ 001
Assume (for contradiction) that is a CFL.
The CFL pumping lemma gives as above. Need to choose . Which ? 𝑢 𝑣𝑥𝑦 𝑧
Try . But can be pumped and stay inside . Bad choice of .
Try . 𝑠2 =¿
0 ⋯ 01 ⋯ 10 ⋯ 01⋯ 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.
7
Turing Machines (TMs)
head
a b a b b ˽ ˽ ...
Finite
control read/write input tape
8
TM – example
TM recognizing
1) Scan right until ˽ while checking if input is in , reject if not.
head
2) Return head to left end. input tape
3) Scan right, crossing off single a, b, and c. a a a b b b c c c ˽ ˽
Finite
4) If the last one of each symbol, accept. control
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). accept
Check-in 5.2
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 , , , , , , ˽ }.
c) All Turing machines come with an eraser.
9 Check-in 5.2
TM – Formal Definition
Defn: A Turing Machine (TM) is a 7-tuple
input alphabet
tape alphabet ()
{L, R} (L = Left, R = Right)
R
10 Check-in 5.3
TM Recognizers and Deciders
Let be a TM. Then accepts .
Say that recognizes if .
Defn: is Turing-recognizable if for some TM .
CFLs
regular
11
Quick review of today
12