Finite Automt Deterministic Finite Automt H. Geuvers nd J. Rot Institute for Computing nd Informtion Sciences Version: fll 2016 J. Rot Version: fll 2016 Tlen en Automten 1 / 21
Outline Finite Automt Finite Automt J. Rot Version: fll 2016 Tlen en Automten 2 / 21
Finite Automt Regulr lnguges Definition L A is regulr if L = L(e) for some regulr expression e. Decidility Prolems Q1 Cn we decide (lgorithmiclly) if w L(e)? Q2 If yes, wht is the complexity of this decision procedure? Q3 Cn we decide if L(e 1 ) = L(e 2 )? Some nswers A1 Yes, we cn give deterministic finite utomton for e to decide w L(e). (This lecture) A2 time is liner in w ; memory is constnt (independent of w). A3 Yes: vi utomt constructions or vi eutions, see Exercise 2.3.6 of the course notes. J. Rot Version: fll 2016 Tlen en Automten 4 / 21
Finite Automt Deterministic Finite Automton (DFA) Intuition. Let A = {, }. Consider the DFA M: strt 0 1 2, Letters, re the moves in the grph Words w A give seuences of moves Strt stte is indicted y strt, Accepting/finl sttes y doule circle (there cn e severl ccepting sttes) The word is ccepted, ut is not ccepted (rejected) J. Rot Version: fll 2016 Tlen en Automten 5 / 21
Finite Automt Deterministic Finite Automton (DFA), strt 0 1 2 M = (Q, 0, δ, F ) with Q = { 0, 1, 2 }, F = { 2 } nd δ given y δ 0 0 1 1 0 2 2 2 2 J. Rot Version: fll 2016 Tlen en Automten 6 / 21
Finite Automt Deterministic Finite Automt formlly M is DFA over A if M = (Q, 0, δ, F ) with A is finite lphet Q is finite set of sttes 0 Q is the initil stte F Q is finite set of finl sttes δ : Q A Q is the trnsition function The multi-step trnsition δ : Q A Q is defined inductively y δ (, λ) = δ (, w) = δ (δ(, ), w) The lnguge ccepted y M, nottion L(M), is: L(M) = {w A δ ( 0, w) F } J. Rot Version: fll 2016 Tlen en Automten 7 / 21
Finite Automt Reding words w A Computtion for δ ( 0, w) in the exmple DFA. strt 0 1 2 Tke w = :, δ ( 0, ) = δ (δ( 0, ), ) = δ ( 0, ) = δ (δ( 0, ), ) = δ ( 1, ) = δ (δ( 1, ), ) = δ ( 2, ) = δ (δ( 2, ), λ) = δ ( 2, λ) = 2 So is ccepted. J. Rot Version: fll 2016 Tlen en Automten 8 / 21
Finite Automt Reding words w A Computtion for δ ( 0, w) in the exmple DFA. strt 0 1 2 Tke w = :, δ ( 0, ) = δ (δ( 0, ), ) = δ ( 0, ) = δ (δ( 0, ), ) = δ ( 1, ) = δ (δ( 1, ), λ) = δ ( 0, λ) = 0 So is not ccepted. The (regulr) lnguge ccepted y M (of the first slide) is: L(( + ) ( + ) ). J. Rot Version: fll 2016 Tlen en Automten 9 / 21
Finite Automt From trnsition tle to stte digrm Consider the utomton M over A = {, } with Q = {0, 1, 2, 3, 4}, 0 = 0, F = {4} δ 0 1 0 1 1 2 2 1 3 3 4 0 4 4 4 1 Which of the following words is ccepted?,, 2 Is it the cse tht {w w is even } L(M)? 3 Is it the cse tht {w w contins } L(M)? J. Rot Version: fll 2016 Tlen en Automten 10 / 21
Finite Automt Mnipulting Finite Automt: products for intersection M strt 0 1 L(M) L 1 = {w w is even} strt p, L 2 = {w w 1} strt 0, p 1, p 0, 1, L 1 L 2 = {w w is even nd w 1} J. Rot Version: fll 2016 Tlen en Automten 12 / 21
Finite Automt Product of two DFAs Given two DFAs over the sme A M 1 = (Q 1, 01, δ 1, F 1 ) M 2 = (Q 2, 02, δ 2, F 2 ) Define with M 1 M 2 = (Q 1 Q 2, 0, δ, F ) 0 := ( 01, 02 ) δ(( 1, 2 ), ) := (δ 1 ( 1, ), δ 2 ( 2, )) Then with F := F 1 F 2 := {( 1, 2 ) 1 F 1 nd 2 F 2 } we hve L(M 1 M 2 ) = L(M 1 ) L(M 2 ) J. Rot Version: fll 2016 Tlen en Automten 13 / 21
Finite Automt Closure Properties Proposition Closure under complement If L is ccepted y some DFA, then so is L = A L. Proof. Suppose tht L is ccepted y M = (Q, 0, δ, F ). Then L is ccepted y M = (Q, 0, δ, F ). Proposition Closure under intersection nd union If L 1, nd L 2 re ccepted y some DFA, then so re L 1 L 2 nd L 1 L 2. Proof. For the intersection, this follows from the product construction on the previous slide. For the union, this cn e seen y the product construction, tking different F (which one?) or y noticing tht L 1 L 2 = L 1 L 2. J. Rot Version: fll 2016 Tlen en Automten 14 / 21
Finite Automt Kleene s Theorem Theorem The lnguges ccepted y DFAs re exctly the regulr lnguges We will prove this in this nd the next lecture y 1 If L = L(M), for some DFA M, then there is regulr expression e such tht L = L(e) (this lecture). 2 If L = L(e), for some regulr expression e, then there is non-deterministic finite utomton (NFA) M such tht L = L(M). (next lecture). 3 For every NFA M, there is DFA M such tht L(M) = L(M ) (next lecture) J. Rot Version: fll 2016 Tlen en Automten 15 / 21
Finite Automt From DFAs to regulr expressions Given the DFA M = (Q, 0, δ, F ), we construct regulr expression e such tht Procedure: L(e) = L(M). We remove sttes, replcing symols from A y regulr expressions over A, until we end up with simple utomton from which we cn red off e. J. Rot Version: fll 2016 Tlen en Automten 17 / 21
Simple utomt Finite Automt M w e such tht L(e) = L(M) w strt 0 w 0 strt 0 u strt 0 1 x v (u + xv y) y u strt 0 1 x v u x(v + yu x) y J. Rot Version: fll 2016 Tlen en Automten 18 / 21
Finite Automt Eliminting sttes Remove stte p, while dding rrows w etween other pirs of sttes. Before: v x y p After: xv y p J. Rot Version: fll 2016 Tlen en Automten 19 / 21
Specil cses Finite Automt Join rrows using + x y x + y First crete new single finl stte 1 p 1 Bewre of loops! v x y p xv y p J. Rot Version: fll 2016 Tlen en Automten 20 / 21
Finite Automt From DFA to RegExp The lgorithm outlined in the previous slides produces for every deterministic finite utomton M, regulr expression e M. Theorem For M DFA we hve L(e M ) = L(M). J. Rot Version: fll 2016 Tlen en Automten 21 / 21