Presentation is loading. Please wait.

Presentation is loading. Please wait.

Costas Busch - LSU1 Pumping Lemma for Context-free Languages.

Similar presentations


Presentation on theme: "Costas Busch - LSU1 Pumping Lemma for Context-free Languages."— Presentation transcript:

1 Costas Busch - LSU1 Pumping Lemma for Context-free Languages

2 Costas Busch - LSU2 Take an infinite context-free language Example: Generates an infinite number of different strings

3 Costas Busch - LSU3 A possible derivation: In a derivation of a “long” enough string, variables are repeated

4 Costas Busch - LSU4 Derivation Tree Repeated variable

5 Costas Busch - LSU5 Derivation Tree Repeated variable

6 Costas Busch - LSU6

7 7

8 8

9 9 Putting all together

10 Costas Busch - LSU10 We can remove the middle part

11 Costas Busch - LSU11

12 Costas Busch - LSU12 We can repeated middle part two times 1 2

13 Costas Busch - LSU13

14 Costas Busch - LSU14 We can repeat middle part three times 1 2 3

15 Costas Busch - LSU15

16 Costas Busch - LSU16 Repeat middle part times i 1

17 Costas Busch - LSU17 For any

18 Costas Busch - LSU18 From Grammar and given string We inferred that a family of strings is in for any

19 Costas Busch - LSU19 Arbitrary Grammars Consider now an arbitrary infinite context-free language Take so that it has no unit-productions and no -productions Let be the grammar of (remove them)

20 Costas Busch - LSU20 Let be the number of variables Let be the maximum right-hand size of any production Example:

21 Costas Busch - LSU21 Take string with. Then in the derivation tree of there is a path from the root to a leaf where a variable of is repeated Claim: Proof: Proof by contradiction

22 Costas Busch - LSU22 Derivation tree of some variable is repeated We will show:

23 Costas Busch - LSU23 First we show that the tree of has at least levels of nodes Suppose the opposite: Levels At most

24 Costas Busch - LSU24 Level 0: Level 1: nodes Maximum number of nodes per level nodes The maximum right-hand side of any production

25 Costas Busch - LSU25 Level 0: Level 1: nodes Level 2: Maximum number of nodes per level

26 Costas Busch - LSU26 nodesLevel : Levels nodesLevel : Maximum possible string length = max nodes at level = Maximum number of nodes per level Level 0:nodes At most

27 Costas Busch - LSU27 Therefore, maximum length of string : However we took, Contradiction!!! Therefore, the tree must have at least levels

28 Costas Busch - LSU28 Thus, there is a path from the root to a leaf with at least nodes Levels At least symbol Variables (root) (leaf)

29 Costas Busch - LSU29 Since there are at most different variables, some variable is repeated Pigeonhole principle END OF CLAIM PROOF

30 Costas Busch - LSU30 Take now a stringwith some variable is repeated Take to be the deepest, so that only is repeated in subtree subtree of From claim:

31 Costas Busch - LSU31 Strings of terminals yield We can write

32 Costas Busch - LSU32 Example:

33 Costas Busch - LSU33 Possible derivations

34 Costas Busch - LSU34 Example:

35 Costas Busch - LSU35 Remove Middle Part Yield:

36 Costas Busch - LSU36 Repeat Middle part two times 1 2 Yield:

37 Costas Busch - LSU37

38 Costas Busch - LSU38 Repeat Middle part times 1 i Yield:

39 Costas Busch - LSU39

40 Costas Busch - LSU40 If we know that: then we also know: Therefore, For all since

41 Costas Busch - LSU41 Observation 1: Since has no unit and -productions At least one of or is not

42 Costas Busch - LSU42 Observation 2: since in subtree only variable is repeated subtree of Explanation follows….

43 Costas Busch - LSU43 subtree of Various yields since no variable is repeated in Maximum right-hand side of any production

44 Costas Busch - LSU44 Thus, if we choose critical length then, we obtain the pumping lemma for context-free languages

45 Costas Busch - LSU45 The Pumping Lemma: there exists an integer such that for any string we can write For any infinite context-free language with lengths and it must be that:

46 Costas Busch - LSU46 Applications of The Pumping Lemma

47 Costas Busch - LSU47 Context-free languages Non-context free languages

48 Costas Busch - LSU48 Theorem: The language is not context free Proof: Use the Pumping Lemma for context-free languages

49 Costas Busch - LSU49 Assume for contradiction that is context-free Since is context-free and infinite we can apply the pumping lemma

50 Costas Busch - LSU50 Let be the critical length of the pumping lemma Pick any string with length We pick:

51 Costas Busch - LSU51 we can write: with lengths and From pumping lemma:

52 Costas Busch - LSU52 Pumping Lemma says: for all

53 Costas Busch - LSU53 We examine all the possible locations of string in

54 Costas Busch - LSU54 Case 1: is in

55 Costas Busch - LSU55

56 Costas Busch - LSU56

57 Costas Busch - LSU57 From Pumping Lemma: However: Contradiction!!!

58 Costas Busch - LSU58 Case 2: is in Similar to case 1

59 Costas Busch - LSU59 Case 3: is in Similar to case 1

60 Costas Busch - LSU60 Case 4: overlaps and

61 Costas Busch - LSU61 Sub-case 1:contains only

62 Costas Busch - LSU62

63 Costas Busch - LSU63

64 Costas Busch - LSU64 From Pumping Lemma: However: Contradiction!!!

65 Costas Busch - LSU65 Sub-case 2:contains and contains only

66 Costas Busch - LSU66 By assumption

67 Costas Busch - LSU67

68 Costas Busch - LSU68 From Pumping Lemma: However: Contradiction!!!

69 Costas Busch - LSU69 Sub-case 3:contains only contains and Similar to sub-case 2

70 Costas Busch - LSU70 Case 5: overlaps and Similar to case 4

71 Costas Busch - LSU71 Case 6: overlaps, and Impossible!

72 Costas Busch - LSU72 In all cases we obtained a contradiction Therefore: the original assumption that is context-free must be wrong Conclusion:is not context-free


Download ppt "Costas Busch - LSU1 Pumping Lemma for Context-free Languages."

Similar presentations


Ads by Google