lgorithms & Models of omputtion S/EE 374, Spring 209 NFs continued, losure Properties of Regulr Lnguges Lecture 5 Tuesdy, Jnury 29, 209 Regulr Lnguges, DFs, NFs Lnguges ccepted y DFs, NFs, nd regulr expressions re the sme. DFs re specil cses of NFs (trivil) NFs ccept regulr expressions (we sw lredy) DFs ccept lnguges ccepted y NFs (tody) Regulr expressions for lnguges ccepted y DFs (lter in the course) L TEXed: Decemer 26, 208 07:00 hn, Hr-Peled, Hssnieh (UIU) S374 Spring 209 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 2 Spring 209 2 / 3 Equivlence of NFs nd DFs Prt I For every NF N there is DF M such tht L(M) = L(N). Equivlence of NFs nd DFs hn, Hr-Peled, Hssnieh (UIU) S374 3 Spring 209 3 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 4 Spring 209 4 / 3
Forml Tuple Nottion for NF non-deterministic fe utomt (NF) N = (Q, Σ, δ, s, ) is five tuple where Q is fe set whose elements re clled sttes, Σ is fe set clled the input lphet, δ : Q Σ {ɛ} P(Q) is the trnsition function (here P(Q) is the power set of Q), s Q is the strt stte, Q is the set of ccepting/finl sttes. δ(q, ) for Σ {ɛ} is suset of Q set of sttes. Extending the trnsition function to strings For NF N = (Q, Σ, δ, s, ) nd q Q the ɛrech(q) is the set of ll sttes tht q cn rech using only ɛ-trnsitions. Inductive defion of δ : Q Σ P(Q): if w = ɛ, δ (q, w) = ɛrech(q) if w = where Σ δ (q, ) = p ɛrech(q) ( r δ(p,) ɛrech(r)) if w = x, δ (q, w) = p δ (q,x)( r δ(p,) ɛrech(r)) hn, Hr-Peled, Hssnieh (UIU) S374 5 Spring 209 5 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 6 Spring 209 6 / 3 Forml defion of lnguge ccepted y N string w is ccepted y NF N if δ N (s, w). The lnguge L(N) ccepted y NF N = (Q, Σ, δ, s, ) is {w Σ δ (s, w) }. Simulting n NF y DF Think of progrm with fixed memory tht needs to simulte NF N on input w. Wht does it need to store fter seeing prefix x of w? It needs to know t lest δ (s, x), the set of sttes tht N could e in fter reding x Is it sufficient? Yes, if it cn compute δ (s, x) fter seeing nother symol in the input. When should the progrm ccept string w? If δ (s, w). Key Oservtion: DF M tht simultes N should keep in its memory/stte the set of sttes of N Thus the stte spce of the DF should e P(Q). hn, Hr-Peled, Hssnieh (UIU) S374 7 Spring 209 7 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 8 Spring 209 8 / 3
Simulting NF Exmple the first revisited Previous lecture.. Rn NF (N) on input. t = 0: D E t = 2: t = 3: t = 4: t = 5: D E D E D E t = : hn, Hr-Peled, Hssnieh (UIU) S374 9 Spring 209 9 / 3 Suset onstruction NF N = (Q, Σ, s, δ, ). We crete DF M = (Q, Σ, δ, s, ) s follows: Q = P(Q) s = ɛrech(s) = δ (s, ɛ) = {X Q X } δ (X, ) = q X δ (q, ) for ech X Q, Σ. hn, Hr-Peled, Hssnieh (UIU) S374 Spring 209 / 3 Exmple: DF from NF NF: (N) DF: ctive thred in prticulr stte. Thus, to simulte the NF, the DF only needs to mintin the current set of sttes of the NF. The forml construction sed on the ove ide is s follows. onsider n NF N =(Q,,,s,). Define the DF det(n) =(Q 0,, 0,s 0, 0 ) s follows. D E Q 0 = P(Q) s 0 = N (s, ) 0 = {X Q X \ 6= ;} 0 ({q,q 2,...q k },)= N (q,) [ N (q 2,) [ [ N (q k,) or more concisely, 0 (X, ) = [ N (q, ) q2x hn, Hr-Peled, Hssnieh (UIU) S374 0 Spring 209 0 / 3 n exmple NF is shown in Figure 4 long with the DF det(n) in Figure 5. Exmple No ɛ-trnsitions q 0 q Figure 4: NF N We will now prove tht the DF defined ove is correct. Tht is Lemm 4. L(N) =L(det(N)) Proof. Need to show 8w 2. det(n) ccepts w i N ccepts w 8w 2. det(n) (s 0,w) 2 0 i N (s, w) \ 6= ; 8w 2. det(n) (s 0,w) \ 6= ; i N (s, w) \ 6= ; {q } {} 0 {q 0 } {q 0,q } Figure 5: DF det(n) equivlent to N gin for the induction proof to go through we need to strengthen the clim s follows. 8w 2. det(n) (s0,w)= N (s, w) In other words, this sys tht the stte of the DF fter reding some string is exctly the set of sttes the NF could e in fter reding the sme string. The proof of the strengthened sttement is y induction on w. se se If w =0thenw =. Now hn, Hr-Peled, Hssnieh (UIU) S374 2 Spring 209 2 / 3 det(n) (s0, ) =s 0 = N (s, ) y the defn. of det(n) nd defn. of s 0
Exmple s 0 = N (s, ) 0 = {X Q X \ 6= ;} 0 ({q,q2,...qk},)= N (q,) [ N (q2,) [ [ N (qk,) or more concisely, 0 (X, ) = [ N (q, ) No ɛ-trnsitions n exmple NF is shown in Figure 4 long with the DF det(n) in Figure 5. q2x Incrementl construction Only uild sttes rechle from s = ɛrech(s) the strt stte of M {q} {} ε q 0 q 0 ε q 3 {q 0, q } 0 {q 2,q 3} {} q0 q 0 {q0} {q0,q} q 2 δ (X, ) = q X δ (q, ) {q 3} Figure 4: NF N Figure 5: DF det(n) equivlent to N We will now prove tht the DF defined ove is correct. Tht is Lemm 4. L(N) =L(det(N)) Proof. Need to show 8w 2. det(n) ccepts w i N ccepts w 8w 2. det(n) (s 0,w) 2 0 i N (s, w) \ 6= ; 8w 2. det(n) (s 0,w) \ 6= ; i N (s, w) \ 6= ; gin for the induction proof to go through we need to strengthen the clim s follows. 8w 2. det(n) (s0,w)= N (s, w) In other words, this sys tht the stte of the DF fter reding some string is exctly the set of sttes the hn, Hr-Peled, NF could Hssnieh e in fter (UIU) reding the sme string. S374 3 The proof of the strengthened sttement is y induction on w. se se If w =0thenw =. Now Spring 209 3 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 4 Spring 209 4 / 3 det(n) (s0, ) =s 0 = N (s, ) y the defn. of det(n) nd defn. of s 0 Incrementl lgorithm 7 Proof of orrectness uild M eginning with strt stte s == ɛrech(s) For ech existing stte X Q consider ech Σ nd clculte the stte Y = δ (X, ) = q X δ (q, ) nd dd trnsition. If Y is new stte dd it to rechle sttes tht need to explored. To compute δ (q, ) - set of ll sttes reched from q on string ompute X = ɛrech(q) ompute Y = p X δ(p, ) ompute Z = ɛrech(y ) = r Y ɛrech(r) Let N = (Q, Σ, s, δ, ) e NF nd let M = (Q, Σ, δ, s, ) e DF constructed from N vi the suset construction. Then L(N) = L(M). Stronger clim: Lemm For every string w, δ N (s, w) = δ M (s, w). Proof y induction on w. se cse: w = ɛ. δ N (s, ɛ) = ɛrech(s). δ M (s, ɛ) = s = ɛrech(s) y defion of s. hn, Hr-Peled, Hssnieh (UIU) S374 5 Spring 209 5 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 6 Spring 209 6 / 3
Proof continued Lemm For every string w, δ N (s, w) = δ M (s, w). Inductive step: w = x (Note: suffix defion of strings) δ N (s, x) = p δn (s,x) δ N (p, ) y inductive defion of δ N δ M (s, x) = δ M (δ M (s, x), ) y inductive defion of δ M y inductive hypothesis: Y = δ N (s, x) = δ M (s, x) Prt II losure Properties of Regulr Lnguges Thus δ N (s, x) = p Y δ N (p, ) = δ M(Y, ) y defion of δ M. Therefore, δ N (s, x) = δ M(Y, ) = δ M (δ M (s, x), ) = δ M (s, x) which is wht we need. hn, Hr-Peled, Hssnieh (UIU) S374 7 Spring 209 7 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 8 Spring 209 8 / 3 Regulr Lnguges Regulr lnguges hve three different chrcteriztions Inductive defion vi se cses nd closure under union, conctention nd Kleene str Lnguges ccepted y DFs Lnguges ccepted y NFs Regulr lnguge closed under mny opertions: union, conctention, Kleene str vi inductive defion or NFs complement, union, intersection vi DFs homomorphism, inverse homomorphism, reverse,... Different representtions llow for flexiility in proofs Exmple: PREFIX Let L e lnguge over Σ. PREFIX(L) = {w wx L, x Σ } If L is regulr then PREFIX(L) is regulr. Let M = (Q, Σ, δ, s, ) e DF tht recognizes L X = {q Q s cn rech q in M} Y = {q Q q cn rech some stte in } Z = X Y rete new DF M = (Q, Σ, δ, s, Z) lim: L(M ) = PREFIX(L). hn, Hr-Peled, Hssnieh (UIU) S374 9 Spring 209 9 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 20 Spring 209 20 / 3
Exercise: SUFFIX Let L e lnguge over Σ. SUFFIX(L) = {w xw L, x Σ } Prove the following: If L is regulr then PREFIX(L) is regulr. Prt III Regex to NF hn, Hr-Peled, Hssnieh (UIU) S374 2 Spring 209 2 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 22 Spring 209 22 / 3 Stge 0: Input Stge : Normlizing,, 2: Normlizing it. + hn, Hr-Peled, Hssnieh (UIU) S374 23 Spring 209 23 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 24 Spring 209 24 / 3
Stge 2: Remove stte + + Stge 4: Redrwn without old edges + hn, Hr-Peled, Hssnieh (UIU) S374 25 Spring 209 25 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 26 Spring 209 26 / 3 Stge 4: Removing Stge 5: Redrw + + + + hn, Hr-Peled, Hssnieh (UIU) S374 27 Spring 209 27 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 28 Spring 209 28 / 3
Stge 6: Removing Stge 7: Redrw + ( + )( + ) + ( + )( + ) + + hn, Hr-Peled, Hssnieh (UIU) S374 29 Spring 209 29 / 3 hn, Hr-Peled, Hssnieh (UIU) S374 30 Spring 209 30 / 3 Stge 8: Extrct regulr expression ( + )( + ) Thus, this utomt is equivlent to the regulr expression ( + )( + ). hn, Hr-Peled, Hssnieh (UIU) S374 3 Spring 209 3 / 3