CHAPTER2 AUTOMATA Landscape
CHAPTER2 AUTOMATA Landscape
MATHEMATICAL MODELING
Methods and Applications
Chapter 2
AUTOMATA THEORY-
A. BASIC TERMS
B. AUTOMATA
MATHEMATICAL MODELING
Methods and Applications
3
COURTESY:
Some material of chapter 1 (Logic Theory) and 2 (Automat Theory) are borrowed from texts
1. REF. 1: MICHAEL HUTH and MARK RYAN. LOGIC IN COMPUTER SCIENCE - Modelling
and Reasoning about Systems, Chapter 1,2,4 [2nd ed., Cambridge University Press 2004]
2. REF. 2: MICHAEL HUTH and MARK RYAN. Solutions Manual - LOGIC IN COMPUTER
MATHEMATICAL MODELING
Methods and Applications
2.1. PART A. BASIC TERMS 4
1. Computer science a very diverse (with many important topics), but in spite of this diversity,
there are some common underlying principles. To study these basic principles, we construct
2. Why study automata theory? Automata theory provides such abstract model, its ideas
have some important applications, both software (programming languages, and compilers
3. An automaton 1 : a construct that possesses all the features of a digital computer, or any
process. It accepts input, produces output, may have some storage, and can make decisions
in transforming the input into the output, see Figure 2.1, in which we use notations below.
MATHEMATICAL MODELING
Methods and Applications
2.1. PART A. BASIC TERMS 5
MATHEMATICAL MODELING
Methods and Applications
2.1. PART A. BASIC TERMS 6
The set of all lower-case letters: Σ = {𝑎, 𝑏, 𝑐, . . . , 𝑧} ... And other sets.
Σ consists of almost all available characters (lowercase and capital letters, numbers, sym-
bols and special characters as space or Greek characters 𝛼, 𝛽...).
MATHEMATICAL MODELING
Methods and Applications
2.1. PART A. BASIC TERMS 7
Question: How about {𝜀}, {0, 00, 001}, are they languages over Σ = {0, 1} ?
guages.
(ii) formation rules by which these symbols are combined into entities called sentences.
5. Operations on languages:
Because languages are sets, hence set operators as the union, intersection, difference ...
MATHEMATICAL MODELING
Methods and Applications
2.1. PART A. BASIC TERMS 8
The reverse of a language is the set of all string reversals, that is,
𝐿𝑅 = {𝑤𝑅 : 𝑤 ∈ 𝐿.}
♦ EXAMPLE 2.1.
b) 𝐿1 ∩ 𝐿2 =? 𝐿1 ∖ 𝐿2 =?
c) 𝐿1 𝐿2 =? 𝐿1𝐿2 = {𝑎𝑏𝑏, 𝑎𝑎𝑏, 𝑏𝑏, 𝑎𝑏𝑐𝑎, 𝑎𝑎𝑐𝑎, 𝑏𝑐𝑎, 𝑎𝑏𝑏𝑎𝑐, 𝑎𝑎𝑏𝑎𝑐, 𝑏𝑏𝑎𝑐},
d) 𝐿2 𝐿1 =? Now newly define 𝐿 = {𝑎𝑏, 𝑎𝑎, 𝑏, 𝑐𝑎, 𝑏𝑎𝑐}, find 𝐿2 =?
PRACTICE 2.1.
1. Prove by induction that: If 𝑢 and 𝑣 are strings, then the length of their concatenation is the
MATHEMATICAL MODELING
Methods and Applications
2.2. Determining a language 10
PRACTICE 2.2.
Let Σ = {𝑎, 𝑏, 𝑐}. Give at least 5 strings for each of the following languages
MATHEMATICAL MODELING
Methods and Applications
2.2. Determining a language 11
b) Using a property, such that all words of the language have this property but other words
have not.
(it is in fact 𝐿3 = {𝜀, 𝑎𝑏, 𝑎𝑎𝑏𝑏, 𝑎𝑎𝑎𝑏𝑏𝑏, . . .} in PRACTICE 2.1 above by enumeration).
Also using property on string length gives 𝐿6 = {𝑢 ∈ Σ* | 𝑛𝑎 (𝑢) = 𝑛𝑏 (𝑢)}, where 𝑛𝑐 (𝑢)
MATHEMATICAL MODELING
Methods and Applications
2.2. Determining a language 12
𝑥 → 𝑦, 𝑥 ∈ (𝑉 ∪ 𝑇 )+ and 𝑦 ∈ (𝑉 ∪ 𝑇 )*.
We say that string 𝑤 derives string 𝑧 (or that 𝑧 is derived from 𝑤).
MATHEMATICAL MODELING
Methods and Applications
2.2. Determining a language 13
ELUCIDATION
1. Briefly, the production rules of grammar 𝐺 specify how the grammar transforms one string
into another, and they define a language associated with the grammar.
2. Successive strings are generally derived by applying such productions of the grammar 𝐺 in
MATHEMATICAL MODELING
Methods and Applications
2.2. Determining a language 14
♦ EXAMPLE 2.3.
MATHEMATICAL MODELING
Methods and Applications
2.2. Determining a language 15
*
We see 𝑆 ⇒ 𝑎𝑆𝑏 ⇒ 𝑎𝑎𝑆𝑏𝑏 = 𝑎2 𝑆𝑏2 ⇒ 𝑎2 𝑏2 ... then 𝑆 ⇒ 𝑎𝑎𝑏𝑏 = 𝑎2 𝑏2 .
♦ EXAMPLE 2.4.
MATHEMATICAL MODELING
Methods and Applications
2.2. Determining a language 16
Or 𝑆 ⇒ 𝑀 𝑏 ⇒ 𝑎𝑀 𝑏𝑏 ⇒ 𝑎𝑎𝑀 𝑏𝑏𝑏? ■
Often it is not so easy to find a grammar for a language described in an informal way, or to
cally that a given language 𝐿 is indeed generated by a certain grammar 𝐺, we must be able
to show
(a) that every word 𝑤 ∈ 𝐿 can be derived from the start variable 𝑆 using 𝐺 and
a
Theorem (REF. 3, p 17): Not all languages can be generated by grammars.
a
Antal Iványi. Algorithms of Informatics, AnTonCom Budapest (2010).
MATHEMATICAL MODELING
Methods and Applications
2.2. Determining a language 17
PRACTICE 2.3. Denote 𝑛𝑐 (𝑢) the number of letter ’c’ in any word 𝑢.
PRACTICE 2.4.
MATHEMATICAL MODELING
Methods and Applications
2.3. Regular Expressions 18
Definition 2.3
Regular expressions over some given alphabet Σ involve a combination of ♣
(︀)︀
♦ strings of symbols from Σ, parentheses , and
MATHEMATICAL MODELING
Methods and Applications
2.3. Regular Expressions 19
But (𝑎 + 𝑏 +) is not a regular expression, since there is no way it can be constructed from
MATHEMATICAL MODELING
Methods and Applications
2.3. Regular Expressions 20
representing language 𝐿.
The language 𝐿(𝑟) ⊂ Σ* associated with expression 𝑟 is defined by the following rules.
MATHEMATICAL MODELING
Methods and Applications
2.3. Regular Expressions 21
spectively. Then (𝑟+𝑠), (𝑟·𝑠), 𝑟 * are regular expressions, (so they) respectively representing
𝑌 , 𝑋 𝑌 , and 𝑋 *. Explicitly,
⋃︀
languages 𝑋
⋃︀
4. 𝐿(𝑟 + 𝑠) ≡ 𝐿(𝑟) + 𝐿(𝑠) = 𝑋 𝑌
6. 𝐿((𝑟)) ≡ 𝐿(𝑟) = 𝑋
)︀*
7. 𝐿(𝑟 * ) ≡ 𝐿(𝑟) = 𝑋 *.
(︀
The language 𝐿(𝑎* · (𝑎 + 𝑏)) = 𝐿(𝑎* ) 𝐿(𝑎 + 𝑏) = ...? = {𝑎, 𝑎𝑎, 𝑎𝑎𝑎, . . . , 𝑏, 𝑎𝑏, 𝑎𝑎𝑏, . . .}
𝑟 = (𝑎 + 𝑏)* represents all the (regular) strings of of 𝑎’s and 𝑏’s, any order.
)︀*
So language 𝐿(𝑟) = 𝐿(𝑎 + 𝑏) = Σ* ?
(︀
■
MATHEMATICAL MODELING
Methods and Applications
2.3. Regular Expressions 22
We also employ the following properties, applied for regular expressions 𝑥, 𝑟 and 𝑠.
(𝑥 + 𝑟) + 𝑠 ≡ 𝑥 + (𝑟 + 𝑠);
(𝑥𝑟)𝑠 ≡ 𝑥(𝑟𝑠)
(𝑥 + 𝑟)* ≡ (𝑥*𝑟*)*
(𝑟*)* ≡ 𝑟*
𝑥*𝑥 ≡ 𝑥𝑥*;
𝑥𝑥* + 𝜀 ≡ 𝑥*
MATHEMATICAL MODELING
Methods and Applications
2.3. Regular Expressions 23
PROBLEM 2.1.
On the alphabet Σ = {𝑎, 𝑏, 𝑐}, give at least 5 words for each language represented by the
a) 𝐸1 = 𝑎* + 𝑏* ,
Hint for c): You will prove firstly 𝐿2 = 𝐿(𝑠) = 𝐿(𝑎* · (𝑎 + 𝑏)) = {𝑎𝑛+1 , 𝑎𝑚 𝑏 | 𝑛, 𝑚 ≥ 0}.
MATHEMATICAL MODELING
Methods and Applications
2.3. Regular Expressions 24
PROBLEM 2.2.
1. 𝐸1 = 𝜀 + 𝑎𝑏 + 𝑎𝑏𝑎𝑏(𝑎𝑏)* ,
MATHEMATICAL MODELING
Methods and Applications
PART B. AUTOMATA
[[GoogleMap]]
2.4. PART B. FINITE AUTOMATA 26
the vertices give the initial states and one or several final/accepting states, and the edges
MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 27
𝑤
A string 𝑤 = 𝑎1 𝑎2 · · · 𝑎𝑛 ∈ Σ* is accepted by an automaton 𝑀 if symbolically 𝑞 ⇝ 𝑞𝑤 ∈
♦ EXAMPLE 2.8.
(︀ )︀
This state diagram shows the two-state finite automaton 𝑀 = {𝑞1 , 𝑞2 }, {0, 1}, 𝑞1 , 𝛿, {𝑞2 } ,
where 𝐹 = {𝑞2 } (unique accepting state), the transition function 𝛿 is given by table below,
that is 𝛿(𝑞1 , 0) = 𝑞1 , 𝛿(𝑞1 , 1) = 𝑞2 and so on. Final states are drawn with a double circle.
MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 28
0 1
𝑞1 𝑞 1 𝑞2
𝑞2 𝑞 1 𝑞2
MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 29
But string 𝑠 = 110 leaves 𝑀 in state 𝑞1 , so it is rejected. You would see that
𝑀 accepts all strings that end in a 1. Thus the language of 𝑀 , 𝐿(𝑀 ) = {𝑤| 𝑤 ends in a 1 }.
𝑎 = 1, 𝑏 = 0 on the machine 𝑀 then we get the same conclusion, for 𝑟 = 𝑎𝑎𝑏𝑎 ∈ 𝑎*(𝑏 + 𝑎).
■
MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 30
𝑏
𝑎, 𝑏
𝑞0 𝑞1
PROBLEM 2.3.
1) 𝑎3 𝑏,
2) 𝑎𝑏𝑎2 𝑏,
3) 𝑎4 𝑏2 𝑎𝑏3 𝑎,
4) 𝑎4 𝑏𝑎4 ,
5) 𝑎𝑏4 𝑎9 𝑏,
MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 31
𝑎 𝑏
𝑏
𝑞0 𝑞1 𝑎 𝑞2
𝑏
𝑎
II) Do Exercises on page 4.2x, for 𝑥 = 4, 5, 6 of REF. 1.
MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 32
(𝑄, Σ, 𝐼, 𝛿, 𝐹 ) where ♣
ELUCIDATION
MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 33
Rather than prescribing a unique move in each situation, we allow a set of possible moves.
An NFA is a directed, labeled graph, named the transition graph 𝑇 (𝑀 ) = (𝑉, 𝐸) of automaton 𝑀 ,
whose node set 𝑉 ≡ 𝑄 and 𝐸 = {(𝑝, 𝑎, 𝑞)}, consisting of transitions - directed edges [la-
Initial states are marked by a small arrow entering the corresponding vertex,
while the final states are marked with double circles [as 𝑞4 in the next figure].
MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 34
♦ EXAMPLE 2.10. Fix 𝑄 = {𝑞1, 𝑞2, 𝑞3, 𝑞4} and Σ = {0, 1, 𝜀}.
MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 35
* The transition graph 𝑇 (𝑀 ) of 𝑀 has edges (𝑞1 , 𝑞1 ) and (𝑞1 , 𝑞2 ) with label 𝑎 = 1.
MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 36
We need two more concepts for the next definition (language accepted by NFA).
We say that
if this word is the label of a productive walk (that is, there is some sequence of possible
moves that will put the machine in a final state 𝑞𝑛 at the end of the string.)
The set of words accepted by an NFA is called the language accepted by this NFA.
MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 37
𝑤
Explicitly this means for each string 𝑤 ∈ 𝐿(𝑀 ) there is a walk labeled 𝑞 −→ 𝑝 from an
So instead of using
MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 38
The language accepted by an NFA so is defined by the extended transition 𝛿 * (𝑞, 𝑤) [Def.
2.8].
(Kleene)].
Let 𝑟 be a regular expression. Then there exists some nondeterministic finite automaton
(NFA) that accepts the language 𝐿(𝑟). Consequently, 𝐿(𝑟) is a regular language.
We discuss more on the equivalence connection between regular languages and regular
1. Regular Expressions define regular languages: how construct an NFA 𝑀 from a given reg-
MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 39
2. Regular Languages give regular expressions: from a regular language 𝐿, find a regular
PROBLEM 2.4.
(I) Consider the set of strings on Σ = {𝑎, 𝑏} in which every 𝑎𝑎 is followed immediately by 𝑏.
For example 𝑎𝑎𝑏, 𝑎𝑎𝑏𝑎, 𝑎𝑎𝑏𝑎𝑎𝑏𝑏𝑎𝑎𝑏 are in the language, but 𝑎𝑎𝑎𝑏 and 𝑎𝑎𝑏𝑎𝑎 are not.
𝑎 𝑏
𝑏
𝑞0 𝑞1 𝑎 𝑞2
𝑏
𝑎
MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 40
𝑀 = (𝑄, Σ, 𝑞0, 𝛿, 𝐹 )
with
4. 𝛿 : 𝑄 × Σ → 𝑄 is a transition function,
ELUCIDATION
MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 41
|𝛿(𝑞, 𝑎)| ≤ 1, ∀𝑞 ∈ 𝑄, ∀𝑎 ∈ Σ
in Defi. 2.7.
The fact |𝛿(𝑞, 𝑎)| = 0 says 𝛿(𝑞, 𝑎) = ∅ (nonfinal trap state in the DFA):
Given a walk 𝑟 = 𝑎𝑏𝑐 . . . 𝑠 (series of accepted arrows/ letters/ actions), and a state 𝑞 ,
the automaton 𝑀 starts with the transition function, called an application 𝛿(𝑞, 𝑎) = 𝑝.
MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 42
𝑎 𝑏 𝑠
𝑞 −→ 𝑝 −→ · · · −→ 𝑝𝑛
The input mechanism then advances one position to the right, as a result
The transition graph 𝑇 (𝑀 ) of finite automaton 𝑀 has an edge (𝑞, 𝑝) with label 𝑎...
the string is accepted if the automaton is in state 𝑝𝑛 ∈ 𝐹 (one of its final states):
𝑎 𝑏 s
𝑞 −→ 𝑝 −→ · · · −→ pn.
♦ EXAMPLE 2.11.
The figure shows the transition graph 𝑇 (𝑀 ) of a DFA = 𝑀 = (𝑄, Σ, 𝑞0 , 𝛿, 𝐹 ) with 𝐹 = {𝑞1 }.
MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 43
ii/ Check 𝑀 recognizes the set 𝐴 of strings which contain an odd number of 𝑎, that is
𝐿(𝑀 ) = 𝐴.
iii/ Determine a new machine 𝑀𝐵 accepts the set 𝐵 of strings which contain an even number
of 𝑎, that is 𝐵 = 𝐿(𝑀𝐵 ).
MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 44
HINT: Obviously 𝑄 = {𝑞0 , 𝑞1 }, the alphabet Σ = {𝑎, 𝑏}, and the set 𝐹 = {𝑞1 } of accepting
states.
a b
→ 𝑞0 𝑞1 𝑞0
𝑞1 𝑞0 𝑞1
ii/: Need to write the pattern of strings 𝑟 ∈ 𝐴 which contain an odd number of 𝑎, as
𝑟 = 𝑏*𝑎𝑛𝑏*, 𝑛 = 2𝑘 + 1?
Then check the equality 𝛿(𝑞0 , 𝑟) = 𝑞1 ∈ 𝐹 if and only if 𝑟 has the above pattern only.
𝑠 = 𝑏*𝑎𝑚𝑏*, 𝑚 = 2𝑘 =⇒ 𝐵 = 𝐿(𝑀𝐵 )
MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 45
Proposition 2.1
Transition graphs provide convenient ways for working with FA. ♠
Give a DFA that accepts all words that contain a number of 0 multiple of 3.
Define the states 𝑄, the transition 𝛿 and set 𝐹 of accepting states properly.
MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 46
Then define a transition 𝛿 such that 𝛿(𝑞𝑜 , 𝑤) ∈ 𝐹 for any word 𝑤 satisfying that 𝑛0 (𝑤) mod 3 = 0
1 1
0
𝑞0 𝑞1
0
iii) What if we redefine states 𝑄 = {𝑞0 , 𝑞1 , 𝑞2 }, and 𝐹 = {𝑞1 , 𝑞2 }? Can we redraw the graph
as
1 1 1
0 0
𝑞0 𝑞1 𝑞2
0 0
MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 47
MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 48
WHAT NEXT?
1. Construction of a DFA and NFA from a given language 𝐿, or a given regular expression 𝐸 ,
2. Equivalence of automata: Build a DFA from a given NFA, see Section 2.6.1;
Why? For an NFA, for a single input given to a single state, the machine can go to more
than one state. So, for an NFA, it is hard to decide for a string to be accepted by the NFA or
MATHEMATICAL MODELING
Methods and Applications
WEEK 5 - Finite Automata- Basic Problems
[[GoogleMap]]
by productive words 𝑤:
𝐿(𝑀 ) = {𝑤 ∈ Σ* : 𝛿 *(𝑞0, 𝑤) ̸∈ 𝐹 }.
MATHEMATICAL MODELING
Methods and Applications
2.5. Finite Automata- Basic Problems 51
Proposition 2.2
Given two accepted (recognized) languages 𝑋, 𝑌 by certain DFA 𝑀
MATHEMATICAL MODELING
Methods and Applications
2.5. Finite Automata- Basic Problems 52
Denote the DFA by 𝑀 = (𝑄, Σ, 𝑞0 , 𝛿, 𝐹 ), where 𝑞0 ̸∈ 𝐹 . Need to find function 𝛿 and set 𝐹 .
KEY FACTS:
(1) Any string 𝑆 ∈ Σ* built up from the alphabet Σ = {𝑎, 𝑏} can have any fixed length, and
written as 𝑆 = (𝑎 + 𝑏)* .
(2) The fact of 𝐿(𝑀 ) = 𝐿 ∋ 𝑎𝑏 [ the language 𝐿 contains the sub-string 𝑎𝑏]
The substring 𝑎𝑏 acts on the initial 𝑞0 in 2 steps to give the final state 𝑞2 via 𝑞1 (w.l.g), hence
𝑎𝑏
state 𝑞2 ∈ 𝐹 . The initial 𝑞0 ̸∈ 𝐹 , also 𝑞1 ̸∈ 𝐹 , hence |𝐹 | = 1, we get 𝑞0 → 𝑞2 ∈ 𝐹.
MATHEMATICAL MODELING
Methods and Applications
2.5. Finite Automata- Basic Problems 53
(︀ )︀
We get 𝑀 = {𝑞0 , 𝑞1 , 𝑞2 }, {𝑎, 𝑏}, 𝑞0 , 𝛿, {𝑞2 } , where the transition 𝛿 is given by the table
𝑎 𝑏
→ 𝑞0 𝑞1 𝑞0
𝑞1 𝑞1 𝑞2
𝑞2 * 𝑞2 𝑞2
*
Here means final state(s). Can you draw the FA or transition graph 𝑇 (𝑀 )?
MATHEMATICAL MODELING
Methods and Applications
2.5. Finite Automata- Basic Problems 54
PRACTICE 2.6.
Determine a DFA that recognizes the language over the alphabet {𝑎, 𝑏} with an even number
Automaton:
Shall we provide a deterministic machine 𝑀 so that each productive word in its language
MATHEMATICAL MODELING
Methods and Applications
2.5. Finite Automata- Basic Problems 55
𝑎 𝑏
→ 𝑞0* 𝑞2 𝑞1
𝑞1 𝑞3 𝑞0
𝑞2 𝑞0 𝑞3
𝑞3 𝑞1 𝑞2
and diagram
𝑏
𝑞0 𝑞1
𝑏
𝑎 𝑎 𝑎 𝑎
𝑏
𝑞2 𝑞3
𝑏
MATHEMATICAL MODELING
Methods and Applications
2.5. Finite Automata- Basic Problems 56
Definition 2.11.II) says that a language 𝐿 is regular if it is accepted by some DFA. We will
see that NFA and DFA are equivalent, [see Section 2.6], so 𝐿 is also regular if it is accepted by
some NFA.
(II) For every NFA 𝑀0 there is an equivalent one 𝑀1 with a single final state. ♡
Fact 2.1.
1. Given a regular expression 𝑟 , then there exists an NFA 𝑀 (𝑟) accepting the regular language
𝐿(𝑟), and the symbolic (or schematic) representation of 𝑀 (𝑟) is shown in Figure 2.3.a).
MATHEMATICAL MODELING
Methods and Applications
2.5. Finite Automata- Basic Problems 57
2. The simple (primitive) regular expressions ∅, 𝜀(𝜆), and 𝑎 ∈ Σ determine the automata (and
MATHEMATICAL MODELING
Methods and Applications
2.5. Finite Automata- Basic Problems 58
3. The automaton 𝑀 (𝑟1 · 𝑟2 ) of product of two regular expressions 𝑟1 , 𝑟2 is given Figure 2.4.
WHY?
●
The automaton for the language L(r1 r2)= L(r1) L(r2), as the language of
the concatenation of 2 automata M1 and M2
Construct an NFA with 3 states 𝑄 = {𝑞0 , 𝑞1 , 𝑞2 }, and the alphabet Σ = {𝑎, 𝑏}, that recog-
HINT: see Figure 2.5. The left top figure shows machine 𝑀1 accepting language
MATHEMATICAL MODELING
Methods and Applications
2.5. Finite Automata- Basic Problems 59
𝐿1 = 𝐿(𝑟1) = 𝐿((𝑎 + 𝑏𝑏)*) = 𝐿(𝑎 + 𝑏𝑏), the left bottom figure shows 𝑀2 accepting
𝐿2 = 𝐿(𝑟2) = 𝐿((𝑏𝑎* + 𝜀)) = 𝐿((𝑏𝑎* 𝜀 + 𝜀)). The result machine 𝑀 = 𝑀 (𝑟1 𝑟2) = 𝑀1 · 𝑀2.
MATHEMATICAL MODELING
Methods and Applications
2.5. Finite Automata- Basic Problems 60
Construct DFAs (automata) that recognize the languages represented by the following reg-
ular expressions
DIY: See Figures 3.3 till 3.5 in REF.2. for automata 𝑀 (𝑟1 + 𝑟2 ) and 𝑀 (𝑟1* ), given regular
expressions 𝑟1 , 𝑟2 .
MATHEMATICAL MODELING
Methods and Applications
PART C. Equivalence of DFA and NFA
[[GoogleMap]]
2.6. PART C: Equivalence of DFA and NFA 62
When we compare different classes of automata, the question invariably arises whether one
class is more powerful than the other. The observable pros and cons of NFA and DFA, as well
♣ OBSERVATION 1.
1. A DFA (deterministic automaton) is in essence a restricted kind of NFA, it is clear that any
deterministic and nondeterministic finite automata recognize the same class of languages.
2. Although the classes of dfa’s and nfa’s are in fact equally powerful, as seen by the following
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 63
𝑀1 and 𝑀2, are said to be equivalent if they both accept the same language,
𝐿(𝑀1) = 𝐿(𝑀2).
♦ EXAMPLE 2.15.
The DFA shown in top-left of Figure 2.6 is equivalent to the NFA (non-deterministic one) in its
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 64
DFA
NFA
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 65
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 66
The initial state set 𝐼 (of NFA) becomes the initial node of 𝑇𝐷 .
2. After an NFA has read a string 𝑤, we may not know exactly what state it will be in,
but, by definition, we can say that it must belong to a set of possible states 𝑆 ⊂ 𝑄:
𝑤
𝑞0 −→ 𝑢𝑗 ∈ 𝑆
An equivalent DFA after reading the same string 𝑤 must be in some definite set 𝑆𝑛 ,
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 67
2) Enlarging 𝑇𝐷 : At loop 𝑛 ≥ 1, repeat next steps until no more edges are missing.
i) - Take any vertex 𝑆 = {𝑢𝑗 } of 𝑇𝐷 that has no outgoing edge for some symbol 𝑎 ∈ Σ.
*
ii) - Compute values of the extended 𝐴𝑗 = 𝛿𝑁 (𝑢𝑗 , 𝑎), for all 𝑢𝑗 ∈ 𝑆 .
*
⋃︀ ⋃︀
iii) - Make a set 𝑆𝑛 = 𝑢𝑗 ∈𝑆 𝐴𝑗 = 𝑗 𝛿𝑁 (𝑢𝑗 , 𝑎) by merging sets 𝐴𝑗 [use the above 𝑎].
iv) - Create node 𝑆𝑛 ∈ 𝑇𝐷 if it does not exist, and
𝑎
Add to 𝑇𝐷 an edge with label 𝑎 from 𝑆 to 𝑆𝑛 : 𝑆 → 𝑆𝑛 .
3) Expanding set 𝐹𝐷 : Any 𝑆𝑛 whose entries contains any 𝑞𝑓 ∈ 𝐹𝑁 (of the NFA 𝑀𝑁 ) is identified
Briefly, in constructing DFA [Step 2)] we can use the corresponding transition 𝛿𝐷 :
{︁ ⋃︁ }︁
*
𝛿𝐷 (𝑞𝐷 , 𝑎) = 𝑆(𝑞𝐷 , 𝑎) = 𝛿𝑁 (𝑞, 𝑎) , ∀𝑞𝐷 ∈ 𝑄𝐷 , ∀𝑎 ∈ Σ. [𝑞𝐷 = 𝑆 in Step 2i) ]. (2.5)
𝑞∈𝑞𝐷
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 68
NOTES:
1. To show that the construction also gives the correct answer, we argue by induction on the
2. An important conclusion we can draw from ALGORITHM 2.1 is that every language ac-
♦ EXAMPLE 2.16.
where 𝑄𝑁 = {0, 1}, Σ = {𝑎, 𝑏}, the start 𝐼 = {0}, the final 𝐹𝑁 = {1},
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 69
𝛿𝑁 a b
→ 0 1 {0, 1}
1 0 1
1* 0 1
Initialize 𝑆0 := {0}, [since NFA has 1 start state], graph 𝑇𝐷 has initial vertex 𝑆0 .
𝑆2 becomes final in 𝑇𝐷 ;
* *
Loop 𝑛 = 2: 𝛿𝑁 (1, 𝑎) = {0} and 𝛿𝑁 (1, 𝑏) = {1}, gives us 𝑆3 := {0, 1}, now becomes final in 𝑇𝐷 ;
The result DFA 𝑀𝐷 has the states 𝑄𝐷 = {𝑆0 , 𝑆2 , 𝑆3 } = {{0}, {1}, {0, 1}, },
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 70
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 71
an initial state: 𝑞0 → · · · 𝑝 → · · · .
RULE: The inaccessible states [not on any walk which starts by an initial state] of 𝑀 can
(II) Use ALGORITHM 2.1 to transform the NFA in the figure below to a DFA 𝑀𝐷 .
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 72
Build sets 𝑆𝑛 as the states of the DFA, note that 𝑞1 is both initial and final node.
Initialize 𝑆0 := {𝑞0, 𝑞1}, [since NFA has 2 start states], graph 𝑇𝐷 has initial vertex 𝑆0 .
Similarly 𝑛 ≥ 3: 𝑆4 := {𝑞0, 𝑞2}, 𝑆5 := {𝑞1, 𝑞2}, 𝑆6 := {𝑞0, 𝑞1, 𝑞2}, where 𝑆0 is the initial
state.
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 73
{︁ ⋃︁ }︁
*
𝛿𝐷 (𝑞𝐷 , 𝑎) = 𝛿𝑁 (𝑞, 𝑎) , ∀𝑞𝐷 ∈ 𝑄𝐷 , ∀𝑎 ∈ Σ. [𝑞𝐷 = 𝑆 in Step 2i) ]
𝑞∈𝑞𝐷
𝛿𝐷 0 1
→ 𝑆0 {𝑆2 } {𝑆3 }
𝑆1 {𝑆2 } ∅
𝑆2 ∅ {𝑆3 }
𝑆3 {𝑆3 } {𝑆3 }
𝑆4 {𝑆5 } {𝑆3 }
𝑆5 {𝑆3 } {𝑆3 }
𝑆6 {𝑆5 } {𝑆3 }
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 74
𝛿𝐷 0 1
→ 𝑆0 {𝑆2 } {𝑆3 }
𝑆2 ∅ {𝑆3 }
𝑆3 {𝑆3 } {𝑆3 }
Figure 2.7: The output DFA from the above input NFA
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 75
NFA
PRACTICE 2.8.
B/ Let Σ = {𝑎, 𝑏, 𝑐}. Determine DFAs which corresponds to the following NFA.
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 76
𝑎 𝑐
0 1 2
𝑏 𝑎
𝑏
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 77
♣ OBSERVATION 2.
Any DFA defines a unique language, but the converse is not true.
For a language 𝐿, there are many DFA’s 𝑀 that accept it: 𝐿 = 𝐿(𝑀 ).
There may be a considerable difference in the number of states of such equivalent au-
tomata.
ber of states, it is desirable to reduce the number of states as far as possible, a storage
minimization problem.
Reducing the states of a DFA is based on finding and combining indistinguishable states.
Definition 2.13
Fix a machine 𝑀 = (𝑄, Σ, 𝑞0 , 𝛿, 𝐹 ), and 𝛿 * the extended map of 𝛿 . ♣
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 78
Indistinguishablity:
ELUCIDATION
At the original automaton, the set of final states 𝐹 makes a ‘equivalence class’, and the
Under actions of symbols in Σ and words in Σ* the states in 𝑄 change their equivalence
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 79
How to define the stopping condition/status? The process must terminate and it
REMINDER
Proposition 2.3
An equivalence relation 𝑅 ⊂ 𝐾 × 𝐾 satisfies 3 properties: reflexive, symmetric and
transitive.
𝑅𝑝 = {𝑞 ∈ 𝐾 : 𝑞 𝑅 𝑝} = {𝑞 ∈ 𝐾 : (𝑝, 𝑞) ∈ 𝑅}.
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 80
Recall that :
(I) States 𝑝, 𝑞 ∈ 𝐾 are indistinguishable when they are in one equivalence class.]
(II) The inaccessible states [not on any walk which starts by an ini tial state] of 𝑀 can be
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 81
enumerating all simple paths of 𝑇 (𝑀 ) starting at the initial state 𝑞0 . Any state not part of some path is inac-
cessible.
If 𝑝 ∈ 𝐹 and 𝑞 ̸∈ 𝐹 or vice versa, we mark the pair (𝑝, 𝑞) as distinguishable (they are in distinct equivalence
3) Loop 𝑛 ≥ 2 to find all equivalence classes of states: Repeat the following step:
Until Stopping condition valid: No previously unmarked pairs are marked. In other words, denote 𝑆𝑛 and
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 83
so we must split the old 𝐼𝐼 = {𝑞0 , 𝑞1 , 𝑞3 } into new 𝐼𝐼 = {𝑞0 } and 𝐼𝐼𝐼 = {𝑞1 , 𝑞3 }.
Next on states 𝑞2 , 𝑞4 :
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 84
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 85
Use ALGORITHM 2.2 to generate all distinct equivalence classes, typically written as 𝐶𝑘 = {𝑞𝑖 , . . . , 𝑞𝑘 }
2) Create a state in 𝑀1 :
For each set 𝐶𝑘 = {𝑞𝑖 , 𝑞𝑗 , . . . , 𝑞𝑘 } [states 𝑞 are indistinguishable], we make a state labeled 𝑖 𝑗 · · · 𝑘 ∈ 𝑄1 of
𝑀1 .
3) Define the transition rule 𝛿1 of 𝑀1 :
For each transition in 𝑀 of the form 𝛿(𝑞, 𝑎) = 𝑝 (letter 𝑎 ∈ Σ) we find the sets to which 𝑞 and 𝑝 belong in.
cally set
rule 𝛿1 as 𝛿1 (𝐶𝑘 , 𝑎) = 𝐶𝑛 , or 𝛿1 (𝑖 𝑗 · · · , 𝑎) = 𝑙 𝑚 · · · 𝑛.
5) Build the new final set 𝐹1 : 𝐹1 of 𝑀1 is the set of all the states whose label contains 𝑖 such that 𝑞𝑖 ∈ 𝐹 .
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 86
MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 87
The remaining transitions are similarly found, giving the function 𝛿1 of the reduced 𝑀1 .
MATHEMATICAL MODELING
Methods and Applications
2.7. Determine regular expression given automata 88
is a mutually close one. The two concepts are essentially the same:
Because of the equivalence of NFA’s and DFA’s, a language is also regular if it is accepted
by some NFA.
MATHEMATICAL MODELING
Methods and Applications
2.7. Determine regular expression given automata 89
“If we have any regular expression 𝑟 , we can construct an nondeterministic finite automaton
♦ EXAMPLE 2.19. Given 3 states 𝑄 = {𝑞0, 𝑞1, 𝑞2}, and the alphabet Σ = {𝑎, 𝑏},
we construct an NFA that recognizes the language 𝐿(𝑟) where the regular
MATHEMATICAL MODELING
Methods and Applications
2.7. Determine regular expression given automata 90
The next part is the converse of Theorem 2.1 [THEOREM 3.2 of REF. 2] .
MATHEMATICAL MODELING
Methods and Applications
2.7. Determine regular expression given automata 91
Theorem 2.3
For every regular language 𝐿, there exists a corresponding regular expression 𝑟 such
that 𝐿 = 𝐿(𝑟). ♡
FACT: Any regular language 𝐿 has an associated NFA 𝑀 , and hence, a transition graph
𝑇 (𝑀 ) is fully determined by 𝐿.
Therefore, given 𝐿, we need to find a regular expression 𝑅 capable of generating the
labels of all the walks (in the graph 𝑇 (𝑀 )) from 𝑞0 to any final state.
The graph 𝑇 (𝑀 )) of any NFA 𝑀 can be considered a new generalized transition graph
MATHEMATICAL MODELING
Methods and Applications
2.7. Determine regular expression given automata 92
An edge labeled with a single symbol 𝑎 is interpreted as an edge labeled with the expression
The label of any walk from the initial state to a final state is the concatenation of several
regular expressions, and hence itself a regular expression, see Equation 2.6.
The strings denoted by such regular expressions are a subset of the language accepted by
the generalized transition graph 𝐺𝑇 (𝑀 ), with the full language being the union of all such
generated subsets.
MATHEMATICAL MODELING
Methods and Applications
2.7. Determine regular expression given automata 93
Property 2.1.
1. If a GTG 𝐺𝑇 (𝑀 ), after conversion from 𝑀 , has some edges missing, we put them in and
label them with ∅. A complete GTG with |𝑉 | vertices has exactly |𝑉 |2 edges.
2. When a GTG has more than two states, we can find an equivalent graph by removing one
The edge (𝑞0 , 𝑞0 ) labeled 𝑎 is a cycle that can generate any number of 𝑎’s, it represents
𝐿(𝑎*).
MATHEMATICAL MODELING
Methods and Applications
2.7. Determine regular expression given automata 94
We could have labeled this edge 𝑎* without changing the language accepted by the graph.
PRACTICE 2.9. Now we have the simple two-state complete GTG shown in Figure 2.10.
MATHEMATICAL MODELING
Methods and Applications
2.7. Determine regular expression given automata 95
q_i q_j
Using double indexes for edges, in this complete GTG with 4 arcs, we can replace
MATHEMATICAL MODELING
Methods and Applications
2.7. Determine regular expression given automata 96
ALGORITHM 2.4 [Construct regular expression from NFA- Procedure nfa-to-rex, REF.2.]
Input: An NFA 𝑀 = (𝑄 = {𝑞0 , 𝑞1 , . . . , 𝑞𝑛 }, Σ, {𝑞0 }, 𝛿, 𝐹 ), |𝐹 | = 1, or a language 𝐿
2a): If the GTG has only two states, with 𝑞𝑖 as its initial state and 𝑞𝑗 its final state, its associated regular
2b) If the GTG has three states, with initial state 𝑞𝑖 , final state 𝑞𝑗 , and third state 𝑞𝑘 , we create new edges
(between 𝑞𝑖 , 𝑞𝑗 ), labeled
MATHEMATICAL MODELING
Methods and Applications
2.7. Determine regular expression given automata 97
Apply rule 2b) for all pairs of states (𝑞𝑖 , 𝑞𝑗 ), 𝑖 ̸= 𝑘 , and 𝑗 ̸= 𝑘 . At each step apply the simplifying rules
♦ EXAMPLE 2.21 (Illustration for Step 2b). Figure 2.11 represents a reduction of a complete
generalized transition graph 𝐺𝑇 (𝑀 ).
MATHEMATICAL MODELING
Methods and Applications
2.7. Determine regular expression given automata 98
edge from 𝑞1 to 𝑞3 : ℎ + 𝑎 𝑓 * 𝑐,
MATHEMATICAL MODELING
Methods and Applications
2.7. Determine regular expression given automata 99
REMINDER:
MATHEMATICAL MODELING
Methods and Applications
2.7. Determine regular expression given automata 100
Define the states (nodes) 𝑉 and the arcs 𝐴 of the graph 𝐺𝑇 (𝐿) = (𝑉, 𝐴)?
where
𝐸𝐸 = the node of strings 𝑤 with an even number of symbol 𝑎’s and 𝑏’s,
𝑂𝐸 = the node of strings 𝑤 with an odd number of 𝑎’s, and even number of 𝑏’s,
𝑂𝑂 = the node of strings 𝑤 with an odd number of symbol 𝑎’s, and 𝑏’s,
𝐸𝑂 denote the node of strings 𝑤 with an even number of 𝑎’s, and odd number of 𝑏’s.
MATHEMATICAL MODELING
Methods and Applications
2.7. Determine regular expression given automata 101
MATHEMATICAL MODELING
Methods and Applications
2.7. Determine regular expression given automata 102
G2 = G_1 \ node OO
G1 = G_0 \ node OE
Figure 2.13: Reduced GTG with 3 and 2 nodes, with output of regular expressions
MATHEMATICAL MODELING
Methods and Applications
2.7. Determine regular expression given automata 103
The loop at 𝑞1 (edge between 𝑞1 = 𝐸𝐸 and itself) in the reduced graph, will have the label
𝑟𝐸𝐸 = ∅ + 𝑎 ∅* 𝑎 = 𝑎𝑎
Similarly [DIY] we can find new edges of the reduced graph, after removing 𝑞2 = 𝑂𝐸 we
get a new graph with 3 nodes (left) and then 2 nodes (the right) of Figure 2.13.
PRACTICE 2.10.
MATHEMATICAL MODELING
Methods and Applications
2.8. Reviewed Problems 104
𝑏
0 1
𝑎
𝑎, 𝑏 𝑏
𝑎
3 𝑎 2 𝑏
Answer:
MATHEMATICAL MODELING
Methods and Applications
2.8. Reviewed Problems 105
𝑏
0 1
𝑎
𝑎, 𝑏 𝑏
𝑎
3 𝑎 2 𝑏
i) This automaton is not a DFA since the number of states is not finite.
MATHEMATICAL MODELING
Methods and Applications
2.8. Reviewed Problems 106
f/ When using determinisation algorithm [ALGORITHM 1] to convert NFA into DFA, how
a) When occuring an event from a state, the NFA does not determine the next state.
b) NFA has not finite number of states but DFA has a finite number of states .
c) The number of states is always reduced when determinisation from NFA to DFA.
MATHEMATICAL MODELING
Methods and Applications
2.8. Reviewed Problems 107
d) NFA does not determine surely the next state in order to simplify the graph.
𝑏
𝑎 𝑎
𝑏
𝑞1 𝑞2
𝑎
𝑏
and regular expression 𝐸 = ((𝑎𝑎)* + 𝑏𝑏* 𝑎(𝑎𝑎)* 𝑏(𝑎𝑏)* )* present the same language 𝐿?
Your choice:
MATHEMATICAL MODELING
Methods and Applications
The counter-example is 𝑏𝑎𝑎?.
4. Are two regular expressions 𝐸1 = (𝑎 + 𝑏)* and 𝐸2 = (𝑎𝑎 + 𝑎𝑏 + 𝑏𝑎 + 𝑏𝑏)* are equivalent?
Your choice:
(b) 𝐸1 ⊆ 𝐸2