250 likes | 505 Views
L ECTURE 6 Theory of Computation Proving that a language is not regular Pushdown automaton (PDA) Context-free grammar (CFG). Intro to Theory of Computation. CS 464. Sofya Raskhodnikova. THE PUMPING LEMMA. Let L be a regular language with |L| = .
E N D
LECTURE 6 • Theory of Computation • Proving that a language is not regular • Pushdown automaton (PDA) • Context-free grammar (CFG) Intro to Theory of Computation CS 464 Sofya Raskhodnikova SofyaRaskhodnikova; based on slides by Nick Hopper
THE PUMPING LEMMA Let L be a regular language with |L| = Then there exists a length p such that if w L and |w| ≥ p then w can be split into three parts w=xyz where: 1. |y| > 0 2. |xy| ≤ p 3. xyiz L for all i ≥ 0 Sofya Raskhodnikova; based on slides by Nick Hopper
GENERAL STRATEGY Proof by contradiction – assume L is regular Then there is a pumping length p Find a string w 2 L with |w| ¸p Show that no matter how an adversary choosesxyz, your w cannot be pumped! Conclude that L is not regular Sofya Raskhodnikova; based on slides by Nick Hopper
PUMPING DOWN USING THE PUMPING LEMMA: ProveC= { 0i1j | i > j ¸ 0} is not regular. Proof: Assume … pumping length p Find a w 2C longer than p 0P+11P Show that … w cannot be pumped: p p+1 w= 00…0011…11 y xz = 0…0011…11 xyyz = 00…00011…11 ·p > p+1 P P Sofya Raskhodnikova; based on slides by Nick Hopper
PUMPING DOWN ProveC= { 0i1j | i > j ¸ 0} is not regular. Proof: Assume … pumping length p Find a w 2C longer than p 0P+11P If w = xyz with |xy| ·p then y = 0J for some J¸ 1. Then xy0z = xz = 0P+1-J1P C Contradiction! xz = 0…0011…11 Sofya Raskhodnikova; based on slides by Nick Hopper
WHAT THE PUMPING LEMMA DOESN’T SAY - I For every p, w L with |w| ≥ p there exist xyz=w, where 1. |y| > 0 2. |xy| ≤ p 3. xyiz L for all i ≥ 0 Let L = 1*. L is regular. The string 10 cannot be pumped with p=1. You need to show that no matter what p is chosen, L has a string w, |w| ≥ p, that cannot be pumped. Sofya Raskhodnikova; based on slides by Nick Hopper
WHAT THE PUMPING LEMMA DOESN’T SAY - II For every xyz=w, where: 1. |y| > 0 2. |xy| ≤ p 3. xyiz L for all i ≥ 0 Example: Let L = 10*1*. Picking w = 10P1P; x=ε; y=10P; z=1P does not contradict pumping lemma! (You can pick x=1, y=0, z=0P-11P.) Sofya Raskhodnikova; based on slides by Nick Hopper
CHOOSING WISELY Let BALANCED = { w | w has an equal # of 1sand 0s } Assume … there is a p Find a w 2 BALANCED longer than p (01)P 0P1P Show that w cannot be pumped: If w = xyz with |xy| ·p then y = 0J for some J>0. Then xyyz = 0P+J1P BALANCED Sofya Raskhodnikova; based on slides by Nick Hopper
REUSING A PROOF Pumping a language can be lots of work… Let’s try to reuse that work! {0n1n : n ¸ 0} = BALANCED ∩ 0*1* If BALANCED is regular then so is {0n1n: n ¸ 0} Sofya Raskhodnikova; based on slides by Nick Hopper
USING CLOSURE Prove: A is not regular ∩ A C = B (Not regular) (regular) or any of {¢, [, ∩, :, R, *} If A is regular, then A ∩ C (= B) is regular. But B is not regular so neither is A. Sofya Raskhodnikova; based on slides by Nick Hopper
USINGCLOSURE: example Prove A = {0i1j : i j} is not regular using B = {0n1n : n¸0} :A = B [ { strings that mix 0s and 1s } :A ∩ 0*1* = B Sofya Raskhodnikova; based on slides by Nick Hopper
PUMPING NON-REGULAR LANGUAGES Let F = {aibjck | i, j, k ¸ 0 and i=1 ) j=k} F has pumping length 2! i = 0 i = 1 i = 2 HW3: prove that F is not regular. A non-regular language may still satisfy the pumping lemma. Sofya Raskhodnikova; based on slides by Nick Hopper
464 so far MODEL OF A PROBLEM: LANGUAGE MODEL OF A PROGRAM: DFA EQUIVALENT MODELS: NFA, REGEXP PROBLEMS THAT A DFA CAN’T SOLVE ARE WE DONE? Sofya Raskhodnikova; based on slides by Nick Hopper
NONE OF THESE ARE REGULAR • Σ = {0, 1}, L = { 0n1n | n ≥ 0 } • Σ = {a, b, c, …, z}, L = { w | w = wR } • Σ = { (, ) }, L = { balanced strings of parens } We can write a SCHEME or JAVA program for any of them! Sofya Raskhodnikova; based on slides by Nick Hopper
PUSHDOWNAUTOMATA (PDA) FINITE STATE CONTROL INPUT STACK (Last in, first out) Sofya Raskhodnikova; based on slides by Nick Hopper
string pop push ε,ε → $ 0,ε→ 0 11 0011 0011 011 1,0 →ε ε,$ → ε 1,0 →ε 1 0 STACK $ 0 $ $
string pop push ε,ε → $ 0,ε→ 0 1 001 001 01 1,0 →ε ε,$ → ε 1,0 →ε 0 STACK $ 0 $ $ PDA to recognize L = { 0n1n | n ≥ 0 }
Formal Definition A PDAis a 6-tuple P = (Q, Σ, Γ, , q0, F) Q is a finite set of states Σ is the alphabet Γis the stack alphabet : Q ΣεΓε → P(Q Γε) is the transition function q0 Q is the start state F Q is the set of accept states P(Q Γε) is the set of subsets of Q Γεand Σε = Σ {ε} Note: A PDA is defined to be nondeterministic. Sofya Raskhodnikova; based on slides by Nick Hopper
Formal Definition A PDAis a 6-tuple P = (Q, Σ, Γ, , q0, F) Q is a finite set of states Σ is the alphabet Γis the stack alphabet : Q ΣεΓε → P(Q Γε) is the transition function q0 Q is the start state F Q is the set of accept states A PDA starts with an empty stack. Itaccepts a string if at least one of its computational branches reads all the input and gets into an accept state at the end of it. Sofya Raskhodnikova; based on slides by Nick Hopper
ε,ε → $ 0,ε→ 0 q0 q1 1,0 →ε ε,$ → ε q3 q2 1,0 →ε Q = {q0, q1, q2, q3} Σ = {0,1} Γ = {$,0} : Q Σε Γε→ P(Q Γε) (q1,1,0) = { (q2,ε) } (q2,1,1) =
EVEN-LENGTH PALINDROMES Σ = {a, b, c, …, z} ε,ε → $ ,ε→ q0 q1 ε,ε→ε ε,$ → ε ,→ε q3 q2
q2 q3 q1 q4 q6 q5 Build a PDA to recognize L = { aibjck | i, j, k ≥ 0 and (i = j or i = k) } c,ε→ε b,a →ε q0 ε,$ → ε ε,ε → ε ε,ε → $ ε,ε → ε ε,ε → ε ε,$ → ε a,ε→ a b,ε→ε c,a →ε
CONTEXT-FREEGRAMMARS (CFGs) production rules start variable A → 0A1 A → B B → # variables terminals A 0A1 00A11 00B11 00#11 Sofya Raskhodnikova; based on slides by Nick Hopper
VALLEY GIRL GRAMMAR <PHRASE> → <FILLER><PHRASE> <PHRASE> → <START><END> <FILLER> → LIKE <FILLER> → UMM <START> → YOU KNOW <START> → ε <END> → GAG ME WITH A SPOON <END> → AS IF <END> → WHATEVER <END> → LOSER Sofya Raskhodnikova; based on slides by Nick Hopper