Presentation is loading. Please wait.

# 1 The Pumping Lemma for Context-Free Languages. 2 Take an infinite context-free language Example: Generates an infinite number of different strings.

## Presentation on theme: "1 The Pumping Lemma for Context-Free Languages. 2 Take an infinite context-free language Example: Generates an infinite number of different strings."— Presentation transcript:

1 The Pumping Lemma for Context-Free Languages

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

3 A derivation: In a derivation of a long string, variables are repeated

4 Derivation treestring

5 repeated Derivation treestring

6

7 Repeated Part

8 Another possible derivation from

9

10 A Derivation from

11

12

13 A Derivation from

14

15

16

17

18 A Derivation from

19

20

21

22 In General:

23 Consider now an infinite context-free language Take so that I has no unit-productions no -productions Let be the grammar of

24 (Number of productions) x (Largest right side of a production) = Let Example : Let

25 Take a string with length We will show: in the derivation of a variable of is repeated

26

27 maximum right hand side of any production

28 Number of productions in grammar

29 Number of productions in grammar Some production must be repeated Repeated variable

30 Some variable is repeated Derivation of string

31 Last repeated variable repeated Strings of terminals Derivation tree of string

32 Possible derivations:

33 We know: This string is also generated:

34 This string is also generated: The original We know:

35 This string is also generated: We know:

36 This string is also generated: We know:

37 This string is also generated: We know:

38 Therefore, any string of the form is generated by the grammar

39 knowing that we also know that Therefore,

40 Observation: Since is the last repeated variable

41 Observation: Since there are no unit or -productions

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

43 Applications of The Pumping Lemma

44 Context-free languages Non-context free languages

45 Theorem: The language is not context free Proof: Use the Pumping Lemma for context-free languages

46 Assume for contradiction that is context-free Since is context-free and infinite we can apply the pumping lemma

47 Pumping Lemma gives a magic number such that: Pick any string with length We pick:

48 We can write: with lengths and

49 Pumping Lemma says: for all

50 We examine all the possible locations of string in

51 Case 1: is within

52 Case 1: and consist from only

53 Case 1: Repeating and

54 Case 1: From Pumping Lemma:

55 Case 1: From Pumping Lemma: However: Contradiction!!!

56 Case 2: is within

57 Case 2: Similar analysis with case 1

58 Case 3: is within

59 Case 3: Similar analysis with case 1

60 Case 4: overlaps and

61 Case 4: Possibility 1:contains only

62 Case 4: Possibility 1:contains only

63 Case 4: From Pumping Lemma:

64 Case 4: From Pumping Lemma: However: Contradiction!!!

65 Case 4: Possibility 2:contains and contains only

66 Case 4: Possibility 2:contains and contains only

67 Case 4: From Pumping Lemma:

68 Case 4: From Pumping Lemma: However: Contradiction!!!

69 Case 4: Possibility 3:contains only contains and

70 Case 4: Possibility 3:contains only contains and Similar analysis with Possibility 2

71 Case 5: overlaps and

72 Case 5: Similar analysis with case 4

73 There are no other cases to consider (since, string cannot overlap, and at the same time)

74 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 "1 The Pumping Lemma for Context-Free Languages. 2 Take an infinite context-free language Example: Generates an infinite number of different strings."

Similar presentations

Ads by Google