Automata and Formal Languages - CM0081 Finite Automata and Regular Expressions Andrés Sicard-Ramírez Universidad EAFIT Semester 2018-2
Introduction Equivalences DFA NFA -NFA RE Finite Automata and Regular Expressions 2/40
Theorem (3.4) If L = L(D) for some DFA D, then there is a regular expression R such that L = L(R). Finite Automata and Regular Expressions 3/40
Inductive proof on the number of states of the automaton Let the states of D be {1, 2,, n} with 1 the start state. Figure from Hopcroft, Motwani and Ullman (2007, Fig. 3.2). Finite Automata and Regular Expressions 4/40
Inductive proof on the number of states of the automaton Let the states of D be {1, 2,, n} with 1 the start state. Rij k : Regular expression describing the set of labels of all paths in D from state i to state j such that the path has no intermediate node whose number is greater than k. Figure from Hopcroft, Motwani and Ullman (2007, Fig. 3.2). Finite Automata and Regular Expressions 5/40
Basis step: Proof for k = 0 (i.e. no intermediate states) and i j Finite Automata and Regular Expressions 6/40
Basis step: Proof for k = 0 (i.e. no intermediate states) and i j No transition from state i to state j i j R 0 ij = Finite Automata and Regular Expressions 7/40
Basis step: Proof for k = 0 (i.e. no intermediate states) and i j No transition from state i to state j i j Rij 0 = One transition from state i to state j a i j Rij 0 = a Finite Automata and Regular Expressions 8/40
Basis step: Proof for k = 0 (i.e. no intermediate states) and i j No transition from state i to state j i j Rij 0 = One transition from state i to state j a i j Rij 0 = a Various transitions from state i to state j i a 1 j R 0 ij = a 1 + + a n a n Finite Automata and Regular Expressions 9/40
Basis step: Proof for k = 0 (i.e. no intermediate states) and i = j Finite Automata and Regular Expressions 10/40
Basis step: Proof for k = 0 (i.e. no intermediate states) and i = j No loops i R 0 ii = Finite Automata and Regular Expressions 11/40
Basis step: Proof for k = 0 (i.e. no intermediate states) and i = j No loops One loop i R 0 ii = a i R 0 ii = + a Finite Automata and Regular Expressions 12/40
Basis step: Proof for k = 0 (i.e. no intermediate states) and i = j No loops One loop i R 0 ii = a i R 0 ii = + a Question Why do not to define R 0 ii = a? Finite Automata and Regular Expressions 13/40
Basis step: Proof for k = 0 (i.e. no intermediate states) and i = j No loops One loop i R 0 ii = a i R 0 ii = + a Question Why do not to define R 0 ii = a? Various loops a 1 i a n R 0 ii = + a 1 + + a n Finite Automata and Regular Expressions 14/40
Inductive step: Proof for k Inductive hypothesis Rij k 1 : path from state i to state j that goes through no state higher than k 1. Finite Automata and Regular Expressions 15/40
Inductive step: Proof for k Inductive hypothesis Rij k 1 : path from state i to state j that goes through no state higher than k 1. The path does not go through state k at all i k j R k ij = Rk 1 ij Finite Automata and Regular Expressions 16/40
Inductive step: Proof for k Inductive hypothesis Rij k 1 : path from state i to state j that goes through no state higher than k 1. The path does not go through state k at all i k j R k ij = Rk 1 ij The path goes through state k at least once i k k k j R k ij = Rk 1 ik (Rk 1 kk ) Rkj k 1 Finite Automata and Regular Expressions 17/40
Inductive step: Proof for k Inductive hypothesis Rij k 1 : path from state i to state j that goes through no state higher than k 1. The path does not go through state k at all i k j R k ij = Rk 1 ij The path goes through state k at least once i k k k j From the previous cases: R k ij = Rk 1 ik (Rk 1 kk ) Rkj k 1 R k ij = Rk 1 ij + R k 1 ik (Rk 1 kk ) Rkj k 1 Finite Automata and Regular Expressions 18/40
Given that the states of D are {1, 2,, n} with 1 the start state, then L(D) = L(R n 1f 1 + + R n 1f m ) with f i F. Finite Automata and Regular Expressions 19/40
Example To convert the DFA D to a regular expression. 1 0 start 1 2 0, 1 L(D) = {w {0, 1} w has at least one 0}. Finite Automata and Regular Expressions 20/40
Example (cont.) 1 0 start 1 2 0, 1 R 0 ij R 0 ij Regexp R11 0 + 1 R12 0 0 R 0 21 R 0 22 + 0 + 1 Finite Automata and Regular Expressions 21/40
Example (cont.) R 1 ij = R0 ij + R0 i1 (R0 11 ) R 0 1j R 0 ij Regexp R11 0 + 1 R12 0 0 R 0 21 R 0 22 + 0 + 1 R 1 ij Regexp R11 1 ( + 1) + ( + 1)( + 1) ( + 1) R12 1 0 + ( + 1)( + 1) 0 R21 1 + ( + 1) ( + 1) R22 1 + 0 + 1 + ( + 1) 0 Finite Automata and Regular Expressions 22/40
Example (cont.) Some simplifications for regular expressions Let L and M be regular expression variables. ( + L) = L ( + L)L = L L + M L = M L L = L = L + = + L = L ( is the annihilator for concatenation) ( is the identity for union) Finite Automata and Regular Expressions 23/40
Example (cont.) Rij 1 = R0 ij + R0 i1 (R0 11 ) R1j 0 Rij 1 Regexp Simplified R11 1 ( + 1) + ( + 1)( + 1) ( + 1) 1 R12 1 0 + ( + 1)( + 1) 0 1 0 R21 1 + ( + 1) ( + 1) R22 1 + 0 + 1 + ( + 1) 0 + 0 + 1 Finite Automata and Regular Expressions 24/40
Example (cont.) R 2 ij = R1 ij + R1 i2 (R1 22 ) R 1 2j Rij 1 R11 1 Regexp 1 R 1 12 1 0 R 1 21 R 1 22 + 0 + 1 Rij 2 R11 2 Regexp 1 + 1 0( + 0 + 1) R 2 12 1 0 + 1 0( + 0 + 1) ( + 0 + 1) R 2 21 + ( + 0 + 1)( + 0 + 1) R 2 22 + 0 + 1 + ( + 0 + 1)( + 0 + 1) ( + 0 + 1) Finite Automata and Regular Expressions 25/40
Example (cont.) Rij 2 = R1 ij + R1 i2 (R1 22 ) R2j 1 Rij 2 Regexp Simplified R11 2 1 + 1 0( + 0 + 1) 1 R12 2 1 0 + 1 0( + 0 + 1) ( + 0 + 1) 1 0(0 + 1) R21 2 + ( + 0 + 1)( + 0 + 1) R22 2 + 0 + 1 + ( + 0 + 1)( + 0 + 1) ( + 0 + 1) (0 + 1) Finite Automata and Regular Expressions 26/40
Example (cont.) The regular expression equivalent to the automaton D is R 2 12 = 1 0(0 + 1). Finite Automata and Regular Expressions 27/40
From Regular Expressions to Finite Automata Theorem (3.7) Every language defined by a regular expression is also defined by a finite automaton. Finite Automata and Regular Expressions 28/40
From Regular Expressions to Finite Automata Theorem (3.7) Every language defined by a regular expression is also defined by a finite automaton. Inductive proof For each regular expression R we construct an -NFA E such that L(R) = L(E) with: 1. exactly one accepting state, 2. no arcs into the initial state and 3. no arcs out of the accepting state. Finite Automata and Regular Expressions 29/40
struct and ɛ-nfa A, s.t. L(A) = L(R). From Regular Expressions to Finite Automata Proof: By structural induction: Basis step: Automata for (a), (b) and a (c). Basis: Automata for ɛ,, and a. (a) (b) a (c) 73 Figure from Hopcroft, Motwani and Ullman (2007, Fig. 3.16). Finite Automata and Regular Expressions 30/40
From Regular Expressions to Finite Automata 3.2. Inductive FINITE step: AUTOMATA AutomatonAND for R REGULAR + S. EXPRESSIONS 105 R S (a) R S (b) Figure from Hopcroft, Motwani and Ullman (2007, Fig. 3.17). Finite Automata and Regular Expressions 31/40
From Regular Expressions to Finite Automata S Inductive step: Automaton for RS. (a) R S (b) R (c) Figure 3.17: The inductive step in the regular-expression-to--nfa construction Figure from Hopcroft, Motwani and Ullman (2007, Fig. 3.17). Finite Automata and Regular Expressions 32/40
From Regular Expressions R to Finite Automata S Inductive step: Automaton for R. (b) R (c) Figure 3.17: The inductive step in the regular-expression-to--nfa construction automaton of Fig. 3.17(c). That automaton allows us to go either: (a) Directly from the start state to the accepting state along a path labeled. That path lets us accept, whichisinl(r ) no matter Figure from whathopcroft, expression Motwani R is. and Ullman (2007, Fig. 3.17). Finite Automata and Regular Expressions 33/40
From Regular Expressions to Finite Automata Example Convert the regular expression R = (0 + 1) 1(0 + 1) to an -NFA E such L(R) = L(E). Finite Automata and Regular Expressions 34/40
From Regular Expressions to Finite Automata Example Convert the regular expression R = (0 + 1) 1(0 + 1) to an -NFA E such L(R) = L(E). 1. -NFA for 0 + 1: start 0 1 Finite Automata and Regular Expressions 35/40
From Regular Expressions to Finite Automata Example (cont.) 2. -NFA for (0 + 1) : start 0 1 Finite Automata and Regular Expressions 36/40
From Regular Expressions to Finite Automata Example (cont.) 3. -NFA for (0 + 1) 1: start 0 1 1 Finite Automata and Regular Expressions 37/40
From Regular Expressions to Finite Automata Example (cont.) 4. -NFA for (0 + 1) 1(0 + 1): start 0 1 1 0 1 Finite Automata and Regular Expressions 38/40
From Regular Expressions to Finite Automata Exercise (3.2.7) There are some simplifications to the constructions of Theorem 3.7, where we converted a regular expression to an -NFA. Here are three: 1. For the union operator, instead of creating new start and accepting states, merge the two start states into one state with all the transitions of both start states. Likewise, merge the two accepting states, having all transitions to either go to the merged state instead. 2. For the concatenation operator, merge the accepting state of the first automaton with the start state of the second. 3. For the closure operator, simply add -transitions from the accepting state to the start state and vice-versa. Each of these simplifications, by themselves, still yield a correct construction; that is, the resulting -NFA for any regular expression accepts the language of the expression. Which subsets of changes (1), (2) and (3) may be made to the construction together, while still yielding a correct automaton for every regular expression? Finite Automata and Regular Expressions 39/40
References Hopcroft, J. E., Motwani, R. and Ullman, J. D. (2007). Introduction to Automata theory, Languages, and Computation. 3rd ed. Pearson Education (cit. on pp. 4, 5, 30 33). Finite Automata and Regular Expressions 40/40