제8장. context-free 언어의특성sclab.yonsei.ac.kr/courses/07am/chap08.pdf제8장.context-free...

22
8. Context-Free 언어의 특성 학습목표 Pumping LemmaClosure 특성을 통해 CFL Language Family간의 관계 이해 Regular 언어에서의 특성과 유사점/ 상이점을 집중적으로 이해할 것

Upload: others

Post on 24-Feb-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 제8장. Context-Free 언어의특성sclab.yonsei.ac.kr/courses/07AM/chap08.pdf제8장.Context-Free 언어의특성학습목표 Pumping Lemma와Closure 특성을통해CFL 와Language

제 8장. Context-Free 언어의특성

학습목표

Pumping Lemma와 Closure 특성을통해 CFL와 Language Family간의 관계이해

Regular 언어에서의특성과유사점/ 상이점을집중적으로이해할것

Page 2: 제8장. Context-Free 언어의특성sclab.yonsei.ac.kr/courses/07AM/chap08.pdf제8장.Context-Free 언어의특성학습목표 Pumping Lemma와Closure 특성을통해CFL 와Language

개요

• Regulardeterministic CFL

CFLcontext sensitive

• 2 pumping lemmas• Closure properties and decision algorithms for CFL

언어계통에서 CFL의위상을점검해봅시다

Page 3: 제8장. Context-Free 언어의특성sclab.yonsei.ac.kr/courses/07AM/chap08.pdf제8장.Context-Free 언어의특성학습목표 Pumping Lemma와Closure 특성을통해CFL 와Language

Two Pumping Lemmas

• Thm 8.1

language free-context infinite :L

L,2,1,0 allfor =∈∋ iLzxyuv ii

,1||,||with

as decomposed becan with integer positive

≥≤=

≥∈∋∃

vymvxyuvxyzw

m|w|Lwm

Regular 언어의경우와비교해보면뭐가다른가요?

L,2,1,0 allfor ,1||,||with

=∈∋

≥≤=

iLzxyymxy

xyzw

i

CFL를위한펌핑렘마를다시정의해봅시다

Page 4: 제8장. Context-Free 언어의특성sclab.yonsei.ac.kr/courses/07AM/chap08.pdf제8장.Context-Free 언어의특성학습목표 Pumping Lemma와Closure 특성을통해CFL 와Language

Pumping Lemma : 증명

• Pf L-{λ} without unit-productions / λ-productions|derivation| ≥ |w| / kL: infinite, G: finite → some variables repeat

s

A

A

x

v y

u z

uvxyzuvAyzuAzS *** ⇒⇒⇒

xAvAyA ** ⇒⇒

generatedbecanzxyuv ii∴

zxyuv ii

R.L.for : cf) zxyi

m

유한개의심볼로무한한스트링을표현하자니트리중에반복되는부분이있을수밖에…

Page 5: 제8장. Context-Free 언어의특성sclab.yonsei.ac.kr/courses/07AM/chap08.pdf제8장.Context-Free 언어의특성학습목표 Pumping Lemma와Closure 특성을통해CFL 와Language

Pumping Lemma : 예1

ex 1) }0:{ ≥= ncbaL nnn

Lavxycba mmm

in not s'only to →

Lmkcbaba

mkk in not generated becan ,s' s,' of no. equal

→≠

mvxyvy ≤→ || possiblenot sc' s,b' s,a' of no. same has

kkmm

nn

byavbabaL

==

=

,,}{cf)

Page 6: 제8장. Context-Free 언어의특성sclab.yonsei.ac.kr/courses/07AM/chap08.pdf제8장.Context-Free 언어의특성학습목표 Pumping Lemma와Closure 특성을통해CFL 와Language

Pumping Lemma : 예2

ex 2)

ex 3)

mmmm baba

mjmkbaba mmjk <<→ or ,

Lin not →

a...ab...ba...ab...bm m m m

u v x y z

}0:{ ! ≥= naL n

}},{:{ *bawwwL ∈=?Rww

Regular 언어의펌핑렘마와동일하게증명RL < CFL

Page 7: 제8장. Context-Free 언어의특성sclab.yonsei.ac.kr/courses/07AM/chap08.pdf제8장.Context-Free 언어의특성학습목표 Pumping Lemma와Closure 특성을통해CFL 와Language

Pumping Lemma : 예3

ex 4) }:{ 2jnbaL jn ==

mm ba2

12 )1(

:kim

a−+ 2)1(

:kim

b−+

12222

2

21

12)1()(

00,0

kmmmmkm

ikk

−<+−=−≤−

=→≠≠

)0,0(0,0 2121 =≠≠= kkkk

a...a...a...ab...b...b...bk1 k2

m2 m

u v x y z

Linnot→

Page 8: 제8장. Context-Free 언어의특성sclab.yonsei.ac.kr/courses/07AM/chap08.pdf제8장.Context-Free 언어의특성학습목표 Pumping Lemma와Closure 특성을통해CFL 와Language

또다른 Pumping Lemma : Linear CFL

• Def 8.1

)( CFGlinear iflinear is CFL : GLLGL =∋∃

:}0:{ ≥= nbaL nn

grammarlinear equivalent no linear not is language show To ∃→

cf) linear grammar : at most one variable on right side of production

ex)

:)}()(:{ wnwnwL ba ==

λ|linear aSbS →

λ|||linearnot bSaaSbSSS →

Page 9: 제8장. Context-Free 언어의특성sclab.yonsei.ac.kr/courses/07AM/chap08.pdf제8장.Context-Free 언어의특성학습목표 Pumping Lemma와Closure 특성을통해CFL 와Language

또다른 Pumping Lemma : 정리

• Thm 8.2

languagelinear infinite :L

as decomposed becan ||,integer positive mwLwm ≥∈∋∃

L,,, iLzxyuv ii 210 allfor =∈

cf) left or right ends of w to be pumped

∋≥≤= 1||,|| with vymuvyzuvxyzw

Page 10: 제8장. Context-Free 언어의특성sclab.yonsei.ac.kr/courses/07AM/chap08.pdf제8장.Context-Free 언어의특성학습목표 Pumping Lemma와Closure 특성을통해CFL 와Language

또다른 Pumping Lemma : 예

ex) )}()(:{ wnwnwL ba ==

mmm abaw 2=

s'entirely contains ,,, azyvu

1 or 1,2 ≥≥++ lkaba lmmkm

linear context-free

linearnotis

Page 11: 제8장. Context-Free 언어의특성sclab.yonsei.ac.kr/courses/07AM/chap08.pdf제8장.Context-Free 언어의특성학습목표 Pumping Lemma와Closure 특성을통해CFL 와Language

2 Pumping Lemmas : Exercises 8.1

* Regular언어를위한 pumping lemma에비해 CFL의 pumping lemma는상대방의 choice가훨씬복잡하다는점을제외하고는동일하게적용할수있다!

- 7 (b), (d), (e) : Pumping lemma를사용한 CFL가아님을보이는좋은예

- 11 : 복합적인적용문제

Page 12: 제8장. Context-Free 언어의특성sclab.yonsei.ac.kr/courses/07AM/chap08.pdf제8장.Context-Free 언어의특성학습목표 Pumping Lemma와Closure 특성을통해CFL 와Language

CFL에대한 Pumping Lemma 응용

CFL에대한 pumping lemma를응용할때, regular language에대한pumping lemma와다른점에유의할필요가있다. Regular language의경우 pump 할곳 (즉, w = xyz내의 y) 은선택한 string w의길이 n인prefix 내에한정되어있다. 반면, CFL의경우 pump 할곳 (w = uvxyz내의 v와 y)은 string u와 z의길이에제한이없으므로조건 |vxy| ≤ m, 즉넓이가 최대m인창(window) 이있을수있는위치이면어디든지가능하다. String vxy는 w의 prefix가될수도있고 suffix가될수도있다. 따라서 CFL에대한 pumping lemma를이용하여어떤 language L이 CFL가아님을증명하는과정에서조건을만족할수없음을보일때, vxy가있을수있는 w 상의많은경우를모두고려해야한다.

wvxy vxy vxy

Page 13: 제8장. Context-Free 언어의특성sclab.yonsei.ac.kr/courses/07AM/chap08.pdf제8장.Context-Free 언어의특성학습목표 Pumping Lemma와Closure 특성을통해CFL 와Language

CFL에대한 Pumping Lemma: 증명

증명. 증명의 바탕이 되는 개념을 설명하기 위하여 간단한 예를 들기로 한다. 다음 Chomsky normal form 의 CFG를고려하자.

S → AB A → DE B → FD E → FGG → DB | g F → HG D → d H → h

이 CFG의 언어의 크기는 무한 함을 쉽게 알 수 있다. 예를 들면, rule B → FD, F → HG, G → DB 에 의하여 B가 F를 생성하고, F가 G를, 그리고 G가 다시B를생성하기때문에무한히많은 string을생성할수있다. 이 CFG 의언어에속한 string w = d(hd)3hg(d)3dghdghd 에대한 parse tree를분석하여보자 (다음쪽그림참조). Parse tree의가장긴줄기에해당하는 path label 에반복하는 pattern F-G-B 가있음을알수있다. 이러한반복 pattern은 grammar의 nonterminal symbol의수가한정되어있는반면, grammar가발생하는 string의길이가한정되어있지않기때문이다.

Page 14: 제8장. Context-Free 언어의특성sclab.yonsei.ac.kr/courses/07AM/chap08.pdf제8장.Context-Free 언어의특성학습목표 Pumping Lemma와Closure 특성을통해CFL 와Language

D

S

BE

AD

d GB

F

G

D

d

H

h g

D

d

d

d

d

F

G

B

F

G

B

F

G

B

F

G

H

Dh

d

H

Dh

d

H

Dh

d

H

h g

D

D

D

F

GH

h gd

S AB A DE

E FG

G DB | g

F HG

D d H h

B → FD

w = d ( h d )3 h g (d)3 d h g d h g du v w x y

Page 15: 제8장. Context-Free 언어의특성sclab.yonsei.ac.kr/courses/07AM/chap08.pdf제8장.Context-Free 언어의특성학습목표 Pumping Lemma와Closure 특성을통해CFL 와Language

Closure Properties of CFL (1)

closed under union, concatenation and star-closure

φ=∩⎜⎜⎝

⎛==

2122222

11111 where),,,(),,,(

VVPSTVGPSTVG

=− 3G

=− 4G

2133321321 where),,},{( VVSPSTTSVV ∪∉∪∪∪

CFG:}|{ 213213 SSSPPP →∪∪=

CFL:)( 213 LLGL ∪=∴

2144421421 where),,},{( VVSPSTTSVV ∪∉∪∪∪

}{ 214214 SSSPPP →∪∪=

)()()( 214 GLGLGL =∴

RL와는달리 CFL의경우 Closure 특성이쉽게만족되지않는경우가많음

Page 16: 제8장. Context-Free 언어의특성sclab.yonsei.ac.kr/courses/07AM/chap08.pdf제8장.Context-Free 언어의특성학습목표 Pumping Lemma와Closure 특성을통해CFL 와Language

Closure Properties of CFL (2)

=− 5G 21555151 where),,},{( VVSPSTSV ∪∉∪

}|{ 51515 λSSSPP →∪=

*)()( 15 GLGL =∴

Page 17: 제8장. Context-Free 언어의특성sclab.yonsei.ac.kr/courses/07AM/chap08.pdf제8장.Context-Free 언어의특성학습목표 Pumping Lemma와Closure 특성을통해CFL 와Language

Closure Properties of CFL (3)

not closed under intersection and complementation

⎜⎜⎝

≥≥=

≥≥=

}0,0:{

}0,0:{

2

1

mncbaL

mncbaLmmn

mnn

λλ

||

22

11

21

cSSbaSS

SSS

→→→Q

}0|{21 ≥=∩ ncbaLL nnn

2121 LLLL ∪=∩

·

·

CFL:

CFLnot :

ationcomplementunder closed : CFL if

Page 18: 제8장. Context-Free 언어의특성sclab.yonsei.ac.kr/courses/07AM/chap08.pdf제8장.Context-Free 언어의특성학습목표 Pumping Lemma와Closure 특성을통해CFL 와Language

Closure Properties of CFL (4)

closed under regular intersection

⎜⎜⎝

⎛Σ=ΓΣ=

22022

11011

accepting dfa:),,,,( accepting npda:),,,,,,(

LFpPMLFzqQM

δδ

210 , ofaction parallel simulating pda:)ˆ,,ˆ,ˆ,,,ˆ(ˆ MMFzqQM δΓΣ=

⎜⎜⎜⎜

×=

=×=

21

000

ˆ),(ˆ

ˆ

FFF

pqqPQQ

lj

ik

jilk

papbaqxq

bapqxpq

=∈

),(),,(),( iff

),),,((ˆ)),,((:ˆ

2

1

δδ

δδ

·

Page 19: 제8장. Context-Free 언어의특성sclab.yonsei.ac.kr/courses/07AM/chap08.pdf제8장.Context-Free 언어의특성학습목표 Pumping Lemma와Closure 특성을통해CFL 와Language

Closure Properties of CFL (5)

s

rM

pwp

xqzwq

=),(

),(),,(iff

0*

*

0and

1

δ

2121

21

)()( & by accepted isit iff ˆby accepted is string a

LLMLMLMMM

∩=∩∴

21

ˆ*

00

,with ),),,((),),,((

FpFqxpqzwpq

sr

srM

∈∈├

Page 20: 제8장. Context-Free 언어의특성sclab.yonsei.ac.kr/courses/07AM/chap08.pdf제8장.Context-Free 언어의특성학습목표 Pumping Lemma와Closure 특성을통해CFL 와Language

Closure Properties of CFL : 예

free-contextnot is )}()()(:{) wnwnwnwL cba ===예

}{~ }0:{ 100100banbaL nn ∩>==

free-context is }100,0:{) <>>== nnbaL nn예

}0|{)( *** ≥=∩ ncbacbaLL nnn

Page 21: 제8장. Context-Free 언어의특성sclab.yonsei.ac.kr/courses/07AM/chap08.pdf제8장.Context-Free 언어의특성학습목표 Pumping Lemma와Closure 특성을통해CFL 와Language

Some Decidable Properties of CFL

- Algorithm to see if L(G) is empty

- Algorithm to see if L(G) is infinite

- CFL L1 = L2 ?

S is useless L(G) is empty

G has repeating variables dependency graph has cycleL(G) is infinite

No algorithm

주어진문제를해결할 algorithm이없다는것의의미?

나중에철저하게검토해봅시다

Page 22: 제8장. Context-Free 언어의특성sclab.yonsei.ac.kr/courses/07AM/chap08.pdf제8장.Context-Free 언어의특성학습목표 Pumping Lemma와Closure 특성을통해CFL 와Language

Closure Properties of CFL : Exercises 8.2

- 6 : Language Family간의 Closed 특성을포괄적으로이해합시다

- 10 : 간단하지만한번생각해서풀어봅니다

- 19 : 답은 YES, 하지만 construction은좀지저분하지요…