Download presentation
Presentation is loading. Please wait.
Published byGloria Lyons Modified over 8 years ago
1
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University 2006
2
2 Content Language Hierarchy Deterministic PDAs (DPDAs) Non-DPDA (NPDA) NPDAs Have More Power than DPDAs Positive Properties of Context Free Languages Negative Properties of Context Free Languages Intersection of CFL and RL (Regular Closure) The Pumping Lemma for CFL Applications of the Pumping Lemma for CFL
3
3 Language Hierarchy
4
4 Regular Languages Context-Free Languages Non-regular languages
5
5 Deterministic PDAs (DPDAs)
6
6 Allowed DPDAs
7
7 Not allowed
8
8 Allowed Something must be matched from the stack
9
9 Not allowed
10
10 DPDA example
11
11 The language is deterministic context-free.
12
12 Definition A language is deterministic context-free if some DPDA accepts it.
13
13 Example of Non-DPDA (NPDA)
14
14 Not allowed in DPDAs
15
15 NPDAs Have More Power than DPDAs
16
16 We will show: which is not deterministic context-free (not accepted by a DPDA). There is a context-free language (accepted by a NPDA)
17
17 The language is:
18
18 The language is context-free Context-free grammar for there is an NPDA that accepts
19
19 is not deterministic context-free Theorem The language (i.e., there is no DPDA that accepts ). (Each a is to be matched by either one or two b. An initial choice must be made.)
20
20 Proof (by contradiction) Assume the opposite, i.e. that is deterministic context free. Therefore: there is a DPDA that accepts
21
21 accepts DPDA with
22
22 The language is not context-free (we will prove it later on using Pumping Lemma for CFL) Fact 1
23
23 The language is not context-free (we will prove later on that the union of two context-free languages is context-free) Fact 2
24
24 We will construct a NPDA that accepts: Contradiction, as is not context-free!
25
25 We modify Replace with Modified
26
26 The NPDA that accepts Modified Original
27
27 Since is accepted by a NPDA it is context-free. Contradiction!
28
28 Therefore: There is no DPDA that accepts Not deterministic context free. END OF PROOF
29
29 Positive Properties of Context-Free Languages
30
30 Context-free languages are closed under Union is context free is context-free Union
31
31 Example Union LanguageGrammar
32
32 In general: For context-free languages with context-free grammars and start variables The grammar of the union has new start variable and additional production
33
33 Context-free languages are closed under Concatenation is context free is context-free Concatenation
34
34 Example Concatenation Language Grammar
35
35 In general: For context-free languages with context-free grammars and start variables The grammar of the concatenation has new start variable and additional production
36
36 Context-free languages are closed under star-operation is context free Star Operation is context free
37
37 Example LanguageGrammar Star Operation
38
38 In general: For context-free language with context-free grammar and start variable The grammar of the star operation has new start variable and additional production
39
39 Negative Properties of Context-Free Languages
40
40 Context-free languages are not closed under intersection is context free not necessarily context-free Intersection
41
41 Example Context-free: NOT context-free Intersection
42
42 Context-free languages are not closed under complement is context free not necessarily context-free Complement
43
43 NOT context-free Example Context-free: Complement
44
44 Intersection of Context-Free Languages and Regular Languages (Regular Closure)
45
45 The intersection of a context-free language and a regular language is a context-free language context free regular context-free
46
46 Construct a new NPDA machine that accepts forNPDA Machine context-free forDFA Machine regular simulates in parallel and
47
47 transition NPDA transition DFA transition NPDA
48
48 initial state NPDA DFA initial state NPDA
49
49 final state NPDA final states DFA final states NPDA
50
50 simulates in parallel and accepts string if and only if accepts string and
51
51 Therefore: (since is NPDA) is context-free
52
52 Applications of Regular Closure
53
53 Prove that is context-free An Application of Regular Closure
54
54 is regular We know is context-free
55
55 regularcontext-free is context-free context-free (regular closure) END OF PROOF
56
56 Prove that is not context-free Another Application of Regular Closure
57
57 context-free regular context-free Ifis context-free Then impossible! Therefore, is not context free (regular closure) END OF PROOF
58
58 The Pumping Lemma for Context-Free Languages
59
59 Take an infinite context-free language Example: Generates an infinite number of different strings
60
60 A derivation
61
61 Derivation tree string
62
62 Derivation tree string repeated
63
63
64
64 Repeated Part
65
65 Another possible derivation
66
66
67
67
68
68
69
69 Therefore, the string is also generated by the grammar
70
70 We know: We also know following string is generated:
71
71 We know: Therefore, following string is also generated:
72
72 We know: Therefore, following string is also generated:
73
73 Therefore, following string is also generated: We know:
74
74 Therefore, knowing that is generated by grammar is generated by We also know that
75
75 In general We are given an infinite context-free grammar Assume has no unit-productions and no -productions
76
76 Take a string with length bigger than (Number of productions) x (Largest right side of a production) > Some variable must be repeated in the derivation of Consequence:
77
77 Last repeated variable String repeated strings of terminals
78
78 Possible derivations
79
79 We know: Following string is also generated:
80
80 This string is also generated: The original We know:
81
81 This string is also generated: We know:
82
82 This string is also generated: We know:
83
83 This string is also generated: We know:
84
84 Therefore, any string of the form is generated by the grammar
85
85 knowing that we also know that Therefore
86
86 Observation Since is the last repeated variable
87
87 Observation Since there are no unit or productions
88
88 The Pumping Lemma for CFL there exists an integer such that for any string we can write For infinite context-free language with lengths and
89
89 Applications of The Pumping Lemma for CFL
90
90 Regular Languages Context-Free Languages Non-regular languages Unrestricted grammar languages
91
91 Theorem The language is not context free Proof Use the Pumping Lemma for context-free languages
92
92 Assume the contrary, that is context-free. Since is context-free and infinite we can apply the pumping lemma.
93
93 Pumping Lemma gives a number such that: For any string with length We can choose e.g.
94
94 We can write: with lengths and
95
95 Pumping Lemma says: for all
96
96 We examine all the possible locations of string in
97
97 Case 1: is within
98
98 Case 1: and consist from only
99
99 Case 1: Repeating and
100
100 Case 1: From Pumping Lemma:
101
101 Case 1: From Pumping Lemma: However: Contradiction!
102
102 Case 2: is within
103
103 Case 2: Similar analysis to case 1
104
104 Case 3: is within
105
105 Case 3: Similar analysis to case 1
106
106 Case 4: overlaps and
107
107 Case 4: Possibility 1: contains only
108
108 Case 4: Possibility 1:contains only
109
109 Case 4: From Pumping Lemma:
110
110 Case 4: From Pumping Lemma: However: Contradiction!
111
111 Case 4: Possibility 2:contains and contains only
112
112 Case 4: Possibility 2: contains and contains only
113
113 Case 4: From Pumping Lemma:
114
114 Case 4: From Pumping Lemma: However: Contradiction!
115
115 Case 4: Possibility 3:contains only contains and
116
116 Case 4: Possibility 3: contains only contains and Similar analysis with Possibility 2
117
117 Case 5: overlaps and
118
118 Case 5: Similar analysis to case 4
119
119 There are no other cases to consider (since, string cannot overlap, and at the same time)
120
120 In all cases we obtained a contradiction Therefore: The original assumption that is context-free must be wrong Conclusion:is not context-free END OF PROOF
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.