1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University 2012
Jan 14, 2016
1
CDT314
FABER
Formal Languages, Automata and Models of Computation
Lecture 9
Mälardalen University
2012
2
Content
Language HierarchyDeterministic PDAs (DPDAs)Non-DPDA (NPDA)NPDAs Have More Power than DPDAsPositive Properties of Context Free Languages Negative Properties of Context Free Languages Intersection of CFL and RL (Regular Closure)
3
Language Hierarchy
4
Regular Languages
}{ nnba }{ RwwContext-Free Languages
Non-regular languages
}0:{ ! nan}0,:{ lncba lnln
5
Deterministic PDAs (DPDAs)
Based on C Busch, RPI, Models of Computation
6
q1 q2wba /,
q1
q21/, wba
q32/, wca
Allowed
DPDAs
7
q1
q21/, wba
q32/, wba
Not allowed
8
Allowed 1q 2qwb /,
q1
q21/, wb
q32/, wc
In -transitions something must be matched from the stack
stransition
9
Not allowed
q1
q21/, wb
q32/, wb
1q 2q /,
10
DPDA example
}0:{)( nbaML nn
aa /,
/, abq0 q1 q2 q3
/,ab
$/$,aa /,
11
}0:{)( nbaML nnThe language
is deterministic context-free.
12
Definition
A language is deterministic context-free
if some DPDA accepts it.
13
Example of Non-DPDA (NPDA)
}{)( RwwML
bb
aa
/,
/,
/,
/,
bb
aa
$/$,q1 q2 /,q0
14
bb
aa
/,
/,
/,
/,
bb
aa
$/$,q1 q2 /,q0
Not allowed in DPDAs
15
NPDAs Have More Power thanDPDAs
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)
L
17
The language is:
}{}{ 2nnnn babaL 0n
18
}{}{ 2nnnn babaL
The language is context-freeL
Context-free grammar for L
21 | SSS
|11 baSS
|22 bbaSS there is an NPDA
that accepts L
19
is not deterministic context-free
Theorem
}{}{ 2nnnn babaL The language
(i.e., there is no DPDA that accepts ). L
(Each a is to be matched by either one or two b.
An initial choice must be made.)
NDPA are more expressive than DPDA.There exist languages accepted by NDPA for which no DPDAexists.
Example
20
Proof (by contradiction)
Assume the opposite, i.e. that
}{}{ 2nnnn babaL
is deterministic context free.
Therefore:
there is a DPDA that acceptsM L
21
nnba nb
acceptsnnba 2
acceptsnnba
DPDA with
M }{}{)( 2nnnn babaML
22
The language
is not context-free.
}{ nnn cba
(we will prove it later on
using Pumping Lemma for CFL)
Fact 1
23
The language
is not context-free }{ nnn cbaL
}){}{( 2nnnn babaL
(we will prove later on that the union of
two context-free languages is context-free)
Fact 2
24
We will construct a NPDA that accepts:
}{ nnn cbaL
}){}{( 2nnnn babaL
This will lead to contradiction,
as
is not context-free! }{ nnn cba
25
We modify M
Replace with cb
}){}{( 2nnnn babaL
nc
Modified Mnnca
}){}{( 2nnnn cacaL
26
The NPDA that accepts }{ nnn cbaL
nnba nb
nc
Modified M
Original M
nnca
27
Since is accepted by a NPDA }{ nnn cbaL
it is context-free.
Contradiction!
28
Therefore:
}{}{ 2nnnn babaL
There is no DPDA that accepts
Not deterministic context free.
END OF PROOF
29
Positive Properties of Context-Free Languages
30
Context-free languages
are closed under Union
1L is context free
2L is context free21 LL
is context-free
Union
31
Example
|11 baSS
|| 222 bbSaaSS
Union
}{1nnbaL
}{2RwwL
21 | SSS }{}{ Rnn wwbaL
Language Grammar
32
In general:
For context-free languages
with context-free grammars
and start variables
21, LL
21, GG
21, SS
The grammar of the union
has new start variable
and additional production21 | SSS
21 LL S
33
Context-free languages
are closed under Concatenation
1L is context free
2L is context free
21LL
is context-free
Concatenation
34
Example
|11 baSS
|| 222 bbSaaSS
Concatenation
}{1nnbaL
}{2RwwL
21SSS }}{{ Rnn wwbaL
Language Grammar
35
In general:
For context-free languages
with context-free grammars
and start variables
21, LL
21, GG21, SS
The grammar of the concatenation
has new start variable
and additional production 21SSS
21LLS
36
Context-free languages
are closed under star-operation
L is context free
Star Operation
*L is context free
37
|aSbS }{ nnbaL
|11 SSS *}{ nnbaL
Example
Language Grammar
Star Operation
|aSbS
38
In general:
For context-free language
with context-free grammar
and start variable
LG
S
The grammar of the star operation
has new start variable
and additional production
*L1S
|11 SSS
39
Negative Properties of Context-Free Languages
40
Context-free languages
are not closed under intersection
1L is context free
2L is context free
21 LL not necessarily
context-free
Intersection
41
Example
}{1mnn cbaL
|
|
cCC
aAbA
ACS
Context-free:}{2mmn cbaL
|
|
bBcB
aAA
ABS
Context-free:
}{21nnn cbaLL NOT context-free
Intersection
42
Context-free languages
are not closed under complement
L is context free
Lnot necessarily context-free
Complement
43
}{2121ncnbnaLLLL
NOT context-free
Example
}{1mnn cbaL
|
|
cCC
aAbA
ACS
Context-free:
}{2mmn cbaL
|
|
bBcB
aAA
ABS
Context-free:
Complement
44
Intersection of Context-Free Languagesand
Regular Languages (Regular Closure)
45
The intersection of
a context-free language and
a regular language
is a context-free language
1L context free
2L regular
21 LL
context-free
46
Construct a new NPDA machine
that accepts
M
21 LL
1LforNPDA
1MMachine
context-free
for 2LDFA
2MMachine
regular
M simulates in parallel and 1M 2M
47
1M
1q 2qcba /,
transition
NPDA 2M
1p 2pa
transition
DFA
11, pq
transition
MNPDA
22 , pqcba /,
48
2M
0p
initial state
1M
0q
initial state
NPDA DFA
initial state
MNPDA
00 , pq
49
1M
1q
final state
NPDA2M
1p
final states
DFA
2p
final states
MNPDA
11, pq 21, pq
50
M simulates in parallel and 1M 2M
M accepts string w if and only if
accepts string w2M
)()()( 21 MLMLML
accepts string w1M and
51
Therefore:
)()( 21 MLML
(since is NPDA) M
is context-free
21 LL is context-free
52
Applications of Regular Closure
53
Prove that
}100:{ nbaL nn
is context-free
An Application of Regular Closure
54
}{}){( 100100*1 babaL is regular
}{ 1001001 baL is regularWe know
}{ nnbaWe know is context-free
55
}{}){( 100100*1 babaL
regular
}{ nnbacontext-free
1}{ Lba nn is context-free
Lnba
Lbann
nn
}100:{
}{ 1
context-free
(regular closure)
END OF PROOF
56
Prove that
}:{ cba nnnwL
is not context-free
Another Application of Regular Closure
57
}{*}**{ nnn cbacbaL
context-free regular context-free
}:{ cba nnnwL If is context-free
Then
impossible!
Therefore, is not context free L
(regular closure)
END OF PROOF