Non-deterministic Finite Automt From Regulr Expressions to NFA- Eliminting non-determinism Rdoud University Nijmegen Non-deterministic Finite Automt H. Geuvers nd J. Rot Institute for Computing nd Informtion Sciences Rdoud University Nijmegen Version: fll 2016 Jurrin Rot Version: fll 2016 Tlen en Automten 1 / 19
Outline Non-deterministic Finite Automt From Regulr Expressions to NFA- Eliminting non-determinism Rdoud University Nijmegen Non-deterministic Finite Automt From Regulr Expressions to NFA- Eliminting non-determinism Jurrin Rot Version: fll 2016 Tlen en Automten 2 / 19
Previous Weeks Non-deterministic Finite Automt From Regulr Expressions to NFA- Eliminting non-determinism Rdoud University Nijmegen Regulr Expressions nd Regulr Lnguges rexp Σ ::= 0 1 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. Jurrin Rot Version: fll 2016 Tlen en Automten 3 / 19
Non-deterministic Finite Automt From Regulr Expressions to NFA- 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) Jurrin Rot Version: fll 2016 Tlen en Automten 4 / 19
Non-deterministic Finite Automt From Regulr Expressions to NFA- 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 Jurrin Rot Version: fll 2016 Tlen en Automten 6 / 19
Non-deterministic Finite Automt From Regulr Expressions to NFA- Eliminting non-determinism Rdoud University Nijmegen Non-deterministic Finite Automt: NFA (definition) 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,) The lnguge ccepted y M, nottion L(M), is: L(M) = {w Σ q f δ (q 0, w) such tht q f F } Jurrin Rot Version: fll 2016 Tlen en Automten 7 / 19
Non-deterministic Finite Automt From Regulr Expressions to NFA- 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. Jurrin Rot Version: fll 2016 Tlen en Automten 8 / 19
Non-deterministic Finite Automt From Regulr Expressions to NFA- Eliminting non-determinism NFAs with silent steps: NFA- We dd -trnsitions or silent steps to NFAs The correct union of M 1 nd M 2 is: ev od Rdoud University Nijmegen strt U, 0 1 In n NFA- we llow for q q. Tht mens δ(q, ) = q δ : Q (Σ {}) PQ Jurrin Rot Version: fll 2016 Tlen en Automten 9 / 19
Non-deterministic Finite Automt From Regulr Expressions to NFA- Eliminting non-determinism NFA- (definition) 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 δ (q 0, w) such tht q f F } Jurrin Rot Version: fll 2016 Tlen en Automten 10 / 19
Non-deterministic Finite Automt From Regulr Expressions to NFA- Eliminting non-determinism Rdoud University Nijmegen Toolkit for uilding n NFA- from regulr expression For ech regulr expression, we construct n NFA-. e M such tht L(M) = L(e) 0 strt q 0 1 strt q 0 (for Σ) strt q 0 f M 1 e = e 1 + e 2 with L(M 1 ) = L(e 1 ) L(M 2 ) = L(e 2 ) strt q 0 M 2 f q 1 f 1 q 2 f 2 Jurrin Rot Version: fll 2016 Tlen en Automten 12 / 19
Non-deterministic Finite Automt From Regulr Expressions to NFA- 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 q 1 f 1 q 2 f 2 e = (e 1 ) with L(M 1 ) = L(e 1 ) M 1 strt q 0 q 1 f 1 Jurrin Rot Version: fll 2016 Tlen en Automten 13 / 19
Non-deterministic Finite Automt From Regulr Expressions to NFA- Eliminting non-determinism Regulr lnguges ccepted y NFA- Rdoud University Nijmegen 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). Jurrin Rot Version: fll 2016 Tlen en Automten 14 / 19
Non-deterministic Finite Automt From Regulr Expressions to NFA- 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 the set of ll sttes you cn go to! Sttes of the DFA re sets-of-sttes from the originl NFA-. A set 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 Jurrin Rot Version: fll 2016 Tlen en Automten 16 / 19
Non-deterministic Finite Automt From Regulr Expressions to NFA- 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 } If M is n NFA-, we define q 0 = -closure(q 0 ) δ(h, ) = -closure(δ(p, )) q H p -closure(q) F = {H Q -closure(h) F } Jurrin Rot Version: fll 2016 Tlen en Automten 17 / 19
Correctness Non-deterministic Finite Automt From Regulr Expressions to NFA- Eliminting non-determinism Rdoud University Nijmegen Given M, n NFA-, we hve defined the DFA M y q 0 = {q 0 } δ(h, ) = q H p -closure(q) -closure(δ(p, )) F = {H Q -closure(h) F } Theorem M nd M ccept the sme lnguges. Proof: This follows from Lemm δ (q, w) F δ ({q}, w) F (Tke q := q 0 ) Proof of the Lemm: induction on w, considering the cses w = nd w = u. Jurrin Rot Version: fll 2016 Tlen en Automten 18 / 19
Non-deterministic Finite Automt From Regulr Expressions to NFA- Eliminting non-determinism Equivlence of DFA, NFA nd NFA- Rdoud University Nijmegen 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- Jurrin Rot Version: fll 2016 Tlen en Automten 19 / 19