Transcript powerpoint
The Pumping Lemma for Context-Free Languages 1 Take an infinite context-free language Generates an infinite number of different strings Example: S AB A aBb B Sb Bb 2 S AB A aBb B Sb Bb A derivation: S AB aBbB abbB abbSb abbABb abbaBbBb abbabbBb abbabbbb 3 Derivation tree S A a B B b b S A b a B b B b b 4 Derivation tree S A a B B b A b a repeated b S B b B b b 5 B B Sb ABb aBbBb aBbbb A a Bb B b S B b b b 6 Repeated part B b S A a B B b b B aBbbb 7 A possible derivation B b S A B a a B B b b b b S A B B aBbbb b B aBbbb aaBbbbbbb 8 S A a B B b b S b A a B B b b S abbaBbbb B aBbbb 9 S A a B b B b A B a A B B b b b S a b S B b b B aBbbb S abbaBbbb abbaaBbbbbbb 10 S A a B b B b A B a A B B b b b S a b S B b b Bb b S abbaaBbbbbbb abbaabbbbbbb 11 S abbaabbbbbbb Therefore, the string abbaabbbbbbb is generated by the grammar 12 We know B b B aBbbb S abbaBbbb This string is also generated: S abbaBbbb abba(a ) B(bbb)bbb 2 2 2 2 abba(a ) B(bbb) bbb abba(a ) b(bbb) bbb 13 We know B b B aBbbb S abbaBbbb This string is also generated: S abbaBbbb i i i i abba (a ) B(bbb) bbb abba (a ) b(bbb) bbb 14 Therefore, knowing that abbabbbb is generated, we also know that i i abba (a ) b(bbb) bbb is generated 15 In general: We are given an infinite context-free grammar G We take the derivation of a long enough string w 16 Take the length of m w Bigger than = Productions * (largest production) Some variable must be repeated in the derivation 17 u, v, x, y, z : strings of terminals S z u A y v A repeated w uvxyz x 18 S Possible derivations: z u A S uAz A vAy y v A repeated A x x 19 We know: S uAz A vAy A x This string is also generated: S uAz uxz 0 0 uv xy z 20 We know: S uAz A vAy A x This string is also generated: S uAz uvAyz uvxyz (the original w uv xy z ) 1 1 21 We know: S uAz A vAy A x This string is also generated: S uAz uvAyz uvvAyyz uvvxyyz 2 2 uv xy z 22 We know: S uAz A vAy A x This string is also generated: S uAz uvAyz uvvAyyz uvvvAyyyz uvvvxyyyz 3 3 uv xy z 23 We know: S uAz A vAy A x This string is also generated: S uAz uvAyz uvvAyyz uvvvAyyyz uvvv vAy yyyz uvvv vxy yyyz i i uv xy z 24 Therefore, any string of the form i i uv xy z Is generated by the grammar i0 G 25 Therefore, knowing that uvxyz L(G ) we also know that i i uv xy z L(G ) 26 S z u A y v A x | vxy | m 27 S z u A y v A x | vy | 1 28 The pumping lemma: For context-free language L there exists an integer w L, for any string we can write | w | m w uvxyz with | vxy | m, Such that: m | vy | 1 i i uv xy z L 29