lecture5 - carnegie mellon universityokahn/flac-s15/lectures/lecture5.pdf · proof 1. let m be a...
TRANSCRIPT
![Page 1: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/1.jpg)
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
15-453
![Page 2: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/2.jpg)
THEOREMFor every regular language L, there exists a UNIQUE (up to re-labeling of the states) minimal DFA Mmim such that L = L(Mmim)
Minimal means wrt number of states
![Page 3: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/3.jpg)
PROOF1. Let M be a DFA for L (wlog, assume no
inaccessible states) 2. For pairs of states (p,q) define: p distinguishable from q and p indistinguisable from q (p~q). 3. Table-filling algorithm: first distinguish final from non-final states and then work backwards to distinguish more pairs. 4. What’s left over are exactly the indistinguishable pairs, ie ~ related pairs. Needs proof.
![Page 4: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/4.jpg)
5. ~ is an equivalence relation so partitions the states into equivalence classes, EM
6. Define Mmin
Define: MMIN = (QMIN, Σ, δMIN, q0 MIN, FMIN)
QMIN = EM, q0 MIN = [q0], FMIN = { [q] | q ∈ F }
δMIN( [q], σ ) = [ δ( q, σ ) ] show well defined
So: δMIN( [q0], w ) = [ δ( q0, w) ], w ∈ Σ*Claim: δMIN( [q], w ) = [ δ( q, w) ], w ∈ Σ*
Follows: MMIN ≡ M
PROOF
^ ^^ ^
![Page 5: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/5.jpg)
But is Mmin unique minimum?
Yes, because if M’ ≡ M and minimum then M’ has no inaccesible states and is irreducible and …. Theorem. Mmin is isomorphic to any M’ with the above properties (need to give mapping and prove it has all the needed properties: everywhere defined , well defined, 1-1, onto, preserves transitions, and {final states} map onto {final states})
So Mmin is isomorphic to any minimum M’ ≡ M
PROOF
![Page 6: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/6.jpg)
1 0
1
0
1
0,1
0
q0 q1
q3
q5
q4
0
1
q2
0,1q0
q0 q1
q1
q3
q3 q4
q4
D
DD
D
D Dq5
q5
D
D
D
![Page 7: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/7.jpg)
1 0
1
00,1
0
q0 q1
q3
q5
q4
0
1
q0
q0 q1
q1
q3
q3 q4
q4
D
DD
D
D Dq5
q5
D
D
D
![Page 8: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/8.jpg)
How can we prove that two DFAs are equivalent?
One way: Minimize
Another way: Let C = (¬A ∩ B) ∪ (A ∩ ¬B) Then, A = B ⇔ C = ∅
C is the “disjoint union”
![Page 9: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/9.jpg)
CONTEXT-FREE GRAMMARS AND PUSH-DOWN AUTOMATA
TUESDAY Jan 28
![Page 10: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/10.jpg)
Σ = {0, 1}, L = { 0n1n | n ≥ 0 }
Σ = {a, b, c, …, z}, L = { w | w = wR }
Σ = { (, ) }, L = { balanced strings of parens }
NONE OF THESE ARE REGULAR
(), ()(), (()()) are in L, (, ()), ())(() are not in L
![Page 11: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/11.jpg)
PUSHDOWN AUTOMATA (PDA)
FINITE STATE
CONTROL
STACK (Last in, first out)
INPUT
Newell, A., Shaw, J.C., & Simon, H.A. ”Report on a general problem-solving program in Information Processing”, Proc. International Conference, UNESCO Paris 1959
![Page 12: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/12.jpg)
PUSHDOWN AUTOMATA (PDA)
FINITE STATE
CONTROL
STACK (Last in, first out)
INPUT
A brief history of the stack, Sten Henriksson, Computer Science Department, Lund University, Lund, Sweden.
Turing ‘47
![Page 13: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/13.jpg)
ε,ε → $ 0,ε → 0
1,0 → ε
1,0 → εε,$ → ε
input pop push
0011
STACK $
0011011
$0
11
$0
1
Non-deterministic
![Page 14: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/14.jpg)
ε,ε → $ 0,ε → 0
1,0 → ε
1,0 → εε,$ → ε
input pop push
001
STACK $ $0 $0
101001
PDA that recognizes L = { 0n1n | n ≥ 0 }
![Page 15: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/15.jpg)
Definition: A (non-deterministic) PDA is a 6-tuple P = (Q, Σ, Γ, δ, q0, F), where:
Q is a finite set of states
Γ is the stack alphabet
q0 ∈ Q is the start state
F ⊆ Q is the set of accept states
Σ is the input alphabet
δ : Q × Σε × Γε → 2 Q × Γε
2Q × Γε is the set of subsets of Q × Γε Σε = Σ ∪ {ε}, Γε= Γ∪ {ε}
pushpop
![Page 16: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/16.jpg)
Let w∈ Σ* and suppose w can be written as w1... wn where wi ∈ Σε (recall Σε = Σ ∪ {ε})
Then P accepts w if there are r0, r1, ..., rn ∈ Q and s0, s1, ..., sn ∈ Γ* (sequence of stacks) such that
1. r0 = q0 and s0 = ε (P starts in q0 with empty stack)
2. For i = 0, ..., n-1: (ri+1 , b) ∈ δ(ri, wi+1, a), where si =at and si+1 = bt for
some a, b ∈ Γε and t ∈ Γ* (P moves correctly according to state, stack and symbol read)
3. rn ∈ F (P is in an accept state at the end of its input)
![Page 17: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/17.jpg)
ε,ε → $ 0,ε → 0
1,0 → ε
1,0 → εε,$ → ε
q0 q1
q2q3
Q = {q0, q1, q2, q3} Γ =Σ =
δ : Q × Σε × Γε → 2 Q × Γε
{0,1} {$,0,1}
δ(q1,1,0) = { (q2,ε) } δ(q2,1,1) = ∅
![Page 18: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/18.jpg)
EVEN-LENGTH PALINDROMES
Σ = {a, b, c, …, z}
ε,ε → $
ε,ε → ε
σ,σ → εε,$ → ε
q0 q1
q2q3
σ,ε → σ
zeus sees suez Madamimadam
(How to recognize odd-length palindromes?)
![Page 19: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/19.jpg)
Build a PDA to recognize L = { aibjck | i, j, k ≥ 0 and (i = j or i = k) }
ε,ε → $
q0
q1
a,ε → a
choose i=j
choose i=kε,ε
→ ε
ε,ε → ε
![Page 20: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/20.jpg)
Build a PDA to recognize L = { aibjck | i, j, k ≥ 0 and (i = j or i = k) }
ε,ε → $
b,a → ε
ε,$ → εq0
q1
q3
a,ε → a
q2
ε,ε →
ε
c,ε → ε
choose i=j
choose i=k
ε,ε → ε
![Page 21: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/21.jpg)
Build a PDA to recognize L = { aibjck | i, j, k ≥ 0 and (i = j or i = k) }
ε,ε → $
b,a → ε
ε,$ → εq0
q5q1
q3
a,ε → a
q2
q4
ε,ε →
ε
q6ε,ε → ε ε,ε → ε ε,$ → ε
b,ε → ε c,a → ε
c,ε → ε
choose i=j
choose i=k
![Page 22: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/22.jpg)
CONTEXT-FREE GRAMMARS
“Colorless green ideas sleep furiously.”
Noam Chomsky (1957)
![Page 23: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/23.jpg)
A → 0A1A → BB → #
CONTEXT-FREE GRAMMARS
A
variablesterminals
production rulesstart variable
⇒ 0A1 ⇒(yields)
⇒ 00A11 ⇒ 00B11 ⇒ 00#11
Non-deterministic
A ⇒* 00#11 (derives)
Derivation
We say: 00#11 is generated by the
Grammar
![Page 24: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/24.jpg)
A → 0A1A → BB → #
CONTEXT-FREE GRAMMARS
A ⇒ 0A1 ⇒(yields)
⇒ 00A11 ⇒ 00B11 ⇒ 00#11
Deterministic CFGs??
A ⇒* 00#11 (derives)
Derivation
We say: 00#11 is generated by the
Grammar
![Page 25: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/25.jpg)
CONTEXT-FREE GRAMMARS
A → 0A1A → BB → #
A → 0A1 | BB → #
![Page 26: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/26.jpg)
<PHRASE> → <START WORD><END WORD>DUDE<PHRASE> → <FILLER><PHRASE>
<FILLER> → LIKE<FILLER> → UMM<START WORD> → FO
<END WORD> → SHO<START WORD> → FA
<END WORD> → SHAZZY<END WORD> → SHEEZY
SNOOP’S GRAMMAR (courtesy of Luis von Ahn)
<END WORD> → SHIZZLE
![Page 27: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/27.jpg)
Generate:
Umm Like Umm Umm Fa Shizzle Dude
Fa Sho Dude
SNOOP’S GRAMMAR (courtesy of Luis von Ahn)
![Page 28: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/28.jpg)
CONTEXT-FREE GRAMMARSA context-free grammar (CFG) is a tuple G = (V, Σ, R, S), where:
V is a finite set of variables
R is set of production rules of the form A → W, where A ∈ V and W ∈ (V∪Σ)*
S ∈ V is the start variable
Σ is a finite set of terminals (disjoint from V)
![Page 29: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/29.jpg)
CONTEXT-FREE LANGUAGESA context-free grammar (CFG) is a tuple G = (V, Σ, R, S), where:
V is a finite set of variables
R is set of production rules of the form A → W, where A ∈ V and W ∈ (V∪Σ)*
S ∈ V is the start variable
Σ is a finite set of terminals (disjoint from V)
L(G) = {w ∈ Σ* | S ⇒* w} Strings Generated by G
A Language L is context-free if there is a CFG that generates precisely the strings in L
![Page 30: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/30.jpg)
A context-free grammar (CFG) is a tuple G = (V, Σ, R, S), where:
V is a finite set of variables
R is set of production rules of the form A → W, where A ∈ V and W ∈ (V∪Σ)*
S ∈ V is the start variable
Σ is a finite set of terminals (disjoint from V)
G = { {S}, {0,1}, R, S } R = { S → 0S1, S → ε }
L(G) =
CONTEXT-FREE LANGUAGES
![Page 31: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/31.jpg)
A context-free grammar (CFG) is a tuple G = (V, Σ, R, S), where:
V is a finite set of variables
R is set of production rules of the form A → W, where A ∈ V and W ∈ (V∪Σ)*
S ∈ V is the start variable
Σ is a finite set of terminals (disjoint from V)
G = { {S}, {0,1}, R, S } R = { S → 0S1, S → ε }
L(G) = { 0n1n | n ≥ 0 } Strings Generated by G
CONTEXT-FREE LANGUAGES
![Page 32: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/32.jpg)
WRITE A CFG FOR EVEN-LENGTH PALINDROMES
S → σSσ for all σ ∈ ΣS → ε
![Page 33: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/33.jpg)
WRITE A CFG FOR THE EMPTY SET
G = { {S}, Σ, ∅, S }
![Page 34: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/34.jpg)
PARSE TREES
A ⇒ 0A1⇒ 00A11 ⇒ 00B11 ⇒ 00#11
A
B
0 1#
A
A
0 1
A → 0A1A → BB → #
![Page 35: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/35.jpg)
<EXPR> → <EXPR> + <EXPR><EXPR> → <EXPR> x <EXPR><EXPR> → ( <EXPR> )<EXPR> → aBuild a parse tree for a + a x a
<EXPR>
a x+ a
<EXPR><EXPR>
a
<EXPR> <EXPR>
<EXPR>
a+ xa
<EXPR><EXPR>
a
<EXPR><EXPR>
![Page 36: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/36.jpg)
Definition: a string is derived ambiguously in a context-free grammar if it has more than one parse tree
Definition: a grammar is ambiguous if it generates some string ambiguously
See G4 for unambiguous standard arithmetic precedence [adds parens (,) ]
L = { aibjck | i, j, k ≥ 0 and (i = j or j = k) } is inherently ambiguous (xtra credit)
Undecidable to tell if a language has unambiguous parse trees (Post’s problem)
![Page 37: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/37.jpg)
Σ = {0, 1}, L = { 0n1n | n ≥ 0 }
WHAT ABOUT?
But L is CONTEXT FREE
NOT REGULAR
Σ = {0, 1}, L1 = { 0n1n 0m| m,n ≥ 0 }
Σ = {0, 1}, L2 = { 0n1m 0n| m,n ≥ 0 }
Σ = {0, 1}, L3 = { 0m1n 0n| m=n ≥ 0 }
A → 0A1A → ε
![Page 38: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/38.jpg)
WHAT ABOUT?
Σ = {0, 1}, L1 = { 0n1n 0m| m, n ≥ 0 }
Σ = {0, 1}, L2 = { 0n1m 0n| m, n ≥ 0 }
Σ = {0, 1}, L3 = { 0m1n 0n| m=n ≥ 0 }
![Page 39: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/39.jpg)
WHAT ABOUT?
S -> AB A -> 0A1 | ε B -> 0B | ε
S -> 0S0 | A A -> 1A | ε
Σ = {0, 1}, L1 = { 0n1n 0m| m, n ≥ 0 }
Σ = {0, 1}, L2 = { 0n1m 0n| m, n ≥ 0 }
Σ = {0, 1}, L3 = { 0m1n 0n| m=n ≥ 0 }
![Page 40: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/40.jpg)
THE PUMPING LEMMA FOR CFGsLet L be a context-free language
Then there is a P such that if w ∈ L and |w| ≥ P
1. |vy| > 0then can write w = uvxyz, where:
3. For every i ≥ 0, uvixyiz ∈ L2. |vxy| ≤ P
![Page 41: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/41.jpg)
WHAT ABOUT?
Σ = {0, 1}, L3 = { 0m1n 0n| m=n ≥ 0 }
Choose w = 0P 1P 0P.
By the Pumping Lemma, we can write w = uvxyz with |vy| > 0, |vxy| ≤ P such that pumping v together with y will produce another word in L3 Since |vxy| ≤ P, vxy = 0a1b, or vxy = 1a 0b.
![Page 42: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/42.jpg)
WHAT ABOUT?
Σ = {0, 1}, L3 = { 0m1n 0n| m=n ≥ 0 }
Pumping in the first case will unbalance with the 0’s at the end; in the second case, will unbalance with the 0’s at the beginning. Contradiction.
Choose w = 0P 1P 0P.
By the Pumping Lemma, we can write w = uvxyz with |vy| > 0, |vxy| ≤ P such that pumping v together with y will produce another word in L3 Since |vxy| ≤ P, vxy = 0a1b, or vxy = 1a 0b.
![Page 43: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/43.jpg)
THE PUMPING LEMMA FOR CFGsLet L be a context-free language
Then there is a P such that if w ∈ L and |w| ≥ P
1. |vy| > 0then can write w = uvxyz, where:
3. For every i ≥ 0, uvixyiz ∈ L2. |vxy| ≤ P
![Page 44: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/44.jpg)
Idea of Proof: If w is long enough, then any parse tree for w must have a path that contains a variable more than once
T
R
R
u v x zy
T
u z
R
R
v y
R
R
v x y
![Page 45: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/45.jpg)
If the height of a parse tree is h, the length of the string generated by that tree is at most:
Formal Proof:
Let b be the maximum number of symbols (length) on the right-hand side of any rule
bh
Let | V | be the number of variables in GDefine P = b|V|+1 Let w be a string of length at least P
Let T be a parse tree for w with a minimum number of nodes. b|V|+1 = P ≤ |w| ≤ bh
T must have height h at least |V|+1
![Page 46: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/46.jpg)
Let T be a parse tree for w with a minimum number of nodes. T must have height at least |V|+1
The longest path in T must have ≥ |V|+1 variablesSelect R to be a variable that repeats among the
lowest |V|+1 variables (in the path)T
R
R
u v x zy
T
u z
R
R
v y
R
R
v x y
1. |vy| > 02. |vxy| ≤ P
![Page 47: Lecture5 - Carnegie Mellon Universityokahn/flac-s15/lectures/Lecture5.pdf · PROOF 1. Let M be a DFA for L (wlog, assume no inaccessible states) 2. For pairs of states (p,q) define:](https://reader033.vdocuments.us/reader033/viewer/2022042300/5ecaac52e047113c4d484f7a/html5/thumbnails/47.jpg)
The longest path in T must have ≥ |V|+1 variables
Select R to be a variable in T that repeats, among the lowest |V|+1 variables in the tree
T
R
R
u v x zy
T
u z
R
R
v y
R
R
v x y
1. |vy| > 02. |vxy| ≤ P
since T has minimun # nodessince |vxy| ≤ b|V|+1 = P