more applications
play

More Applications for any string w L , | w | m of The - PDF document

Review Languages and Grammars Alphabets, strings, languages Regular Languages CS 301 - Lecture 17 Deterministic Finite and Nondeterministic Automata Equivalence of NFA and DFA Pumping Lemma for Regular Expressions


  1. Review • Languages and Grammars – Alphabets, strings, languages • Regular Languages CS 301 - Lecture 17 – Deterministic Finite and Nondeterministic Automata – Equivalence of NFA and DFA Pumping Lemma for – Regular Expressions – Regular Grammars – Properties of Regular Languages Context Free Grammars – Languages that are not regular and the pumping lemma • Context Free Languages Fall 2008 – Context Free Grammars – Derivations: leftmost, rightmost and derivation trees – Parsing and ambiguity – Simplifications and Normal Forms – Nondeterministic Pushdown Automata – Pushdown Automata and Context Free Grammars – Deterministic Pushdown Automata • Today: – Pumping Lemma for context free grammars The Pumping Lemma: L For infinite context-free language m there exists an integer such that More Applications • for any string w L , | w | m of ∈ ≥ The Pumping Lemma w = uvxyz we can write with lengths | vxy | m and | vy | 1 ≤ ≥ and it must be: i i uv xy z L , for all i 0 ∈ ≥ 1

  2. Non-context free languages Theorem: The language n n n { vv : v { a , b }} { a b c : n 0 } L { vv : v { a , b }*} ≥ ∈ = ∈ is not context free Context-free languages n n ww R { a b : n 0 } { : w { a , b }*} Proof: ≥ ∈ Use the Pumping Lemma for context-free languages L { vv : v { a , b }*} L { vv : v { a , b }*} = ∈ = ∈ m Pumping Lemma gives a magic number L Assume for contradiction that such that: is context-free L m Pick any string of with length at least L Since is context-free and infinite m m m m a b a b L we pick: we can apply the pumping lemma ∈ 2

  3. L { vv : v { a , b }*} L { vv : v { a , b }*} = ∈ = ∈ m m m m a b a b uvxyz | vxy ≤ | m | vy | 1 ≥ = m m m m a b a b uvxyz We can write: = | vxy ≤ | m | vy | 1 with lengths and ≥ We examine all the possible locations m m m m of string in vxy a b a b Pumping Lemma says: i i uv xy z L for all i 0 ∈ ≥ L { vv : v { a , b }*} L { vv : v { a , b }*} = ∈ = ∈ m m m m m m m m | vxy ≤ | m | vy | 1 | vxy ≤ | m | vy | 1 a b a b uvxyz a b a b uvxyz ≥ ≥ = = m m Case 1: vxy Case 1: vxy is within the first a is within the first a k k k k k + k 1 k + k 1 y = a 2 y = a 2 v = a 1 v = a 1 ≥ ≥ 1 2 1 2 m m m m m m m m k k + + 1 2 a ...... a b ...... b a ...... a b ...... b a .......... ...... a b ...... b a ...... a b ...... b u v x y z u x z 2 2 v y 3

  4. L { vv : v { a , b }*} L { vv : v { a , b }*} = ∈ = ∈ m m m m m m m m a b a b uvxyz | vxy ≤ | m | vy | 1 a b a b uvxyz | vxy ≤ | m | vy | 1 ≥ ≥ = = m m Case 1: vxy a Case 1: vxy a is within the first is within the first m k k m m m 2 2 m k k m m m 2 2 + + + + a 1 2 b a b uv xy z L a 1 2 b a b uv xy z L = ∉ = ∉ 2 2 k + k 1 uv xy z L However, from Pumping Lemma: ≥ ∈ 1 2 Contradiction!!! L { vv : v { a , b }*} L { vv : v { a , b }*} = ∈ = ∈ m m m m m m m m a b a b uvxyz | vxy ≤ | m | vy | 1 a b a b uvxyz | vxy ≤ | m | vy | 1 = ≥ = ≥ m m Case 2: v a Case 2: v a is in the first is in the first m m y b y b is in the first is in the first k k k k k + k 1 k + k 1 y = b 2 y = b 2 v = a 1 ≥ v = a 1 ≥ 1 2 1 2 m m m m m + k m + k m m 1 2 a ...... a b ...... b a ...... a b ...... b a .......... .. a b .......... .. b a ...... a b ...... b u v x y z u 2 x 2 z v y 4

  5. L { vv : v { a , b }*} L { vv : v { a , b }*} = ∈ = ∈ m m m m m m m m | vxy ≤ | m | vy | 1 | vxy ≤ | m | vy | 1 a b a b uvxyz a b a b uvxyz = ≥ = ≥ m m Case 2: v a Case 2: v a is in the first is in the first m m y b y b is in the first is in the first m k m k m m 2 2 m k m k m m 2 2 + + + + a 1 b 2 a b uv xy z L a 1 b 2 a b uv xy z L = ∉ = ∉ 2 2 uv xy z L However, from Pumping Lemma: ∈ k + k 1 ≥ 1 2 Contradiction!!! L { vv : v { a , b }*} L { vv : v { a , b }*} = ∈ = ∈ m m m m m m m m a b a b uvxyz | vxy ≤ | m | vy | 1 a b a b uvxyz | vxy ≤ | m | vy | 1 = ≥ = ≥ m b m m b m Case 3: v a Case 3: v a overlaps the first overlaps the first m m y b y b is in the first is in the first k b k b 1 k 1 k k k v = a 2 y = b 3 k , 2 k 1 v = a 2 y = b 3 k , 2 k 1 ≥ ≥ 1 1 m m m m k k m + k m m m 2 1 3 a ...... a b ...... b a ...... a b ...... b a ...... a b ... b a ... a b ......... b a ...... a b ...... b u u v x y z 2 2 z x v y 5

  6. L { vv : v { a , b }*} L { vv : v { a , b }*} = ∈ = ∈ m m m m m m m m | vxy ≤ | m | vy | 1 | vxy ≤ | m | vy | 1 a b a b uvxyz a b a b uvxyz = ≥ = ≥ m b m m b m Case 3: v a Case 3: v a overlaps the first overlaps the first m m y b y b is in the first is in the first m k k m k m m 2 2 m k k k m m 2 2 + a b 2 a 1 b 3 a b uv xy z L a b 2 a 1 b 3 a b uv xy z L = ∉ = ∉ 2 2 uv xy z L However, from Pumping Lemma: ∈ k , 2 k 1 ≥ 1 Contradiction!!! L { vv : v { a , b }*} m m m m = ∈ Other cases: vxy a b a b is within m m m m a b a b uvxyz | vxy ≤ | m | vy | 1 = ≥ or m Case 4: v a in the first m m m m a b a b m b m y a Overlaps the first or Analysis is similar to case 3 m m m m a b a b m m m m Analysis is similar to case 1: a ...... a b ...... b a ...... a b ...... b m m m m a b a b u v x y z 6

  7. m m m m There are no other cases to consider More cases: vxy a b a b overlaps or Since , it is impossible | vxy ≤ | m to overlap: vxy m m m m a b a b m m m m a b a b nor m m m m a b a b Analysis is similar to cases 2,3,4: nor m m m m a b a b m m m m a b a b Non-context free languages In all cases we obtained a contradiction n n n { ww : w { a , b }} ∈ { a b c : n 0 } ≥ a n ! { : n 0 } ≥ Therefore: The original assumption that L { vv : v { a , b }*} = ∈ Context-free languages is context-free must be wrong n n ww R { a b : n 0 } { : w { a , b }*} ≥ ∈ Conclusion: L is not context-free 7

  8. n ! L { a : n 0 } = ≥ Theorem: The language n ! L { a : n 0 } = ≥ Assume for contradiction that L is not context free is context-free Proof: Use the Pumping Lemma L Since is context-free and infinite for context-free languages we can apply the pumping lemma n ! n ! L { a : n 0 } L { a : n 0 } = ≥ = ≥ m Pumping Lemma gives a magic number a m = ! uvxyz We can write: such that: | vxy ≤ | m | vy | 1 with lengths and ≥ L m Pick any string of with length at least Pumping Lemma says: a m ∈ ! L we pick: i i uv xy z L for all i 0 ∈ ≥ 8

  9. n ! n ! L { a : n 0 } L { a : n 0 } = ≥ = ≥ a m = ! a m = ! uvxyz | vxy ≤ | m | vy | 1 uvxyz | vxy ≤ | m | vy | 1 ≥ ≥ m ! a .......... ..... a We examine all the possible locations m ! of string in vxy a u v x y z k k 1 k k m v = a 1 y = a 2 ≤ + ≤ There is only one case to consider 1 2 n ! n ! L { a : n 0 } L { a : n 0 } = ≥ = ≥ a m = ! a m = ! | vxy ≤ | m | vy | 1 | vxy ≤ | m | vy | 1 uvxyz uvxyz ≥ ≥ m ! k k m + ! k + + k k k = + 1 2 1 2 a .......... .......... ....... a a .......... .......... ....... a u x z u x z 2 2 2 2 y y v v k k k k 1 k k m 1 k ≤ m v = a 1 y = a 2 ≤ + ≤ v = a 1 y = a 2 ≤ 1 2 9

  10. n ! L { a : n 0 } = ≥ m 2 Since , for we have: 1 k ≤ m ≤ ≥ a m = ! uvxyz | vxy ≤ | m | vy | 1 m ! k m ! m ≥ + ≤ + m ! m ! m < + m ! ( 1 m ) = + m ! k 2 2 + a uv xy z = ( m 1 )! = + 1 k ≤ m ≤ m ! m ! k ( m 1 )! < + < + n ! n ! L { a : n 0 } L { a : n 0 } = ≥ = ≥ a m = ! a m = ! | vxy ≤ | m | vy | 1 | vxy ≤ | m | vy | 1 uvxyz uvxyz ≥ ≥ m ! m ! k ( m 1 )! < + < + 2 2 uv xy z L However, from Pumping Lemma: ∈ m ! k 2 2 m ! k 2 2 + + a uv xy z L a uv xy z L = ∉ = ∉ Contradiction!!! 10

Recommend


More recommend