Automata and Formal Languages - CM0081
Finite Automata and Regular Expressions
Andrés Sicard-Ramírez
Universidad EAFIT
Semester 2017-2
Introduction
DFA
NFA
π-NFA
RE
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
2/39
From Finite Automata to Regular Expressions
Theorem (Hopcroft, Motwani and Ullman [2007], Theorem 3.4)
If πΏ = πΏ(π΄) for some DFA π΄, then there is a regular expression π
such that πΏ = πΏ(π
).
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
3/39
From Finite Automata to Regular Expressions
Inductive proof on the number of states of the automaton
Let the states of π΄ be {1, 2, β¦ , π} with 1 the start state.
β
Hopcroft, Motwani and Ullman [2007, Fig. 3.2].
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
4/39
From Finite Automata to Regular Expressions
Inductive proof on the number of states of the automaton
Let the states of π΄ be {1, 2, β¦ , π} with 1 the start state.
π
π
ππ
: Regular expression describing the set of labels of all paths
in π΄ from state π to state π such that the path has no
intermediate node whose number is greater than π.β
β
Hopcroft, Motwani and Ullman [2007, Fig. 3.2].
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
5/39
From Finite Automata to Regular Expressions
Basis step: Proof for π = 0 (i.e. no intermediate states) and π β π
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
6/39
From Finite Automata to Regular Expressions
Basis step: Proof for π = 0 (i.e. no intermediate states) and π β π
No transition from state π to state π
π
π
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
0
π
ππ
=β
7/39
From Finite Automata to Regular Expressions
Basis step: Proof for π = 0 (i.e. no intermediate states) and π β π
No transition from state π to state π
π
π
0
π
ππ
=β
One transition from state π to state π
π
a
π
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
0
π
ππ
=a
8/39
From Finite Automata to Regular Expressions
Basis step: Proof for π = 0 (i.e. no intermediate states) and π β π
No transition from state π to state π
π
π
0
π
ππ
=β
One transition from state π to state π
π
a
π
0
π
ππ
=a
Various transitions from state π to state π
a1
0
β¦
π
ππ
= a1 + β― + an
π
π
aπ
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
9/39
From Finite Automata to Regular Expressions
Basis step: Proof for π = 0 (i.e. no intermediate states) and π = π
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
10/39
From Finite Automata to Regular Expressions
Basis step: Proof for π = 0 (i.e. no intermediate states) and π = π
No loops
π
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
0
π
ππ
=π
11/39
From Finite Automata to Regular Expressions
Basis step: Proof for π = 0 (i.e. no intermediate states) and π = π
No loops
0
π
ππ
=π
π
One loop
a
π
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
0
π
ππ
=π+a
12/39
From Finite Automata to Regular Expressions
Basis step: Proof for π = 0 (i.e. no intermediate states) and π = π
No loops
0
π
ππ
=π
π
One loop
a
π
0
π
ππ
=π+a
0
0
Question: Why not define π
ππ
by π
ππ
= π + aβ ?
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
13/39
From Finite Automata to Regular Expressions
Basis step: Proof for π = 0 (i.e. no intermediate states) and π = π
No loops
0
π
ππ
=π
π
One loop
a
0
π
ππ
=π+a
π
0
0
Question: Why not define π
ππ
by π
ππ
= π + aβ ?
Various loops
a1
π
β¦
aπ
0
π
ππ
= π + a1 + β― + an
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
14/39
From Finite Automata to Regular Expressions
Inductive step: Proof for π
πβ1
Inductive hypothesis π
ππ
: path from state π to state π that goes
through no state higher than π β 1.
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
15/39
From Finite Automata to Regular Expressions
Inductive step: Proof for π
πβ1
Inductive hypothesis π
ππ
: path from state π to state π that goes
through no state higher than π β 1.
The path does not through state π at all
π
π
π
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
π
πβ1
π
ππ
= π
ππ
16/39
From Finite Automata to Regular Expressions
Inductive step: Proof for π
πβ1
Inductive hypothesis π
ππ
: path from state π to state π that goes
through no state higher than π β 1.
The path does not through state π at all
π
π
πβ1
π
ππ
= π
ππ
π
π
The path goes through state π at least once
π
π
π
π
π
π
πβ1
πβ1 β πβ1
π
ππ
= π
ππ
(π
ππ
) π
ππ
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
17/39
From Finite Automata to Regular Expressions
Inductive step: Proof for π
πβ1
Inductive hypothesis π
ππ
: path from state π to state π that goes
through no state higher than π β 1.
The path does not through state π at all
π
π
πβ1
π
ππ
= π
ππ
π
π
The path goes through state π at least once
π
π
π
π
π
π
πβ1
πβ1 β πβ1
π
ππ
= π
ππ
(π
ππ
) π
ππ
From the previous cases:
π
πβ1
πβ1
πβ1 β πβ1
π
ππ
= π
ππ
+ π
ππ
(π
ππ
) π
ππ
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
18/39
From Finite Automata to Regular Expressions
Given that the states of π΄ are {1, 2, β¦ , π} with 1 the start state,
then
π
π
πΏ(π΄) = πΏ(π
1π
+ β― + π
1π
) with ππ β πΉ .
1
π
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
19/39
From Finite Automata to Regular Expressions
Example
To convert the DFA π΄ to a regular expression.
1
start
1
0
2
0, 1
πΏ(π΄) = {π€ β {0, 1}β β£ π€ has at least one 0}.
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
20/39
From Finite Automata to Regular Expressions
Example (cont.)
1
start
1
0
2
0, 1
0
π
ππ
0
π
ππ
Regexp
0
π
11
π+1
0
π
12
0
0
π
21
β
0
π
22
π+0+1
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
21/39
From Finite Automata to Regular Expressions
Example (cont.)
1
0
0
0 β 0
π
ππ
= π
ππ
+ π
π1
(π
11
) π
1π
0
π
ππ
Regexp
1
π
ππ
Regexp
0
π
11
π+1
1
π
11
(π + 1) + (π + 1)(π + 1)β (π + 1)
0
π
12
0
1
π
12
0 + (π + 1)(π + 1)β 0
0
π
21
β
1
π
21
β
+ β
(π + 1)β (π + 1)
0
π
22
π+0+1
1
π
22
π + 0 + 1 + β
(π + 1)β 0
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
22/39
From Finite Automata to Regular Expressions
Example (cont.)
Some simplifications for regular expressions
Let πΏ and π be regular expression variables.
(π + πΏ)β = πΏβ
(π + πΏ)πΏβ = πΏβ
πΏ + π βπΏ = π βπΏ
πΏβ
= β
πΏ = β
(β
is the annihilator for concatenation)
πΏ + β
= β
+ πΏ = πΏ (β
is the identity for union)
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
23/39
From Finite Automata to Regular Expressions
Example (cont.)
1
0
0
0 β 0
π
ππ
= π
ππ
+ π
π1
(π
11
) π
1π
1
π
ππ
Regexp
Simplified
1
π
11
(π + 1) + (π + 1)(π + 1)β (π + 1)
1β
1
π
12
0 + (π + 1)(π + 1)β 0
1β 0
1
π
21
β
+ β
(π + 1)β (π + 1)
β
1
π
22
π + 0 + 1 + β
(π + 1)β 0
π+0+1
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
24/39
From Finite Automata to Regular Expressions
Example (cont.)
2
1
1
1 β 1
π
ππ
= π
ππ
+ π
π2
(π
22
) π
2π
1
π
ππ
Regexp
2
π
ππ
1
π
11
1
π
12
1
π
21
1
π
22
1β
2
π
11
2
π
12
2
π
21
2
π
22
1β 0
β
π+0+1
Regexp
1β
+
1β 0(π
+ 0 + 1)β β
1β 0 + 1β 0(π + 0 + 1)β (π + 0 + 1)
β
+ (π + 0 + 1)(π + 0 + 1)β β
π + 0 + 1 + (π + 0 + 1)(π + 0 + 1)β (π + 0 + 1)
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
25/39
From Finite Automata to Regular Expressions
Example (cont.)
2
1
1
1 β 1
π
ππ
= π
ππ
+ π
π2
(π
22
) π
2π
2
π
ππ
2
π
11
2
π
12
2
π
21
2
π
22
Regexp
1β
+
1β 0(π
+0+
Simplified
1)β β
1β
1β 0 + 1β 0(π + 0 + 1)β (π + 0 + 1)
1β 0(0 + 1)β
β
+ (π + 0 + 1)(π + 0 + 1)β β
β
π + 0 + 1 + (π + 0 + 1)(π + 0 + 1)β (π + 0 + 1)
(0 + 1)β
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
26/39
From Finite Automata to Regular Expressions
Example (cont.)
The regular expression equivalent to the automaton π΄ is
2
π
12
= 1β 0(0 + 1)β .
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
27/39
From Regular Expressions to Finite Automata
Theorem (Hopcroft, Motwani and Ullman [2007], Theorem 3.7)
Every language defined by a regular expression is also defined by a
finite automaton.
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
28/39
From Regular Expressions to Finite Automata
Theorem (Hopcroft, Motwani and Ullman [2007], Theorem 3.7)
Every language defined by a regular expression is also defined by a
finite automaton.
Inductive proof
For each regular expression π
we construct an π-NFA πΈ such that
πΏ(π
) = πΏ(πΈ) with:
1. exactly one accepting state,
2. no arcs into the initial state and
3. no arcs out of the accepting state.
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
29/39
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
β
Hopcroft, Motwani and Ullman [2007, Fig. 3.16].
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
30/39
From Regular Expressions to Finite Automata
3.2.
FINITE
AUTOMATA
AND
Inductive
step:
Automaton
for REGULAR
π
+ π.β EXPRESSIONS
Ξ΅
Ξ΅
R
S
105
Ξ΅
Ξ΅
(a)
R
Ξ΅
S
(b)
β
Hopcroft, Motwani and Ullman [2007, Fig.Ξ΅ 3.17].
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
31/39
Ξ΅
Ξ΅
From Regular Expressions to Finite Automata
S
Inductive step: Automaton for π
π.(βa)
Ξ΅
R
S
(b)
Ξ΅
Ξ΅
R
Ξ΅
Ξ΅
(c)
Figure
3.17: The inductive step in the regular-expression-to--NFA construction
β
Hopcroft, Motwani and Ullman [2007, Fig. 3.17].
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
32/39
Ξ΅
R
S
From Regular Expressions to Finite Automata
(b)
Inductive step: Automaton for π
β .β
Ξ΅
Ξ΅
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 , which is in L(R ) no matter
what
expression
is. [2007, Fig. 3.17].
β
Hopcroft, Motwani
and R
Ullman
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
33/39
From Regular Expressions to Finite Automata
Example
Convert the regular expression π
= (0 + 1)β 1(0 + 1) to an π-NFA πΈ
such πΏ(π
) = πΏ(πΈ).
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
34/39
From Regular Expressions to Finite Automata
Example
Convert the regular expression π
= (0 + 1)β 1(0 + 1) to an π-NFA πΈ
such πΏ(π
) = πΏ(πΈ).
1. π-NFA for 0 + 1:
π
0
π
start
π
1
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
π
35/39
From Regular Expressions to Finite Automata
Example (cont.)
2. π-NFA for (0 + 1)β :
start
π
π
π
π
0
1
π
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
π
π
π
36/39
From Regular Expressions to Finite Automata
Example (cont.)
3. π-NFA for (0 + 1)β 1:
start
π
π
π
π
0
1
π
π
π
π
1
π
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
37/39
From Regular Expressions to Finite Automata
Example (cont.)
4. π-NFA for (0 + 1)β 1(0 + 1):
start
π
π
π
π
0
1
π
π
π
π
π
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
1
π
π
π
0
1
π
π
38/39
References
Hopcroft, J. E., Motwani, R. and Ullman, J. D. (2007). Introduction to
Automata theory, Languages, and Computation. 3rd ed. Pearson
Education.
Automata and Formal Languages - CM0081. Finite Automata and Regular Expressions
39/39
© Copyright 2026 Paperzz