Download - CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University
![Page 1: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/1.jpg)
1
CDT314
FABER
Formal Languages, Automata and Models of Computation
Lecture 9
Mälardalen University
2012
![Page 2: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/2.jpg)
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)
![Page 3: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/3.jpg)
3
Language Hierarchy
![Page 4: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/4.jpg)
4
Regular Languages
}{ nnba }{ RwwContext-Free Languages
Non-regular languages
}0:{ ! nan}0,:{ lncba lnln
![Page 5: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/5.jpg)
5
Deterministic PDAs (DPDAs)
Based on C Busch, RPI, Models of Computation
![Page 6: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/6.jpg)
6
q1 q2wba /,
q1
q21/, wba
q32/, wca
Allowed
DPDAs
![Page 7: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/7.jpg)
7
q1
q21/, wba
q32/, wba
Not allowed
![Page 8: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/8.jpg)
8
Allowed 1q 2qwb /,
q1
q21/, wb
q32/, wc
In -transitions something must be matched from the stack
stransition
![Page 9: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/9.jpg)
9
Not allowed
q1
q21/, wb
q32/, wb
1q 2q /,
![Page 10: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/10.jpg)
10
DPDA example
}0:{)( nbaML nn
aa /,
/, abq0 q1 q2 q3
/,ab
$/$,aa /,
![Page 11: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/11.jpg)
11
}0:{)( nbaML nnThe language
is deterministic context-free.
![Page 12: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/12.jpg)
12
Definition
A language is deterministic context-free
if some DPDA accepts it.
![Page 13: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/13.jpg)
13
Example of Non-DPDA (NPDA)
}{)( RwwML
bb
aa
/,
/,
/,
/,
bb
aa
$/$,q1 q2 /,q0
![Page 14: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/14.jpg)
14
bb
aa
/,
/,
/,
/,
bb
aa
$/$,q1 q2 /,q0
Not allowed in DPDAs
![Page 15: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/15.jpg)
15
NPDAs Have More Power thanDPDAs
![Page 16: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/16.jpg)
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
![Page 17: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/17.jpg)
17
The language is:
}{}{ 2nnnn babaL 0n
![Page 18: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/18.jpg)
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
![Page 19: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/19.jpg)
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
![Page 20: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/20.jpg)
20
Proof (by contradiction)
Assume the opposite, i.e. that
}{}{ 2nnnn babaL
is deterministic context free.
Therefore:
there is a DPDA that acceptsM L
![Page 21: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/21.jpg)
21
nnba nb
acceptsnnba 2
acceptsnnba
DPDA with
M }{}{)( 2nnnn babaML
![Page 22: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/22.jpg)
22
The language
is not context-free.
}{ nnn cba
(we will prove it later on
using Pumping Lemma for CFL)
Fact 1
![Page 23: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/23.jpg)
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
![Page 24: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/24.jpg)
24
We will construct a NPDA that accepts:
}{ nnn cbaL
}){}{( 2nnnn babaL
This will lead to contradiction,
as
is not context-free! }{ nnn cba
![Page 25: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/25.jpg)
25
We modify M
Replace with cb
}){}{( 2nnnn babaL
nc
Modified Mnnca
}){}{( 2nnnn cacaL
![Page 26: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/26.jpg)
26
The NPDA that accepts }{ nnn cbaL
nnba nb
nc
Modified M
Original M
nnca
![Page 27: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/27.jpg)
27
Since is accepted by a NPDA }{ nnn cbaL
it is context-free.
Contradiction!
![Page 28: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/28.jpg)
28
Therefore:
}{}{ 2nnnn babaL
There is no DPDA that accepts
Not deterministic context free.
END OF PROOF
![Page 29: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/29.jpg)
29
Positive Properties of Context-Free Languages
![Page 30: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/30.jpg)
30
Context-free languages
are closed under Union
1L is context free
2L is context free21 LL
is context-free
Union
![Page 31: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/31.jpg)
31
Example
|11 baSS
|| 222 bbSaaSS
Union
}{1nnbaL
}{2RwwL
21 | SSS }{}{ Rnn wwbaL
Language Grammar
![Page 32: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/32.jpg)
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
![Page 33: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/33.jpg)
33
Context-free languages
are closed under Concatenation
1L is context free
2L is context free
21LL
is context-free
Concatenation
![Page 34: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/34.jpg)
34
Example
|11 baSS
|| 222 bbSaaSS
Concatenation
}{1nnbaL
}{2RwwL
21SSS }}{{ Rnn wwbaL
Language Grammar
![Page 35: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/35.jpg)
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
![Page 36: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/36.jpg)
36
Context-free languages
are closed under star-operation
L is context free
Star Operation
*L is context free
![Page 37: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/37.jpg)
37
|aSbS }{ nnbaL
|11 SSS *}{ nnbaL
Example
Language Grammar
Star Operation
|aSbS
![Page 38: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/38.jpg)
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
![Page 39: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/39.jpg)
39
Negative Properties of Context-Free Languages
![Page 40: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/40.jpg)
40
Context-free languages
are not closed under intersection
1L is context free
2L is context free
21 LL not necessarily
context-free
Intersection
![Page 41: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/41.jpg)
41
Example
}{1mnn cbaL
|
|
cCC
aAbA
ACS
Context-free:}{2mmn cbaL
|
|
bBcB
aAA
ABS
Context-free:
}{21nnn cbaLL NOT context-free
Intersection
![Page 42: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/42.jpg)
42
Context-free languages
are not closed under complement
L is context free
Lnot necessarily context-free
Complement
![Page 43: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/43.jpg)
43
}{2121ncnbnaLLLL
NOT context-free
Example
}{1mnn cbaL
|
|
cCC
aAbA
ACS
Context-free:
}{2mmn cbaL
|
|
bBcB
aAA
ABS
Context-free:
Complement
![Page 44: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/44.jpg)
44
Intersection of Context-Free Languagesand
Regular Languages (Regular Closure)
![Page 45: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/45.jpg)
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
![Page 46: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/46.jpg)
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
![Page 47: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/47.jpg)
47
1M
1q 2qcba /,
transition
NPDA 2M
1p 2pa
transition
DFA
11, pq
transition
MNPDA
22 , pqcba /,
![Page 48: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/48.jpg)
48
2M
0p
initial state
1M
0q
initial state
NPDA DFA
initial state
MNPDA
00 , pq
![Page 49: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/49.jpg)
49
1M
1q
final state
NPDA2M
1p
final states
DFA
2p
final states
MNPDA
11, pq 21, pq
![Page 50: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/50.jpg)
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
![Page 51: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/51.jpg)
51
Therefore:
)()( 21 MLML
(since is NPDA) M
is context-free
21 LL is context-free
![Page 52: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/52.jpg)
52
Applications of Regular Closure
![Page 53: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/53.jpg)
53
Prove that
}100:{ nbaL nn
is context-free
An Application of Regular Closure
![Page 54: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/54.jpg)
54
}{}){( 100100*1 babaL is regular
}{ 1001001 baL is regularWe know
}{ nnbaWe know is context-free
![Page 55: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/55.jpg)
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
![Page 56: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/56.jpg)
56
Prove that
}:{ cba nnnwL
is not context-free
Another Application of Regular Closure
![Page 57: CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University](https://reader036.vdocuments.us/reader036/viewer/2022062518/568148d9550346895db5f3b2/html5/thumbnails/57.jpg)
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