Top Banner
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University 2012
57

CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University

Jan 14, 2016

Download

Documents

kirby

CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University 2012. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CDT314 FABER Formal Languages, Automata  and Models of Computation Lecture 9 Mälardalen University

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

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

3

Language Hierarchy

Page 4: CDT314 FABER Formal Languages, Automata  and Models of Computation Lecture 9 Mälardalen University

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

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

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

7

q1

q21/, wba

q32/, wba

Not allowed

Page 8: CDT314 FABER Formal Languages, Automata  and Models of Computation Lecture 9 Mälardalen University

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

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

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

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

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

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

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

15

NPDAs Have More Power thanDPDAs

Page 16: CDT314 FABER Formal Languages, Automata  and Models of Computation Lecture 9 Mälardalen University

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

17

The language is:

}{}{ 2nnnn babaL 0n

Page 18: CDT314 FABER Formal Languages, Automata  and Models of Computation Lecture 9 Mälardalen University

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

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

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

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

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

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

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

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

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

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

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

29

Positive Properties of Context-Free Languages

Page 30: CDT314 FABER Formal Languages, Automata  and Models of Computation Lecture 9 Mälardalen University

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

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

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

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

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

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

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

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

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

39

Negative Properties of Context-Free Languages

Page 40: CDT314 FABER Formal Languages, Automata  and Models of Computation Lecture 9 Mälardalen University

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

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

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

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

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

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

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

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

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

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

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

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

52

Applications of Regular Closure

Page 53: CDT314 FABER Formal Languages, Automata  and Models of Computation Lecture 9 Mälardalen University

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

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

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

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

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