Presentation is loading. Please wait.

Presentation is loading. Please wait.

Applications of Regular Closure

Similar presentations


Presentation on theme: "Applications of Regular Closure"— Presentation transcript:

1 Applications of Regular Closure

2 The intersection of a context-free language and a regular language is a context-free language Regular Closure context free regular context-free

3 An Application of Regular Closure
Prove that: is context-free

4 We know: is context-free

5 We also know: is regular is regular

6 context-free regular (regular closure) is context-free is context-free

7 Another Application of Regular Closure
Prove that: is not context-free

8 Impossible!!! If is context-free Then context-free regular
(regular closure) Then context-free regular context-free Impossible!!! Therefore, is not context free

9 Decidable Properties of Context-Free Languages

10 Membership Question: for context-free grammar find if string Membership Algorithms: Parsers Exhaustive search parser CYK parsing algorithm

11 Empty Language Question:
for context-free grammar find if Algorithm: Remove useless variables Check if start variable is useless

12 Infinite Language Question:
for context-free grammar find if is infinite Algorithm: 1. Remove useless variables 2. Remove unit and productions 3. Create dependency graph for variables 4. If there is a loop in the dependency graph then the language is infinite

13 Example: Infinite language Dependency graph

14

15 The Pumping Lemma for Context-Free Languages

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

17 Variables are repeated
A derivation:

18 Derivation tree string

19 Derivation tree string repeated

20

21 Repeated Part

22 Another possible derivation

23

24

25

26 Therefore, the string is also generated by the grammar

27 We know: We also know this string is generated:

28 We know: Therefore, this string is also generated:

29 We know: Therefore, this string is also generated:

30 We know: Therefore, this string is also generated:

31 Therefore, knowing that
is generated by grammar , we also know that is generated by

32 In general: We are given an infinite context-free grammar
Assume has no unit-productions no productions

33 > Take a string with length bigger than (Number of productions) x
(Largest right side of a production) Consequence: Some variable must be repeated in the derivation of

34 String Last repeated variable repeated

35 Possible derivations:

36 We know: This string is also generated:

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

38 We know: This string is also generated:

39 We know: This string is also generated:

40 We know: This string is also generated:

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

42 Therefore, knowing that we also know that

43 Observation: Since is the last repeated variable

44 Observation: Since there are no unit or productions

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

46 Applications of The Pumping Lemma

47 Non-context free languages

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

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

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

51 We can write: with lengths and

52 Pumping Lemma says: for all

53 We examine all the possible locations
of string in

54 Case 1: is within

55 Case 1: and consist from only

56 Case 1: Repeating and

57 Case 1: From Pumping Lemma:

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

59 Case 2: is within

60 Case 2: Similar analysis with case 1

61 Case 3: is within

62 Case 3: Similar analysis with case 1

63 Case 4: overlaps and

64 Case 4: Possibility 1: contains only contains only

65 Case 4: Possibility 1: contains only contains only

66 Case 4: From Pumping Lemma:

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

68 Case 4: Possibility 2: contains and contains only

69 Case 4: Possibility 2: contains and contains only

70 Case 4: From Pumping Lemma:

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

72 Case 4: Possibility 3: contains only contains and

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

74 Case 5: overlaps and

75 Case 5: Similar analysis with case 4

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

77 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 "Applications of Regular Closure"

Similar presentations


Ads by Google