Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Non-deterministic Finite Automt H. Geuvers nd T. vn Lrhoven Institute for Computing nd Informtion Sciences Intelligent Systems Rdoud University Nijmegen Version: fll 2014 H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 1 / 18
Outline Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Non-deterministic Finite Automt Eliminting non-determinism H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 2 / 18
Previous Weeks Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Regulr Expressions nd Regulr Lnguges rexp Σ ::= s rexp Σ rexp Σ rexp Σ +rexp Σ rexp Σ with s Σ L Σ is regulr if L = L(e) for some regulr expression e. Deterministic Finite Automt, DFA Proposition Closure under complement, union, intersection If L 1, L 2 re ccepted y some DFA, then so re L 1 = Σ L 1 L 1 L 2 L 1 L 2. H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 3 / 18
Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Kleene s Theorem (nnounced lst lecture) Theorem The lnguges ccepted y DFAs re exctly the regulr lnguges We prove this y 1 If L = L(M) for some DFA M, then there is regulr expression e such tht L = L(e) (Previous lecture) 2 If L = L(e), for some regulr expression e, then there is non-deterministic finite utomton with -steps (NFA ) M such tht L = L(M). (This lecture) 3 For every NFA, M, there is DFA M such tht L(M) = L(M ) (This lecture) H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 4 / 18
Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Non-deterministic finite utomton (NFA), q strt 0 q 1 q 2 δ(q, ) is not one stte, ut set of sttes. δ q 0 {q 0 } {q 0, q 1 } q 1 {q 2 } q 2 in shorthnd δ q 0 q 0 q 0, q 1 q 1 q 2 q 2 H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 6 / 18
Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Non-deterministic Finite Automt: NFA (formlly) M is NFA over Σ if M = (Q, q 0, δ, F ) with Q is finite set of sttes q 0 Q is the initil stte F Q is finite set of finl sttes δ : Q Σ PQ is the trnsition function [PQ denotes the collection of susets of Q] Reding function δ : Q Σ PQ (multi-step trnsition) δ (q, ) = {q} δ (q, w) = {q q δ (p, w) for some p δ(q, )} = δ (p, w) p δ(q,) [ X i denotes the union of ll the X i ] The lnguge ccepted y M, nottion L(M), is: L(M) = {w Σ q f F (q f δ (q 0, w))} H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 7 / 18
Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen For the union of lnguges we cn put NFAs in prllel Exmple. Suppose we wnt to hve n NFA for L 1 L 2 = {w w is even or w 1} First ide: put the two mchines non-deterministiclly in prllel strt ev od, strt 0 1 strt, ev0 od 1 But this is wrong: The NFA ccepts. H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 8 / 18
Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Non-deterministic Finite Automt with silent steps: NFA We dd -trnsitions or silent steps to NFAs The correct union of M 1 nd M 2 is: ev od strt U, 0 1 In n NFA we llow δ(q, ) = q for q q. Tht mens δ : Q (Σ {}) PQ H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 9 / 18
NFA formlly Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen M is n NFA over Σ if M = (Q, q 0, δ, F ) with Q is finite set of sttes q 0 Q is the initil stte F Q is finite set of finl sttes δ : Q (Σ {}) PQ is the trnsition function The -closure of stte q, -closure(q), is the set of sttes rechle with only -steps. Reding function δ : Q Σ PQ (multi-step trnsition) δ (q, ) = -closure(q) δ (q, w) = {q p -closure(q) r δ(p, ) (q δ (r, w))} = δ (r, w) p -closure(q) r δ(p,) The lnguge ccepted y M, nottion L(M), is: L(M) = {w Σ q f F (q f δ (q 0, w))} H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 10 / 18
Non-deterministic Finite Automt Eliminting non-determinism Insulted mchines Rdoud University Nijmegen A finite utomton M is clled insulted if q 0 hs no in-going rrows there is only one finl stte which hs no out-going rrows Proposition. For ny mchine M one cn find n insulted NFA M such tht M ccepts the sme lnguge Proof. By dding sttes nd silent steps, for exmple strt 0 1 gives q strt 0 0 1 q f H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 11 / 18
Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Toolkit for uilding n NFA from regulr expression For ech regulr expression, we construct n insulted NFA. e M such tht L(M) = L(e) strt q 0 strt q 0 (for Σ) strt S F M 1 e = e 1 + e 2 with L(M 1 ) = L(e 1 ) L(M 2 ) = L(e 2 ) strt S S1 M 2 F1 F S2 F2 H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 12 / 18
Non-deterministic Finite Automt Eliminting non-determinism Toolkit (continued) Rdoud University Nijmegen e M such tht L(M) = L(e) e = e 1 e 2 with L(M 1 ) = L(e 1 ) L(M 2 ) = L(e 2 ) M 1 M 2 strt S1 F1 S2 F2 e = (e 1 ) with L(M 1 ) = L(e 1 ) M1 strt S S1 F1 F H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 13 / 18
Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Regulr lnguges ccepted y NFA Proposition. For every regulr expression e there is n NFA M e such tht L(M e ) = L(e). Proof. Apply the toolkit. M e cn e found y induction on the structure of e: First do this for the simplest regulr expressions. For composed regulr expression compose the utomt. Corollry. For every regulr lnguge L there is n NFA M tht ccepts L (so L(M) = L). H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 14 / 18
Non-deterministic Finite Automt Eliminting non-determinism Avoiding non-determinism Rdoud University Nijmegen We cn trnsform ny NFA (nd NFA ) into DFA tht ccepts the sme lnguge. Ide: Keep trck of ll the sttes you cn go to! A comintion of sttes is finl if one of the memers is finl. Exmple:L = {w w is even or w 1} strt U ev od, strt U od,0 od,1 ev,0 0 1 ev,1 H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 16 / 18
Non-deterministic Finite Automt Eliminting non-determinism Eliminting non-determinism nd -steps Let M e NFA given y (Q, q 0, δ, F ) Define the DFA M + s (Q +, q + 0, δ+, F + ) where Q + = PQ Rdoud University Nijmegen q 0 = {q 0 } δ + (H, ) = δ(q, ), for H Q, q H F + = {H Q H F } Then M + is DFA ccepting the sme lnguge s M If M is n NFA, we tke δ + (H, ) = q H p -closure(q) -closure(δ(p, )) F + = {H Q -closure(h) F } H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 17 / 18
Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Equivlence of DFA, NFA nd NFA Conclusion. Every NFA (or NFA) M cn e turned into DFA M ccepting the sme lnguge. Corollry. For every regulr lnguge L there is DFA M tht ccepts L (so L(M) = L). Proof. Given regulr expression e, first construct n NFA M such tht L(M) = L(e). Then chnge it into DFA preserving the lnguge tht is ccepted. Rephrsing of Kleene s Theorem: The clss of regulr lnguges is (equivlently) chrcterized s 1 The lnguges descried y regulr expression 2 The lnguges ccepted y DFA 3 The lnguges ccepted y n NFA 4 The lnguges ccepted y NFA H. Geuvers & T. vn Lrhoven Version: fll 2014 Forml Lnguges, Grmmrs nd Automt 18 / 18