CmSc 365 Thory of Computtion Finit Stt Automt nd Rgulr Exprssions (Chptr 2, Sction 2.3) ALPHABET oprtions: U, conctntion, * otin otin Strings Form Rgulr xprssions dscri Closd undr U, conctntion nd * (if nd r rg. xpr., thn U, nd * r rg. xpr.) Sts of strings Sts of strings (sust of ) By dfinition By dfinition Lngugs Rgulr lngugs (sust of) Closd undr, conctntion nd * (if L1 nd L2 r rg. lngugs., thn L1 U L2, L1L2 nd L1* r rg. lng.) THEOREM: Rgulr lngug IFF ccptd y som FSA lngugs Closd undr, conctntion nd * FSA rcogniz (ccpt) Strings ovr n lpht If L1 nd L2 r ccptd y som FSA, thn L1 L2, L1L2 nd L1* r ccptd y som FSA 1
Thorm : Th clss of lngugs ccptd y finit utomt is closd undr. union. conctntion c. Kln str d. complmnttion. intrsction Proof. union Lt M1 = (K1,, 1, s1, F1), M2 = (K2,, 2, s2, F2), W construct non-dtrministic utomton M = (K,,, s, F), whr K = K1 K2 {s} F = F1 F2 = 1 2 { (s,, s1), (s,, s2)} W introduc nw strt stt s, nd M gusss whthr th input is for M1 or M2. Formlly, if w є * thn (s,w) * M (q, ) for som q є F iff ithr (s1, w) * M1 (q, ) for som q є F1 or (s2, w) * M2 (q, ) for som q є F2 Hnc M ccpts w iff M1 ccpts w or M2 ccpts w, thus L(M) = L(M1) L(M2). conctntion W will construct n utomton M tht ccpts L(M) = L(M1) L(M2) Lt M1 = (K1,, 1, s1, F1), M2 = (K2,, 2, s2, F2), W construct non-dtrministic utomton M = (K,,, s, F), whr K = K1 K2 s = s1 F = F2 = 1 2 { (q,, s2) q є F 1} Hr th id is th connct ll finl stts of M1 with mpty links to th strt stt of M2. 2
Formlly, if w є * thn (s,w) * M (q, ) for som q є F iff w = uv, nd (s1, u) * M1 (q, ) for som q є F1, i.. u є L(M1) (s2, v) * M2 (q, ) for som q є F2, i.. v є L(M2) Hnc M ccpts w iff M1 ccpts prt of w nd thn M2 ccpts th rmining prt thus L(M) = L(M1) L(M2) c. Kln str Lt M1 = (K1,, 1, s1, F1), ccpting L(M1) W construct M tht ccpts L(M) = L(M1)* in th following wy: M = (K,,, s, F), whr K = K1 {s} F = F1 {s} = 1 {(s,, s1)} { (q,, s1) q є F 1} Th id hr is to hv nw strt stt connctd to s1 with n mpty link, so tht M ccpts th mpty string, nd to hv -trnsitions from ll finl stts of M1 to s1, so tht onc string hs n rd, th computtion cn rsum from th initil stt. d. complmnttion Lt M = (K,, δ, s, F), ccpting L(M). Th complmnt of L(M) is * - L(M). It is ccptd y dtrministic FSA constructd in th following wy: M = (K,, δ, s, K F) M is idnticl to M xcpt tht th finl nd non-finl stts r intrchngd. Thus string tht is ccptd y M will not ccptd y M nd vic vrs.. intrsction Hr w pply th qulity L1 L2 = * - (( * - L1) ( * - L2)) 3
Th closdnss undr intrsction follows from th closdnss undr union nd complmnttion. How to construct M (w considr dtrministic complt utomt): Lt M1 = (K1,, 1, s1, F1), M2 = (K2,, 2, s2, F2), W construct dtrministic utomton M = (K,,, s, F), whr K = K1 x K2 s = (s1,s2) F = {(q, p) q є F 1, p є F 2 } = { (q1, p1),, (q2,p2)) (q1,, q2) є 1,(p1,,p2) є 2 } Lt M1 nd M2 r ccpting L(M1) nd L(M2) rspctivly. Th nw utomton M hs to ccpt strings { w w L(M1) L(M2)}, i.. oth M1 nd M2 on w hv to stop in finl stts. How to construct FSA Rul 1: An FSA tht ccpts string of on lttr: Whn pplying Rul 2, Rul 3, nd Rul 4 low, ssum tht n FSA hs on finl stt only. If thr r mor finl stts, w cn rplc thm y intrnl stts nd link thm to nw finl stt y th mpty string. Rul 2: Squntil linking of two FSAs W link th finl stt of th first FSA with th strting stt of th scond FSA y n mpty link. Th finl stt of th first FSA is not finl stt in th nw FSA. Th strting stt of th scond FSA is not nymor strting stt in th nw FSA. Thus w otin nw FSA. If th first FSA ccpts L1 nd th scond FSA ccpts L2, thn th nw FSA will ccpt L1L2 Rul 3: Prlll linking of two FSAs. Introduc nw strting stt. 4
. Link th nw strting stt with th strting stts of ch FSA y n mpty link (th strting stts of th two FSAs r no mor strting stts) c. Introduc nw finl stt d. Link th finl stts of ch FSA to th nw finl stt y n mpty link. Th finl stts of th two FSAs r no mor finl stts. If th first FSA ccpts L1 nd th scond FSA ccpts L2, th nw FSA will ccpt L1 L2 Rul 4: Kln str on FSA. Givn n FSA tht ccpts th lngug L, how do w uild n FSA ht ccpts L*? W link its strting stt to its finl stt y n mpty link, nd its finl stt to its strting stt y n mpty link. Rul 5: Complmnttion Hr w simpl intrchng th finl nd th non-finl stts Rul 6: Intrsction S prt ) in th thorm ov. Exmpl 1: Build n FSA tht ccpts ( U *)* 1. W uild n FSA tht ccpts '' - FSA1 (Rul 1) 2. W uild n FSA tht ccpts '' - FSA2 (Rul 1) 3. W link ths two FSA squntilly - FSA3 (Rul 2) 5
Hr w cn simplify th FSA: 4. Nxt w uild n FSA tht ccpts (sm s in 2.) - FSA4 (Rul 1) 5. Th FSA tht ccpts * will FSA5 (Rul 4) 6. Now w link in prlll FSA3 nd FSA5. Th nw FSA is FSA6 (Rul 3) 6
7 7. Lst w uild FSA7 = FSA6* (Rul 4) Exmpl 2: Construct utomton tht ccpts L1 L2, whr L1 = {w * w contins vn numr of s} L2 = {w * w contins odd numr of s}
Lt M1 ccpt L1, nd M2 ccpt L2. W will dscri M1 nd M2 y trnsition tls: M1: K1 = {q1, q2} S1 = q1 F1 = {q1} q1 q2 q1 q2 q1 q2 M2: K2 = {p1, p2} S2= p1 F2 = {p2} p1 p1 p2 p2 p2 p1 Th nw utomton M will hv th following stts: K = {(q1, p1), (q1, p2), (q2, p1), (q2, p2)} S = (q1, p1) F = {(q1, p2)} Th trnsition tl is: (q1, p1) ( q2, p1) (q1, p2) (q1, p2) ( q2, p2) (q1, p1) (q2, p1) ( q1, p1) (q2, p2) (q2, p2) ( q1, p2) (q2, p1) W will show now tht th string is ccptd, whil th strings nd will not ccptd 8
((q1, p1), ) ((q2, p1), ) ((q1, p1), ) ((q1, p2), ) ((q2, p2), ) ((q1, p2), ) ((q1, p1), ) ((q1, p2), ) (q1, p2) is finl stt in M, so th string is ccptd ((q1, p1), ) ((q2, p1), ) ((q1, p1), ) ((q1, p2), ) ((q1, p1), ) (q1,p1) is not finl stt, so is not ccptd ((q1, p1), ) ((q2, p1), ) ((q2, p2), ) ((q2, p1), ) ((q2, p2), ) (q2, p2) is not finl stt, so is not ccptd 9