A Non Context-Free Language
description
Transcript of A Non Context-Free Language
![Page 1: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/1.jpg)
1
A Non Context-Free Language
(We will prove it at the next class)
![Page 2: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/2.jpg)
2
Regular languages
**ba
Context-free languagesnnba
Non Context-free languagesnnn cba
![Page 3: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/3.jpg)
3
Deterministic PDAs
DPDAs
![Page 4: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/4.jpg)
4
DPDAs
Allowed: q1 q2wba ,
q1
q21, wba
q32, wca
![Page 5: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/5.jpg)
5
q1
q21, wba
q32, wba
Not allowed:
![Page 6: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/6.jpg)
6
Allowed:1q 2q
wb,
q1
q21, wb
q32, wc
Something must be matched from the stack
![Page 7: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/7.jpg)
7
Not allowed:
q1
q21, wb
q32, wba
![Page 8: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/8.jpg)
8
DPDA example
a, a
b, a q0 q1 q2 q3
b, a
, $ $
}0:{)( nbaML nn
a, a
![Page 9: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/9.jpg)
9
}0:{)( nbaML nnThe language
is deterministic context-free
![Page 10: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/10.jpg)
10
Definition:
A language is deterministic context-freeif some DPDA accepts it
![Page 11: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/11.jpg)
11
Example of Non-DPDA (NPDA)
, $ $q1 q2
bb
aa
,
,
, q0
bb
aa
,
,
}{)( RwwML
![Page 12: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/12.jpg)
12
, $ $q1 q2
bb
aa
,
,
, q0
bb
aa
,
,
Not allowed in DPDAs
![Page 13: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/13.jpg)
13
NPDAs
Have More Power than
DPDAs
![Page 14: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/14.jpg)
14
We will show:
there is a context-free language
which is not deterministic context-free
(accepted by a NPDA)
(not accepted by a DPDA)
L
![Page 15: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/15.jpg)
15
The language is:
}{}{ 2nnnn babaL
0n
![Page 16: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/16.jpg)
16
}{}{ 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 17: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/17.jpg)
17
}{}{ 2nnnn babaL
is not deterministic context-free
Theorem:
The language
(there is no DPDA that accepts ) L
![Page 18: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/18.jpg)
18
Proof: Assume for contradiction that
}{}{ 2nnnn babaL
is deterministic context free
Therefore:
there is a DPDA that accepts M L
![Page 19: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/19.jpg)
19
DPDA with M
nnba nb
acceptsnnba 2
acceptsnnba
}{}{)( 2nnnn babaML
![Page 20: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/20.jpg)
20
The language is not context-free
}{ nnn cba
(we will prove it at the next class)
Fact 1:
![Page 21: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/21.jpg)
21
The language is not context-free
}{ nnn cbaL
}){}{( 2nnnn babaL
(we will prove later today that the union oftwo context-free languages is context-free)
Fact 2:
![Page 22: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/22.jpg)
22
We will construct a NPDA that accepts:
}{ nnn cbaL
}){}{( 2nnnn babaL
Contradiction!
![Page 23: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/23.jpg)
23
We modify M
nc
Modified M
Replace with cb
nnca
}){}{( 2nnnn babaL
}){}{( 2nnnn cacaL
![Page 24: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/24.jpg)
24
The NPDA that accepts }{ nnn cbaL
nnba nb
nc
Modified M
Original M
nnca
![Page 25: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/25.jpg)
25
Since is accepted by a NPDA }{ nnn cbaL
it is context-free
Contradiction!
(since is not context-free)}{ nnn cbaL
![Page 26: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/26.jpg)
26
Therefore:
}{}{ 2nnnn babaL
There is no DPDA that accepts
End of Proof
Not deterministic context free
![Page 27: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/27.jpg)
27
Positive Propertiesof
Context-Free languages
![Page 28: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/28.jpg)
28
Context-free languages are closed under: Union
1L is context free
2L is context free
21 LL
is context-free
Union
![Page 29: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/29.jpg)
29
Example
|11 baSS
|| 222 bbSaaSS
Union
}{1nnbaL
}{2RwwL
21 | SSS }{}{ Rnn wwbaL
Language Grammar
![Page 30: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/30.jpg)
30
In general:
The grammar of the union has new start variableand additional production 21 | SSS
For context-free languageswith context-free grammarsand start variables
21, LL
21, GG
21, SS
21 LL S
![Page 31: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/31.jpg)
31
Context-free languages are closed under: Concatenation
1L is context free
2L is context free
21LL
is context-free
Concatenation
![Page 32: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/32.jpg)
32
Example
|11 baSS
|| 222 bbSaaSS
Concatenation
}{1nnbaL
}{2RwwL
21SSS }}{{ Rnn wwbaL
Language Grammar
![Page 33: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/33.jpg)
33
In general:
The grammar of the concatenation has new start variableand additional production 21SSS
For context-free languageswith context-free grammarsand start variables
21, LL
21, GG
21, SS
21LLS
![Page 34: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/34.jpg)
34
Context-free languages are closed under: Star-operation
L is context free*L is context-free
Star Operation
![Page 35: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/35.jpg)
35
|aSbS }{ nnbaL
|11 SSS *}{ nnbaL
Example
Language Grammar
Star Operation
![Page 36: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/36.jpg)
36
In general:
The grammar of the star operation has new start variableand additional production
For context-free languagewith context-free grammarand start variable
LGS
*L1S
|11 SSS
![Page 37: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/37.jpg)
37
Negative Propertiesof
Context-Free Languages
![Page 38: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/38.jpg)
38
Context-free languagesare not closed under: intersection
1L is context free
2L is context free
21 LL
not necessarilycontext-free
Intersection
![Page 39: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/39.jpg)
39
Example
}{1mnn cbaL
|
|
cCC
aAbA
ACS
Context-free:
}{2mmn cbaL
|
|
bBcB
aAA
ABS
Context-free:
}{21nnn cbaLL NOT context-free
Intersection
![Page 40: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/40.jpg)
40
Context-free languagesare not closed under: complement
L is context free L not necessarilycontext-free
Complement
![Page 41: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/41.jpg)
41
}{2121nnn cbaLLLL
NOT context-free
Example
}{1mnn cbaL
|
|
cCC
aAbA
ACS
Context-free:
}{2mmn cbaL
|
|
bBcB
aAA
ABS
Context-free:
Complement
![Page 42: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/42.jpg)
42
Intersectionof
Context-free languagesand
Regular Languages
![Page 43: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/43.jpg)
43
The intersection of a context-free language and a regular languageis a context-free language
1L context free
2L regular
21 LL
context-free
![Page 44: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/44.jpg)
44
1Lfor for 2LNPDA
1M
DFA
2M
Construct a new NPDA machinethat accepts
Machine Machine
M21 LL
context-free regular
M simulates in parallel and 1M 2M
![Page 45: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/45.jpg)
45
1M 2M
1q 2qcba ,
transition
1p 2pa
transition
NPDA DFA
11, pq cba ,
transition
MNPDA
22 , pq
![Page 46: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/46.jpg)
46
1M 2M
0q
initial state
0p
initial state
NPDA DFA
Initial state
MNPDA
00 , pq
![Page 47: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/47.jpg)
47
1M 2M
1q
final state
1p
final states
NPDA DFA
final states
MNPDA
11, pq
2p
21, pq
![Page 48: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/48.jpg)
48
M simulates in parallel and 1M 2M
M accepts string w if and only if
accepts string and w1M
accepts string w2M
)()()( 21 MLMLML
![Page 49: A Non Context-Free Language](https://reader035.fdocuments.in/reader035/viewer/2022062221/56814897550346895db5ac41/html5/thumbnails/49.jpg)
49
Therefore: )()( 21 MLML
(since is NPDA) M
is context-free
21 LL is context-free