0% found this document useful (0 votes)
17 views112 pages

CHAPTER2 AUTOMATA Landscape

Chapter 2 of the document focuses on Automata Theory as a fundamental aspect of Mathematical Modeling, covering basic terms, language determination, regular expressions, and finite automata. It discusses the equivalence of deterministic and nondeterministic automata and includes various problems and examples related to these concepts. The chapter aims to provide a theoretical foundation for understanding formal languages and grammars in computer science.

Uploaded by

Khoa Trần
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views112 pages

CHAPTER2 AUTOMATA Landscape

Chapter 2 of the document focuses on Automata Theory as a fundamental aspect of Mathematical Modeling, covering basic terms, language determination, regular expressions, and finite automata. It discusses the equivalence of deterministic and nondeterministic automata and includes various problems and examples related to these concepts. The chapter aims to provide a theoretical foundation for understanding formal languages and grammars in computer science.

Uploaded by

Khoa Trần
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 112

MATHEMATICAL MODELING

METHODS And APPLICATIONS


MATHEMATICAL MODELING

Chapter 2: AUTOMATA THEORY

© Man VM. Nguyen(†) and Khuong An Nguyen(‡)

(†) Faculty of Science - Mahidol University

(‡) Faculty of Computer Science & Engineering - HCMC University of Technology


Contents

Chapter 2 AUTOMATA THEORY-


For Mathematical Modeling 1

2.1 PART A. BASIC TERMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4


2.2 Determining a language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.3 Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.4 PART B. FINITE AUTOMATA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.5 Finite Automata- Basic Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
2.6 PART C: Equivalence of DFA and NFA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
2.7 Determine regular expression given automata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
2.8 Reviewed Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
List of Figures

2.1 A automaton for the process of an X-ray machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5


2.2 NFA with total 4 states . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.3 Symbolic representation of automata based on (primitive) regular expressions . . . . . . . . . . . . . . . . . . . . . 57
2.4 Automaton for L (r1 r2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
2.5 Construct an NFA with 3 states . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
2.6 Equivalence of two small automata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
2.7 The output DFA from the above input NFA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
2.8 NFA-to-DFA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
2.9 A simple GTG, language 𝐿 and its regular expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
2.10 A simple NFA and its regular expression? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
2.11 Reduce node of a complete GTG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
2.12 A complete GTG with 4 nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
2.13 Reduced GTG with 3 and 2 nodes, with output of regular expressions . . . . . . . . . . . . . . . . . . . . . . . . . . 102

MATHEMATICAL MODELING
Methods and Applications
Chapter 2

AUTOMATA THEORY-

For Mathematical Modeling


2

AUTOMATA THEORY from Mathematical Modeling View


We study the following topics in this chapter.

A. BASIC TERMS

Motivation and Key concepts

Determining a language - Regular Expressions

B. AUTOMATA

Finite Automata, see Section 2.4

Finite Automata- Basic Problems, in Section 2.5

B. C. Equivalence of DFA and NFA

Equivalence of DFA and NFA (Nondeterministic automata)

Determine a regular expression given an automaton, in Section 2.7.

Knowledge blocks include automata theory, formal languages and grammars;

bringing the theoretical foundation of computer science (CS).

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

SCIENCE [2nd ed., Cambridge University Press 2004]

3. REF. 3: Peter Linz. An Introduction to Formal Languages and Automata,

6th Ed., Jones & Bartlett Learning (2017)

4. REF. 4: Mordechai Ben-Ari. Mathematical Logic for Computer Science,

Chapter 15 Third Edition, Springer-Verlag (2012).

MATHEMATICAL MODELING
Methods and Applications
2.1. PART A. BASIC TERMS 4

2.1 Overview - Motivation - Key concepts

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

abstract models of computers and computation.

2. Why study automata theory? Automata theory provides such abstract model, its ideas

have some important applications, both software (programming languages, and compilers

...), midleware (operating systems) to hardware (digital design).

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.

○ with label: describe states of a process/agent


→: transitions from a state to another one
1 single automaton, plural automata

MATHEMATICAL MODELING
Methods and Applications
2.1. PART A. BASIC TERMS 5

□: action of an agent (or multiple agents)

Figure 2.1: A automaton for the process of an X-ray machine

Chapter’s aims: We will study various automata, mostly

abstract and mathematical concepts, to see how they are related to

(formal) languages and grammars.

MATHEMATICAL MODELING
Methods and Applications
2.1. PART A. BASIC TERMS 6

From Alphabets to Languages- KEY TERMINOLOGIES

We need basic definitions and their relations.

1. An alphabet Σ is a finite and non-empty set of symbols (or characters).

For example: Σ = {𝑎, 𝑏, 𝑐}, the binary Σ = {0, 1},

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 𝛼, 𝛽...).

2. A string (word) 𝑢 over Σ is a finite sequence of symbols from the alphabet Σ.

A empty string is denoted by 𝜀 (with no symbols at all).

The length of a string 𝑢, denoted by |𝑢|, is the number of characters. Obviously

|𝜀| = 0, empty string has length of 0, and 𝜀𝑢 = 𝑢𝜀 = 𝑢.

If 𝑢 = 𝑢1 𝑢2 · · · 𝑢𝑛 , clearly |𝑢| = 𝑛. Let Σ* be the set of all strings over Σ.

String concatenation is map from Σ* × Σ* to Σ* , with (𝑢, 𝑣) ↦→ 𝑢.𝑣 = 𝑢𝑣 =: 𝑤.

MATHEMATICAL MODELING
Methods and Applications
2.1. PART A. BASIC TERMS 7

The substrings 𝑢 and 𝑣 are said to be a prefix and a suffix of 𝑤.

3. A language 𝐿 over Σ is a sub-set of Σ* .

Denote ∅ the empty language. Σ* itself is called the universal language.

Question: How about {𝜀}, {0, 00, 001}, are they languages over Σ = {0, 1} ?

4. A formal language : an abstraction of the general characteristics of programming lan-

guages.

A formal language consists of

(i) a set of symbols and

(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 ...

of two languages are immediately defined.


⋃︀
Union of languages 𝐿1 , 𝐿2 is set-like union 𝐿1 𝐿2 .

MATHEMATICAL MODELING
Methods and Applications
2.1. PART A. BASIC TERMS 8

Product (or multiplication) 𝐿1 𝐿2 = {𝑢 𝑣| 𝑢 ∈ 𝐿1 , 𝑣 ∈ 𝐿2 }.

This is based on concatenation of languages 𝐿1 , 𝐿2

Power 𝐿0 = {𝜀}, 𝐿𝑖 = 𝐿𝑖−1 𝐿, if power 𝑖 ≥ 1.

Iteration (star operation) 𝐿* is a special union of powers



⋃︁ ⋃︁
* 𝑖
𝐿 = 𝐿 = {𝜀} 𝐿+
𝑖=0
⋃︀∞
where 𝐿+ = 𝑖=1 𝐿𝑖 is named proper iteration.
The union, product and iteration are called regular operations.

The complement 𝐿 = Σ* ∖ 𝐿 of a language 𝐿 [is defined with respect to Σ* ].

The reverse of a language is the set of all string reversals, that is,

𝐿𝑅 = {𝑤𝑅 : 𝑤 ∈ 𝐿.}

♦ EXAMPLE 2.1.

Let Σ = {𝑎, 𝑏, 𝑐}, 𝐿1 = {𝑎𝑏, 𝑎𝑎, 𝑏}, 𝐿2 = {𝑏, 𝑐𝑎, 𝑏𝑎𝑐}

a) 𝐿1 ∪ 𝐿2 =? 𝐿1 ∪ 𝐿2 = {𝑎𝑏, 𝑎𝑎, 𝑏, 𝑐𝑎, 𝑏𝑎𝑐},


MATHEMATICAL MODELING
Methods and Applications
2.1. PART A. BASIC TERMS 9

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

sum of the individual lengths, that is |𝑢.𝑣| = |𝑢| + |𝑣|.

2. Let alphabet Σ = {𝑎, 𝑏, 𝑐}.

i) Write at least 10 elements of Σ* .

Is 𝐿 = {𝑎, 𝑎𝑎, 𝑎𝑎𝑏} a finite language over Σ?

ii) Is 𝐿3 = {𝜀, 𝑎𝑏, 𝑎𝑎𝑏𝑏, 𝑎𝑎𝑎𝑏𝑏𝑏, 𝑎𝑎𝑎𝑎𝑏𝑏𝑏𝑏, . . .} a language? finite?

iii) Is 𝐿4 = {𝑎𝑛 𝑏𝑛 : 𝑛 = 0, 1, 2, . . .} also a language over Σ? Is it 𝐿3?


Is the string 𝑢 = 𝑎𝑏𝑏 in 𝐿4 ? How about 𝑣 = 𝑎𝑎𝑎𝑎𝑎𝑏𝑏𝑏𝑏𝑏?

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

𝐿1: all strings with exactly one ’𝑎’.


𝐿2: all strings of even length.
𝐿3: all strings which the number of appearances of ’𝑏’ is divisible by 3.
𝐿4: all strings ending with ’𝑎’.

𝐿5: all non-empty strings not ending with ’𝑎’.

𝐿6: all strings including at least one ’𝑎’ and


whose the first appearance of ’𝑎’ is not followed by a ’𝑐’.

MATHEMATICAL MODELING
Methods and Applications
2.2. Determining a language 11

2.2 Determining a language

A language can be specified in several ways:

a) Enumeration (listing) of its words, for example: 𝐿1 = {𝜀, 0, 1}.

b) Using a property, such that all words of the language have this property but other words

have not.

c) Using its grammar, [defined yet?] for example:

𝐿(𝐺) = {𝑎𝑛𝑏𝑛| 𝑛 ≥ 1} defined by a grammar 𝐺 = (𝑉, 𝑇, 𝑃, 𝑆), as defined explicitly next.

♦ EXAMPLE 2.2 (Using a property).

Fix Σ = {𝑎, 𝑏}, then 𝐿4 = {𝑎𝑛 𝑏𝑛 : 𝑛 = 0, 1, 2, . . .} is a language

(it is in fact 𝐿3 = {𝜀, 𝑎𝑏, 𝑎𝑎𝑏𝑏, 𝑎𝑎𝑎𝑏𝑏𝑏, . . .} in PRACTICE 2.1 above by enumeration).

Also using property on string length gives 𝐿6 = {𝑢 ∈ Σ* | 𝑛𝑎 (𝑢) = 𝑛𝑏 (𝑢)}, where 𝑛𝑐 (𝑢)

denotes the number of letter ’c’ in word 𝑢. Is 𝐿4 ⊂ 𝐿6 ? ■

MATHEMATICAL MODELING
Methods and Applications
2.2. Determining a language 12

Definition 2.1 (Grammar of a language)


A grammar is defined as a quadruple 𝐺 = (𝑉, 𝑇, 𝑃, 𝑆) where

𝑉 is a finite set of objects called variables,

𝑇 is a finite set of objects called terminal symbols, 𝑇 ∩ 𝑉 = ∅,

𝑃 is a finite set of productions (production rules), and

𝑆 ∈ 𝑉 is a special symbol called the start variable.

We will assume that all production rules are of the form

𝑥 → 𝑦, 𝑥 ∈ (𝑉 ∪ 𝑇 )+ and 𝑦 ∈ (𝑉 ∪ 𝑇 )*.

If string 𝑤 consists of 𝑥, say 𝑤 = 𝑎𝑥𝑏, string 𝑧 consists of 𝑦 , say 𝑧 = 𝑎𝑦𝑏, and 𝑥 → 𝑦 ,

then we define direct derivation, written as 𝑤 ⇒ 𝑧.

We say that string 𝑤 derives string 𝑧 (or that 𝑧 is derived from 𝑤).

MATHEMATICAL MODELING
Methods and Applications
2.2. Determining a language 13

If there is a finite derivation sequence 𝑤1 ⇒ 𝑤2 ⇒ · · · ⇒ 𝑤𝑛 [unspecified steps]


* *
then we reduce it as 𝑤1 ⇒ 𝑤𝑛 . Relation ⇒ is called a derivation.

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

arbitrary order, and as often as desired.

3. Derivation are based on productions.

Definition 2.2 (Language generated by a grammar)


A grammar 𝐺 = (𝑉, 𝑇, 𝑃, 𝑆) can normally generate many strings.

MATHEMATICAL MODELING
Methods and Applications
2.2. Determining a language 14

The language 𝐿 = 𝐿(𝐺) defined or generated by the grammar 𝐺 is


*
𝐿 = 𝐿(𝐺) = {𝑤 ∈ 𝑇 * : 𝑆 ⇒ 𝑤} (2.1)

(the set of all such terminal strings). We obtain the derivation


*
[𝑆 ⇒ 𝑤] ≡ [𝑆 ⇒ 𝑤1 ⇒ 𝑤2 ⇒ · · · ⇒ 𝑤𝑛 ⇒ 𝑤],
* a
in which strings 𝑆 and 𝑤𝑖 are called sentential forms of the derivation ⇒.
a
Sentential forms are strings that contain both variables and terminals.

♦ EXAMPLE 2.3.

Let define grammar 𝐺 = (𝑉, 𝑇, 𝑃, 𝑆) where

𝑉 = {𝑆} [only one variable],


𝑇 = {𝑎, 𝑏} [terminal symbols], and
𝑃 = {𝑆 → 𝑎𝑆𝑏, 𝑆 → 𝑎𝑏, 𝑆 → 𝜀} with three production rules.

MATHEMATICAL MODELING
Methods and Applications
2.2. Determining a language 15

*
We see 𝑆 ⇒ 𝑎𝑆𝑏 ⇒ 𝑎𝑎𝑆𝑏𝑏 = 𝑎2 𝑆𝑏2 ⇒ 𝑎2 𝑏2 ... then 𝑆 ⇒ 𝑎𝑎𝑏𝑏 = 𝑎2 𝑏2 .

Also 𝑎2 𝑆𝑏2 ⇒ 𝑎3 𝑏3 ... and hence


*
recursively we get the following derivation 𝑆 ⇒ 𝑎𝑛 𝑏𝑛 , i.e.

𝑆 ⇒ 𝑎𝑆𝑏 ⇒ 𝑎2𝑆𝑏2 ⇒ . . . ⇒ 𝑎𝑛𝑆𝑏𝑛.

Therefore the language defined by 𝐺 is


*
𝐿(𝐺) = {𝑤 ∈ 𝑇 * : 𝑆 ⇒ 𝑤} = {𝑎𝑛 𝑏𝑛| 𝑛 ≥ 1} ■

♦ EXAMPLE 2.4.

Consider a language 𝐿 = {𝑎𝑛 𝑏𝑛+1 | 𝑛 ≥ 0}. Find a grammar that generates 𝐿.


Should the grammar 𝐺 = (𝑉, 𝑇, 𝑃, 𝑆) be defined as before?

No, we need to modify it to generate an extra 𝑏 in 𝐿.

Explicitly we extend a new ‘stronger variable’ 𝑆 to incorporate 𝑏 to the sentences of 𝐿, hence

if redefine 𝑉 = {𝑆, 𝑀 }, 𝑇 = {𝑎, 𝑏} then 𝑀 replaces the old 𝑆 ’s role,

MATHEMATICAL MODELING
Methods and Applications
2.2. Determining a language 16

and so the set of productions becomes 𝑃 = {𝑆 → 𝑀 𝑏, 𝑀 → 𝑎𝑀 𝑏, 𝑀 → 𝜀}.


*
Can you derive specific sentences to convince yourself, like 𝑎𝑏2 ∈ 𝐿 by checking [𝑆 ⇒ 𝑎𝑏2 ]?

Or 𝑆 ⇒ 𝑀 𝑏 ⇒ 𝑎𝑀 𝑏𝑏 ⇒ 𝑎𝑎𝑀 𝑏𝑏𝑏? ■

Is a language generated by a certain grammar 𝐺?

Often it is not so easy to find a grammar for a language described in an informal way, or to

give an intuitive characterization of the language defined by a grammar. To show mathemati-

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

(b) that every string so derived is in 𝐿.

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

HW: Readers should try the following.

PRACTICE 2.3. Denote 𝑛𝑐 (𝑢) the number of letter ’c’ in any word 𝑢.

Take now Σ = {𝑎, 𝑏}, and consider a language

𝐿6 = {𝑢 ∈ Σ*| 𝑛𝑎(𝑢) = 𝑛𝑏(𝑢)}.

Prove that the grammar 𝐺 = (𝑉, 𝑇, 𝑃, 𝑆) with 𝑇 = Σ, 𝑉 = {𝑆, 𝑀 }, and productions

𝑃 = {𝑆 → 𝜀, 𝑆 → 𝑎𝑆𝑏, 𝑀 → 𝑏𝑆𝑎, 𝑆 → 𝑆𝑆} generates the language 𝐿.

Hint: check both 𝐿(𝐺) ⊆ 𝐿 and 𝐿 ⊆ 𝐿(𝐺).

PRACTICE 2.4.

Solve examples in page 4.12, and Exercises in page 13, 14 of REF 1 .

MATHEMATICAL MODELING
Methods and Applications
2.3. Regular Expressions 18

2.3 Regular Expressions

Definition 2.3
Regular expressions over some given alphabet Σ involve a combination of ♣
(︀)︀
♦ strings of symbols from Σ, parentheses , and

♦ the operators + (union), · (product or concatenation), and * (transitive closure).

A regular expression over the alphabet Σ is ‘recursively’ determined by 3 conditions

1. ∅, 𝜀 and 𝑎 ∈ Σ are all regular expressions, called primitive regular expressions.

2. If 𝑟 and 𝑠 are regular expressions, so are (𝑟), 𝑟 + 𝑠, 𝑟 · 𝑠, and 𝑟 * .

3. A string is a regular expression if and only if it can be derived from the

primitive regular expressions by a finite number of applications of the rules in (2). ■

MATHEMATICAL MODELING
Methods and Applications
2.3. Regular Expressions 19

♦ EXAMPLE 2.5. On the alphabet Σ = {𝑎, 𝑏, 𝑐}

the string (𝑎 + 𝑏 · 𝑐)* · (𝑐 + ∅) is a regular expression, explain?

But (𝑎 + 𝑏 +) is not a regular expression, since there is no way it can be constructed from

the primitive regular expressions.

In fact, regular expressions can be used to describe some simple languages.

♦ EXAMPLE 2.6. On the alphabet Σ = {𝑎, 𝑏}

The regular expression (𝑎 + 𝑏)* represents all the strings, written 𝐿

𝑎*(𝑏𝑎*)* represent the same language 𝐿


(𝑎 + 𝑏)*𝑎𝑎𝑏 represent all strings ending with 𝑎𝑎𝑏? or 𝐿 · 𝑎𝑎𝑏

MATHEMATICAL MODELING
Methods and Applications
2.3. Regular Expressions 20

Languages associated with regular expressions

Definition 2.4 (Kleene)


Language 𝐿 ⊆ Σ* is regular if and only if there exists a regular expression over Σ

representing language 𝐿.

Knowledge box 1. Regular Expressions denote languages in the following ways.

♦ Consider a regular expression (string) 𝑟 ∈ Σ* = {∅, 𝜀, 𝑎, 𝑏, . . .}.

The language 𝐿(𝑟) ⊂ Σ* associated with expression 𝑟 is defined by the following rules.

1. ∅ is a regular expression, representing the empty language,

2. 𝜀 is a regular expression, representing language {𝜀},

3. For every 𝑎 ∈ Σ, 𝑎 is a regular expression, representing the language {𝑎}.

What if 𝑟 = 𝑎 · 𝑏 = 𝑎𝑏, then the language 𝐿(𝑟) =?

♦ Consider regular expressions 𝑟 and 𝑠, representing languages 𝑋 = 𝐿(𝑟), 𝑌 = 𝐿(𝑠) re-

MATHEMATICAL MODELING
Methods and Applications
2.3. Regular Expressions 21

spectively. Then (𝑟+𝑠), (𝑟·𝑠), 𝑟 * are regular expressions, (so they) respectively representing

𝑌 , 𝑋 𝑌 , and 𝑋 *. Explicitly,
⋃︀
languages 𝑋
⋃︀
4. 𝐿(𝑟 + 𝑠) ≡ 𝐿(𝑟) + 𝐿(𝑠) = 𝑋 𝑌

5. 𝐿(𝑟 · 𝑠) ≡ 𝐿(𝑟) 𝐿(𝑠) = 𝑋 𝑌

6. 𝐿((𝑟)) ≡ 𝐿(𝑟) = 𝑋
)︀*
7. 𝐿(𝑟 * ) ≡ 𝐿(𝑟) = 𝑋 *.
(︀

♦ EXAMPLE 2.7. On the alphabet Σ = {𝑎, 𝑏}


)︀*
Take 𝑟 = 𝑎, 𝐿(𝑟 * ) ≡ 𝐿(𝑎)
(︀
= {𝜀, 𝑎, 𝑎𝑎, 𝑎𝑎𝑎, . . .}.
Take 𝑟 = 𝑎* ·𝑏, it give the language, 𝐿(𝑟) = 𝐿(𝑎* ·𝑏) = 𝐿(𝑎* )𝐿(𝑏) = {𝑏, 𝑎𝑏, 𝑎2 𝑏, 𝑎3 𝑏, . . . , 𝑎𝑎, 𝑎𝑎𝑎, . . .}.

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 𝑠.

(𝑥 + 𝑟) + 𝑠 ≡ 𝑥 + (𝑟 + 𝑠);

(𝑥𝑟)𝑠 ≡ 𝑥(𝑟𝑠)

(𝑥 + 𝑟)* ≡ (𝑥* + 𝑟)* ≡ (𝑥 + 𝑟*)* ≡ (𝑥* + 𝑟*)*

(𝑥 + 𝑟)* ≡ (𝑥*𝑟*)*

(𝑟*)* ≡ 𝑟*

𝑥*𝑥 ≡ 𝑥𝑥*;

𝑥𝑥* + 𝜀 ≡ 𝑥*

PRACTICE 2.5. On the alphabet Σ = {𝑎, 𝑏},

I) 𝑠 = (𝑎𝑎)* (𝑏𝑏)* 𝑏 represents all the (regular) strings of language 𝐿(𝑠) =?

II) Is 𝐸 = (𝑎 + 𝑏)* (𝑎 + 𝑏𝑏) regular? Find the language 𝐿(𝐸) =?

Hint: 𝐿(𝑎 + 𝑏𝑏) consists of word ending by 𝑎 or a double 𝑏. ■

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

following regular expressions.

a) 𝐸1 = 𝑎* + 𝑏* ,

b) Elucidate why 𝑎* 𝑏 = {𝑏, 𝑎𝑏, 𝑎2 𝑏, 𝑎3 𝑏, . . . , 𝑎𝑎𝑎 . . . 𝑎𝑏}?

Then find the language of 𝐸2 = 𝑎* 𝑏 + 𝑏* 𝑎.

c) 𝐸 = b(ca + ac) (aa) + 𝑎* · (𝑎 + 𝑏) = r + 𝑠 =⇒ 𝐿𝐸 =?

Hint for c): You will prove firstly 𝐿2 = 𝐿(𝑠) = 𝐿(𝑎* · (𝑎 + 𝑏)) = {𝑎𝑛+1 , 𝑎𝑚 𝑏 | 𝑛, 𝑚 ≥ 0}.

Next find 𝐿0 = 𝐿(𝑏(𝑐𝑎 + 𝑎𝑐)) = 𝐿(𝑏𝑐𝑎) ∪ 𝐿(𝑏𝑎𝑐),

then finally get 𝐿1 = 𝐿(𝑟) = 𝐿0 {𝑎𝑎} = 𝐿(𝑟). ■

MATHEMATICAL MODELING
Methods and Applications
2.3. Regular Expressions 24

PROBLEM 2.2.

Simplify each of the following regular expressions

1. 𝐸1 = 𝜀 + 𝑎𝑏 + 𝑎𝑏𝑎𝑏(𝑎𝑏)* ,

2. 𝐸2 = 𝑎𝑎(𝑏* + 𝑎) + 𝑎(𝑎𝑏* + 𝑎𝑎),

3. 𝐸3 = 𝑎(𝑎 + 𝑏)* + 𝑎𝑎(𝑎 + 𝑏)* + 𝑎𝑎𝑎(𝑎 + 𝑏)* .

MATHEMATICAL MODELING
Methods and Applications
PART B. AUTOMATA

AIM of studying Automata: toward a representation of a process or system.

[[GoogleMap]]
2.4. PART B. FINITE AUTOMATA 26

2.4 Finite Automata

An automaton (a machine) can be represented by a graph in which

the vertices give the initial states and one or several final/accepting states, and the edges

means transitions or events.

Definition 2.5 (Finite automaton (FA))


A finite automaton 𝑀 is a 5-tuples (𝑄, Σ, 𝑞, 𝛿, 𝐹 ) or (𝑄, Σ, 𝐼, 𝛿, 𝐹 ) where ♣

1. 𝑄 is a finite set, called the states,

2. Σ is a finite set, called alphabet,

3. 𝑞 ∈ 𝑄 is the initial or start state,

4. 𝛿 : 𝑄 × Σ → 𝑄 is the transition function,

5. 𝐹 ⊆ 𝑄 is the set of accepting states of the automaton.

MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 27

Definition 2.6 (Accepted string and Language of a machine (finite automaton))


𝑤
A string 𝑤 = 𝑎1 𝑎2 · · · 𝑎𝑛 ∈ Σ* is accepted by an automaton 𝑀 if symbolically 𝑞 ⇝ 𝑞𝑤 ∈

𝐹 , meaning applying 𝑤 on 𝑞 gives a final (accept) state 𝑞𝑤 in 𝐹 .


If 𝐴 is the set of all strings 𝑤 that machine 𝑀 accepts, we say that

𝐴 is the language of machine 𝑀 and write 𝐿(𝑀 ) = 𝐴 = {𝑤 : |𝑀 accepts string 𝑤}.


We say that machine 𝑀 recognizes (or accepts) the language 𝐴.

♦ 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

A finite automaton with two states

0 1

𝑞1 𝑞 1 𝑞2
𝑞2 𝑞 1 𝑞2

MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 29

Let string 𝑟 = 1101 ∈ 𝐴, will 𝑀 accept it?

We apply 𝑟 = 1101 ∈ 𝐴 on the start state 𝑞1 , letter by letter to find out.

Use 𝑟 = 1101 ∈ 𝐴 we finally get state 𝑞2 ∈ 𝐹 (accepting states).

The string 𝑟 is accepted because 𝑞2 is an accept state.

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 }.

Moreover the regular expression

𝑟 = 1101 ∈ 1*(0 + 1),

expresses the complete information of 𝑀 . Abstractly, if we would replace letter

𝑎 = 1, 𝑏 = 0 on the machine 𝑀 then we get the same conclusion, for 𝑟 = 𝑎𝑎𝑏𝑎 ∈ 𝑎*(𝑏 + 𝑎).

♦ EXAMPLE 2.9 (Finite automaton to a regular expression ).

MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 30

𝑏
𝑎, 𝑏
𝑞0 𝑞1

Regular expression is 𝑟 = 𝑏* (𝑎 + 𝑏)? But what is the transition function 𝛿 ?

PROBLEM 2.3.

I) Let Σ = {𝑎, 𝑏}. Which of the strings

1) 𝑎3 𝑏,

2) 𝑎𝑏𝑎2 𝑏,

3) 𝑎4 𝑏2 𝑎𝑏3 𝑎,

4) 𝑎4 𝑏𝑎4 ,

5) 𝑎𝑏4 𝑎9 𝑏,

are accepted by the following finite automaton?

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

2.4.1 Nondeterministic finite automata

Definition 2.7 (Nondeterministic finite automaton (NFA))


A non-deterministic finite automaton 𝑀 is represented by a 5-tuples (𝑄, Σ, 𝑞0 , 𝛿, 𝐹 ) or

(𝑄, Σ, 𝐼, 𝛿, 𝐹 ) where ♣

1. 𝑄 a finite, nonempty set of states,

2. Σ is the input alphabet,

3. 𝑞0 is an initial state, [𝑞0 can be extended to 𝐼 ⊂ 𝑄, the set of initial states],

4. 𝛿 : 𝑄 × (Σ ∪ {𝜀}) → 2𝑄 is a transition function,

5. 𝐹 ⊆ 𝑄 is the set of final/accepting states of the automaton.

In Item 4, generally the 𝛿 can be extended to 𝐸 , a set of many transition functions.

ELUCIDATION

Nondeterminism/ Nondeterministic property means a choice of moves for automaton 𝑀 .

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.

Formally, we achieve this by defining the transition function 𝛿 so that Range(𝛿) ⊂ 𝑄

or Range(𝛿) ∈ 2𝑄 [its range is a set of possible states in 𝑄].

An NFA is a directed, labeled graph, named the transition graph 𝑇 (𝑀 ) = (𝑉, 𝐸) of automaton 𝑀 ,

whose node set 𝑉 ≡ 𝑄 and 𝐸 = {(𝑝, 𝑎, 𝑞)}, consisting of transitions - directed edges [la-

beled with letter 𝑎 ∈ Σ] - from (state) node 𝑝 to node 𝑞 :


𝑎
𝑝 −→ 𝑞.

Among nodes some are initial and some final states.

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].

A sequence (𝑞𝑖 , 𝑎𝑖+1 , 𝑞𝑖+1 ), where 𝑞𝑖 ∈ 𝑄 for 𝑖 = 0, 1, . . . , 𝑛 − 1 of edges of graph 𝑇 (𝑀 )

is a walk 𝑤 in 𝑇 (𝑀 ) with the label 𝑎1 , 𝑎2 , . . . , 𝑎𝑛 .


𝑤
We write 𝑤 = 𝑎1 , 𝑎2 , . . . , 𝑎𝑛 or shortly 𝑞0 −→ 𝑞𝑛 .

MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 34

♦ EXAMPLE 2.10. Fix 𝑄 = {𝑞1, 𝑞2, 𝑞3, 𝑞4} and Σ = {0, 1, 𝜀}.

An nfa with 4 states and 1 accepting state.

Figure 2.2: NFA with total 4 states

* Transition function 𝛿 gives the Range(𝛿) ∈ 2𝑄 :

MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 35

If, as in Figure 2.2, the current state is 𝑞1 , select actions 𝑤 = 1 0 1

then the symbol 𝑎 = 1 is read, and 𝛿(𝑞1 , 𝑎) = {𝑞1 , 𝑞2 },

hence either 𝑞1 or 𝑞2 could be the next state of the NFA.

* The transition graph 𝑇 (𝑀 ) of 𝑀 has edges (𝑞1 , 𝑞1 ) and (𝑞1 , 𝑞2 ) with label 𝑎 = 1.

* In Figure 2.2, string of actions 𝑤 = 1 0 1 acts on 𝑞1 and returns 𝑞4 .

The states in a walk are not necessary distinct. ■

Definition 2.8 (Extended transition function in NFA)


For an NFA, the extended transition function 𝛿 * is defined

so that 𝛿 * (𝑞𝑖 , 𝑤) contains 𝑞𝑗 if and only if

there is a walk in the transition graph from 𝑞𝑖 to 𝑞𝑗 labeled 𝑤.

This holds for all 𝑞𝑖 , 𝑞𝑗 ∈ 𝑄, and 𝑤 ∈ Σ* .

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).

Productive walk: A walk


𝑤
𝑤 = 𝑎1, 𝑎2, . . . , 𝑎𝑛 ≡ 𝑞0 −→ 𝑞𝑛

is productive if its start-vertex is an initial state

and its end-vertex is a final state, i.e. 𝑞0 ∈ 𝐼 and 𝑞𝑛 ∈ 𝐹 .

Word and language accepted by an NFA 𝑀 or its transition graph 𝑇 (𝑀 ):

We say that

an NFA 𝑇 (𝑀 ) accepts or recognizes a word 𝑤 = 𝑎1 , 𝑎2 , . . . , 𝑎𝑛 [or 𝑤 accepted by 𝑇 (𝑀 )]

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

Definition 2.9 (Language accepted by NFA)


The language being accepted by an NFA 𝑀 = (𝑄, Σ, 𝐼, 𝛿, 𝐹 ) is determined by

𝐿(𝑀 ) = {𝑤 ∈ Σ* : 𝛿 *(𝑞, 𝑤) ∩ 𝐹 ̸= ∅, ∃𝑞 ∈ 𝐼}. (2.2)

It is the language consists of all strings 𝑤 = 𝑎1 , 𝑎2 , . . . , 𝑎𝑛 labeling of a productive walk.

𝑤
Explicitly this means for each string 𝑤 ∈ 𝐿(𝑀 ) there is a walk labeled 𝑞 −→ 𝑝 from an

initial vertex 𝑞 ∈ 𝐼 of the transition graph to some final vertex 𝑝 ∈ 𝐹 .

So instead of using

𝐿(𝑀 ) = {𝑤 ∈ Σ* : 𝛿 *(𝑞, 𝑤) ∩ 𝐹 ̸= ∅, ∃𝑞 ∈ 𝐼},

we also use the equivalent


𝑤
𝐿(𝑀 ) = {𝑤 ∈ Σ* : ∃𝑞 ∈ 𝐼, ∃𝑝 ∈ 𝐹, and there exists the path 𝑞 −→ 𝑝}. (2.3)

MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 38

Knowledge box 2 (Regular Expressions denote Regular Languages).

The language accepted by an NFA so is defined by the extended transition 𝛿 * (𝑞, 𝑤) [Def.

2.8].

A language 𝐿 is regular if there exists a regular expression generating 𝐿 [Def. 2.4

(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

expressions later in Section 2.7, including two smaller problems

1. Regular Expressions define regular languages: how construct an NFA 𝑀 from a given reg-

ular expression 𝑟 , so that 𝑀 accepts 𝐿(𝑟).

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

expression that generates 𝐿.

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.

Construct an accepting NFA.

(II) Give regular expression for the following finite automaton

𝑎 𝑏
𝑏
𝑞0 𝑞1 𝑎 𝑞2
𝑏
𝑎

PROBLEM 2.5. Do Exercise on page 4.3y, for 𝑦 = 1, 2, 3 of REF. 1.

MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 40

2.4.2 Deterministic finite automata

Definition 2.10 (Deterministic finite automaton (DFA))


A deterministic finite automaton or DFA 𝑀 is defined by a 5-tuples

𝑀 = (𝑄, Σ, 𝑞0, 𝛿, 𝐹 )

with

1. 𝑄 a finite, nonempty set of states,

2. Σ is the input alphabet,

3. 𝑞0 ∈ 𝑄 is the initial state,

4. 𝛿 : 𝑄 × Σ → 𝑄 is a transition function,

5. 𝐹 ⊆ 𝑄 is the set of final/accepting states of the automaton, |𝐹 | ≥ 1.

ELUCIDATION
MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 41

A DFA fulfills that |𝐼| = 1 and moreover

|𝛿(𝑞, 𝑎)| ≤ 1, ∀𝑞 ∈ 𝑄, ∀𝑎 ∈ Σ

in Defi. 2.7.

For letter 𝑎 ∈ Σ, if |𝛿(𝑞, 𝑎)| = 1

then 𝛿(𝑞, 𝑎) = 𝑝, an edge in the transition graph 𝑇 (𝑀 ).

The fact |𝛿(𝑞, 𝑎)| = 0 says 𝛿(𝑞, 𝑎) = ∅ (nonfinal trap state in the DFA):

this represents an impossible move for the automaton and, therefore,

means nonacceptance of the letter 𝑎, and nonacceptance of any string 𝑟 holding 𝑎.

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

each move consumes one input symbol of 𝑟 .

The transition graph 𝑇 (𝑀 ) of finite automaton 𝑀 has an edge (𝑞, 𝑝) with label 𝑎...

When the end letter 𝑠 of the string 𝑟 = 𝑎 𝑏 𝑐 . . . 𝑠 is reached,

the string is accepted if the automaton is in state 𝑝𝑛 ∈ 𝐹 (one of its final states):
𝑎 𝑏 s
𝑞 −→ 𝑝 −→ · · · −→ pn.

Otherwise the string is rejected. ♦

♦ 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

A DFA with two states and only one accepting state

i/ Determine the transition 𝛿 .

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.

i/ The transition 𝛿 fulfills 𝛿(𝑞0 , 𝑎) = 𝑞1 , 𝛿(𝑞0 , 𝑏) = 𝑞0 . . . and given in table

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.

iii/: Perhaps we redefine the new defining string

𝑠 = 𝑏*𝑎𝑚𝑏*, 𝑚 = 2𝑘 =⇒ 𝐵 = 𝐿(𝑀𝐵 )

where 𝑀𝐵 = (𝑄, Σ, 𝑞1 , 𝛿, 𝐹 ), 𝐹 = {𝑞0 }? ■

MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 45

Proposition 2.1
Transition graphs provide convenient ways for working with FA. ♠

Precisely, given a DFA 𝑀 = (𝑄, Σ, 𝑞0 , 𝛿, 𝐹 ), let its transition graph be 𝑇 (𝑀 ).

For all 𝑞𝑖 , 𝑞𝑗 ∈ 𝑄, and 𝑤 ∈ Σ+ , then the extended transition

𝛿 *(𝑞𝑖, 𝑤) = 𝑞𝑗 if and only if there is a walk with label 𝑤 (in 𝑇 (𝑀 )) from 𝑞𝑖 to 𝑞𝑗 .

♦ EXAMPLE 2.12. Set alphabet Σ = {0, 1}

Give a DFA that accepts all words that contain a number of 0 multiple of 3.

Give an execution of this automaton on word w= 1101010.

Any other way to define DFA?

GUIDANCE for solving.

Define the states 𝑄, the transition 𝛿 and set 𝐹 of accepting states properly.

MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 46

i) Call DFA 𝑀 = (𝑄, Σ, 𝑞0 , 𝛿, 𝐹 ) with 𝑄 = {𝑞0 , 𝑞1 }, and 𝐹 = {𝑞1 }?.

Then define a transition 𝛿 such that 𝛿(𝑞𝑜 , 𝑤) ∈ 𝐹 for any word 𝑤 satisfying that 𝑛0 (𝑤) mod 3 = 0

[word 𝑤 contains a number of 0 multiple of 3].

1 1
0
𝑞0 𝑞1
0

ii) Here 𝑤 = 1101010 fulfills 𝑛0 (𝑤) mod 3 = 0, and 𝛿(𝑞𝑜 , 𝑤) = 𝑞1 ∈ 𝐹 .

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

PROBLEM 2.6. Do Exercise on page 4.37, REF.1.

MATHEMATICAL MODELING
Methods and Applications
2.4. PART B. FINITE AUTOMATA 48

WHAT NEXT?

We next study four basic problems in Finite Automata theory:

1. Construction of a DFA and NFA from a given language 𝐿, or a given regular expression 𝐸 ,

Section 2.5.1 and 2.5.2.

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

not. This type of problem will not arise for DFA.

3. Minimization of a DFA, given in Section 2.6.2; Why? To save storage in computer.

4. Inverse of Problem 1: Determining a regular expression given an automaton (NFA- DFA),

studied in Section 2.7.

Problems 1 and 4 show a mutual relationship between languages and automata.

MATHEMATICAL MODELING
Methods and Applications
WEEK 5 - Finite Automata- Basic Problems

[[GoogleMap]]

Problem 1: finding automata (DFA and NFA) given a regular expression

Problem 2: studying equivalence of DFA and NFA (transform NFA to DFA)

Problem 3: minimizing a DFA

Problem 4: finding a regular expression given an automaton


2.5. Finite Automata- Basic Problems 50

2.5 Finite Automata- Basic Problems

2.5.1 Recognized languages and Construct a DFA

Definition 2.11 (Language recognized (accepted) by DFA)


I) A language 𝐿 ⊂ Σ* (over an alphabet Σ) is accepted by an automaton

if there exists a DFA𝑀 accepting all strings of 𝐿. Then we write 𝐿 = 𝐿(𝑀 ).

Precisely, the language 𝐿(𝑀 ) being accepted by a DFA 𝑀 = (𝑄, Σ, 𝑞0 , 𝛿, 𝐹 ) is determined

by productive words 𝑤:

𝐿(𝑀 ) = {𝑤 ∈ Σ* : 𝛿 *(𝑞0, 𝑤) ∈ 𝐹 }. (2.4)

Nonacceptance means that the DFA stops in a nonfinal state, so that

𝐿(𝑀 ) = {𝑤 ∈ Σ* : 𝛿 *(𝑞0, 𝑤) ̸∈ 𝐹 }.

II) A language is said to be regular if it is accepted by some DFA 𝑀 .

MATHEMATICAL MODELING
Methods and Applications
2.5. Finite Automata- Basic Problems 51

Proposition 2.2
Given two accepted (recognized) languages 𝑋, 𝑌 by certain DFA 𝑀

𝑌 , 𝑋 · 𝑌 , and 𝑋 * are also recognized.


⋃︀ ⋂︀
then 𝑋 𝑌,𝑋 ♠

♦ EXAMPLE 2.13 (From a language to a DFA).

Construct a DFA given in above figure with 3 states 𝑄 = {𝑞0 , 𝑞1 , 𝑞2 },

the alphabet Σ = {𝑎, 𝑏}, and such that it

recognizes the language 𝐿 containing the sub-string 𝑎𝑏.

MATHEMATICAL MODELING
Methods and Applications
2.5. Finite Automata- Basic Problems 52

GUIDANCE for solving.

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 𝑎𝑏]

implies that 𝐿 consists of regular expression of the form 𝑆𝑙 𝑎𝑏 𝑆𝑟 = (𝑎 + 𝑏)* 𝑎𝑏 (𝑎 + 𝑏)* .

Indeed, first 𝑞0 ̸∈ 𝐹 , and |𝐹 | ≥ 1.

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 ∈ 𝐹.

This results in 𝐹 = {𝑞2 }. As a result, any word 𝑤𝑟𝑖𝑔ℎ𝑡 = 𝑎𝑏 (𝑎 + 𝑏)* ∈ 𝐿.

Second since 𝑀 is deterministic, 𝑤𝑙𝑒𝑓 𝑡 = (𝑎 + 𝑏)* 𝑎𝑏 ∈ 𝐿 and so the concatenated word

𝑤 = 𝑤𝑙𝑒𝑓 𝑡 · 𝑤𝑟𝑖𝑔ℎ𝑡 = (𝑎 + 𝑏)* 𝑎𝑏 (𝑎 + 𝑏)* ∈ 𝐿 = 𝐿(𝑀 ).

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 𝑇 (𝑀 )?

This example shows a language 𝐿, accepted by the above DFA 𝑀 , so 𝐿 is regular. 𝐿 is

precisely determined by a regular expression 𝑎𝑏:

MATHEMATICAL MODELING
Methods and Applications
2.5. Finite Automata- Basic Problems 54

𝐿 = 𝐿(𝑎𝑏) = {𝑟, 𝑟 = (𝑎 + 𝑏)* 𝑎𝑏 (𝑎 + 𝑏)*}. ■


)︀*
NOTE: (𝑎 + 𝑏)* = {𝑎} ∪ {𝑏} = Σ*
(︀

is the set of all string made by 𝑎, 𝑏 in any order and length.

And writing 𝑐 𝑑 ≡ 𝑐 · 𝑑 = concatenation of two strings 𝑐, 𝑑.

PRACTICE 2.6.

Determine a DFA that recognizes the language over the alphabet {𝑎, 𝑏} with an even number

of 𝑎 and an even number 𝑏.

Automaton:

Shall we provide a deterministic machine 𝑀 so that each productive word in its language

𝐿(𝑀 ) has an even number of 𝑎 and an even number 𝑏?

MATHEMATICAL MODELING
Methods and Applications
2.5. Finite Automata- Basic Problems 55

The machine is defined by table below in which we denote

→: start state, and


*
: final state(s)

𝑎 𝑏
→ 𝑞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

2.5.2 Regular languages and Construct an NFA

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.

Theorem 2.1 (THEOREM 3.1 of REF. 2)


(I) If we have any regular expression 𝑟 , we can construct an nondeterministic finite

automaton (NFA) 𝑀 that accepts the language 𝐿(𝑟).

(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

b) symbolic representation of M(empty)


a) symbolic representation of M(r)

c) symbolic representation of M(λ) d) symbolic representation of M(a)

Figure 2.3: Symbolic representation of automata based on (primitive) regular expressions

2. The simple (primitive) regular expressions ∅, 𝜀(𝜆), and 𝑎 ∈ Σ determine the automata (and

their accepted languages), respectively shown in Figure 2.3.b) to d).

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

Figure 2.4: Automaton for L (r1 r2)

♦ EXAMPLE 2.14 (From a language to a NFA).

Construct an NFA with 3 states 𝑄 = {𝑞0 , 𝑞1 , 𝑞2 }, and the alphabet Σ = {𝑎, 𝑏}, that recog-

nizes the given language 𝐿(𝑟) where 𝑟 = (𝑎 + 𝑏𝑏)* (𝑏𝑎* + 𝜀).

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

Step 2: Building up the grand NFA (as a


product or concatenation of M1, M2)
Step 1: Construct NFA of compnents,
M1 accepts L1= L(a+bb)...

Figure 2.5: Construct an NFA with 3 states

𝐿1 = 𝐿(𝑟1) = 𝐿((𝑎 + 𝑏𝑏)*) = 𝐿(𝑎 + 𝑏𝑏), the left bottom figure shows 𝑀2 accepting
𝐿2 = 𝐿(𝑟2) = 𝐿((𝑏𝑎* + 𝜀)) = 𝐿((𝑏𝑎* 𝜀 + 𝜀)). The result machine 𝑀 = 𝑀 (𝑟1 𝑟2) = 𝑀1 · 𝑀2.

PROBLEM 2.7. Consider the set of strings Σ* on Σ = {𝑎, 𝑏, 𝑐}.

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

𝐸1 = 𝑎* + 𝑏*𝑎, 𝐸2 = 𝑏* + 𝑎* 𝑎𝑏 𝑎*, and 𝐸2 = 𝑎𝑎𝑏 + 𝑐𝑎𝑏* 𝑎𝑐.

DIY: See Figures 3.3 till 3.5 in REF.2. for automata 𝑀 (𝑟1 + 𝑟2 ) and 𝑀 (𝑟1* ), given regular

expressions 𝑟1 , 𝑟2 .

PROLOGUE - WHAT NEXT ?

We study Equivalence of DFA and NFA.

MATHEMATICAL MODELING
Methods and Applications
PART C. Equivalence of DFA and NFA

AIM: Study Equivalence of DFA and NFA

[[GoogleMap]]
2.6. PART C: Equivalence of DFA and NFA 62

2.6 Equivalence of DFA and NFA

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

as their relationship are briefed as follows.

♣ OBSERVATION 1.

1. A DFA (deterministic automaton) is in essence a restricted kind of NFA, it is clear that any

language that is accepted by a DFA is also accepted by some NFA. Generally,

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

claim: For every language 𝐿𝐷 accepted by some DFA

there is a NFA 𝑀 that accepts the same language, 𝐿(𝑀 ) = 𝐿𝐷 .

But the converse (from NFA to DFA) is not so obvious.

MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 63

How to convert any NFA into an equivalent DFA?

We need the concept of equivalence between finite automata 𝑀1 and 𝑀2 :

𝑀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

bottom-right, since they both accept the language 𝐿 = {(10)𝑛 : 𝑛 ≥ 0}.

MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 64

DFA

NFA

Figure 2.6: Equivalence of two small automata

MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 65

2.6.1 From NFA (non-deterministic automaton) to DFA

Theorem 2.2 (From NFA to DFA- Theorem 1.10 of REF.3)


For any NFA one may construct an equivalent DFA. ♡

An algorithm for transforming a NFAto an equivalent DFA must have:

Input: A NFA 𝑀𝑁 = (𝑄𝑁 , Σ, 𝐼 ∋ 𝑞0 , 𝛿𝑁 , 𝐹𝑁 ),

and let 𝐿 be the language accepted by 𝑀𝑁 .

Output: A DFA 𝑀𝐷 = (𝑄𝐷 , Σ, {𝑞0 }, 𝛿𝐷 , 𝐹𝐷 ) such that 𝐿 = 𝐿(𝑀𝐷 ).

HOW to transform from non-deterministic machine 𝑀𝑁 to deterministic machine 𝑀𝐷 ?

1. In the transition graph 𝑇𝐷 = 𝑇 (𝑀𝐷 ) of DFA 𝑀𝐷 ,

every node must have exactly |Σ| outgoing edges,

MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 66

each labeled with a different element of Σ (by definition).

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 𝑆𝑛 ,

see ALGORITHM 2.1 [THEOREM 2.2, REF.2.]

MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 67

Algorithm 2.1 NFA to an equivalent DFA(𝑀𝑁 = (𝑄𝑁 , Σ, 𝐼 ∋ 𝑞0 , 𝛿𝑁 , 𝐹𝑁 ))


1) Initializing 𝑇𝐷 : Create 𝑇𝐷 vertex 𝐼 ∋ 𝑞0 , identify it as the initial vertex. Set 𝑆 = 𝐼 .

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

as a final vertex in the DFA 𝑀𝐷 . Update 𝑆 = 𝑆𝑛 , go back to Step 2.

Stopping condition: No more edges are missing.

If 𝑀𝑁 accepts empty string 𝜀, the vertices 𝐼 in 𝑇𝐷 is also made a final vertex.

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

length of the input string.

2. An important conclusion we can draw from ALGORITHM 2.1 is that every language ac-

cepted by an NFA is regular.

♦ EXAMPLE 2.16.

Given a NFA 𝑀𝑁 = (𝑄𝑁 , Σ, 𝐼 ∋ 𝑞0 , 𝛿𝑁 , 𝐹𝑁 ) [top-left in next figure]

where 𝑄𝑁 = {0, 1}, Σ = {𝑎, 𝑏}, the start 𝐼 = {0}, the final 𝐹𝑁 = {1},

and the transition function 𝛿𝑁 is given by table below,

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 .

Loop 𝑛 = 1: 𝑆1 := {0}, [use 𝑏], next use 𝑎 on 0 shows 𝑆2 := {1} = 𝐹𝑁 , but

𝑆2 becomes final in 𝑇𝐷 ;
* *
Loop 𝑛 = 2: 𝛿𝑁 (1, 𝑎) = {0} and 𝛿𝑁 (1, 𝑏) = {1}, gives us 𝑆3 := {0, 1}, now becomes final in 𝑇𝐷 ;

Repeat steps ... till no more edges are generated.

The result DFA 𝑀𝐷 has the states 𝑄𝐷 = {𝑆0 , 𝑆2 , 𝑆3 } = {{0}, {1}, {0, 1}, },

the final states 𝐹𝐷 = {{1}, {0, 1}},

MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 70

the transition 𝛿𝐷 is in the left bottom of figure below.

MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 71

Definition 2.12 (Accessible states )


A state 𝑝 is accessible in a DFA 𝑀 = (𝑄, Σ, {𝑞0 }, 𝛿, 𝐹 ) if it is on a walk which starts by

an initial state: 𝑞0 → · · · 𝑝 → · · · .

RULE: The inaccessible states [not on any walk which starts by an initial state] of 𝑀 can

be eliminated without changing accepted language. ♣

Reminder: accessible and productive states are different.

A state 𝑝 is productive if it is on a walk which ends in a final state: · · · → 𝑝 → 𝑞𝑛 ∈ 𝐹 .

PRACTICE 2.7. (I) Remake EXAMPLE 2.15.

(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

A nondeterministic finite automaton with 3 states

GUIDANCE for solving.

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 .

Loop 𝑛 = 1: 𝑆1 := {𝑞0}, [use 𝜀], 𝑆2 := {𝑞1}, [use 0 on 𝑞0 , 𝑆2 become final in 𝑇𝐷 ];


*
Loop 𝑛 = 2: 𝛿𝑁 (𝑞1, 1) = 𝑞2 gives 𝑆3 := {𝑞2}, [become final in 𝑇𝐷 ];

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

Make the transition function 𝛿𝐷 with Equation 2.5

{︁ ⋃︁ }︁
*
𝛿𝐷 (𝑞𝐷 , 𝑎) = 𝛿𝑁 (𝑞, 𝑎) , ∀𝑞𝐷 ∈ 𝑄𝐷 , ∀𝑎 ∈ Σ. [𝑞𝐷 = 𝑆 in Step 2i) ]
𝑞∈𝑞𝐷

we get the transition table

𝛿𝐷 0 1

→ 𝑆0 {𝑆2 } {𝑆3 }
𝑆1 {𝑆2 } ∅
𝑆2 ∅ {𝑆3 }
𝑆3 {𝑆3 } {𝑆3 }
𝑆4 {𝑆5 } {𝑆3 }
𝑆5 {𝑆3 } {𝑆3 }
𝑆6 {𝑆5 } {𝑆3 }

This automaton contains many inaccessible states, 𝑆1 , 𝑆4 , 𝑆5 , 𝑆6 , and

MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 74

deleting them determines the accessible states of DFA:

𝑈0 = {𝑆0}, 𝑈1 = {𝑆0, 𝑆2, 𝑆3}, 𝑈2 = {𝑆0, 𝑆2, 𝑆3} = 𝑈1 = 𝑈.


The transition table of the resulted DFA 𝑀𝐷 is

𝛿𝐷 0 1

→ 𝑆0 {𝑆2 } {𝑆3 }
𝑆2 ∅ {𝑆3 }
𝑆3 {𝑆3 } {𝑆3 }

The equivalent DFA with NFA above

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

The corresponding transition graph 𝑇 (𝑀𝐷 ) is in Fig 2.7. ■

NFA

The output DFA

Figure 2.8: NFA-to-DFA

PRACTICE 2.8.

A/ Use ALGORITHM 2.1 to transform the NFA in Figure 2.8 to a DFA 𝑀𝐷 .

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

𝑏 𝑎
𝑏

C/ Do Exercises on page 4.4x, 𝑥 = 6, 7, 8 in REF.1.

MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 77

2.6.2 Minimization of a DFA

♣ 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.

Representation of an automaton for computation requires space proportional to the num-

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 𝛿 . ♣

Distinguishablity: States 𝑝 and 𝑞 of 𝑀 are called distinguishable

MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 78

𝐷𝐼𝑆 : if there exists some string 𝑤 ∈ Σ* such that

𝛿 *(𝑝, 𝑤) ∈ 𝐹 and 𝛿 *(𝑞, 𝑤) ̸∈ 𝐹.

[I go to final, and You not]

Indistinguishablity:

Two states 𝑝 and 𝑞 of 𝑀 are called indistinguishable if 𝐷𝐼𝑆 happens:

∀𝑤 ∈ Σ* : 𝛿 *(𝑝, 𝑤) ∈ 𝐹 ⇔ 𝛿 *(𝑞, 𝑤) ∈ 𝐹 [ we are in the same class!]

ELUCIDATION

Hence, indistinguishablity defines a ‘binary relation’ on the set 𝑄.

At the original automaton, the set of final states 𝐹 makes a ‘equivalence class’, and the

complement 𝐹 𝑐 = 𝑄 ∖ 𝐹 makes another ‘equivalence class’.

Under actions of symbols in Σ and words in Σ* the states in 𝑄 change their equivalence

classes, until a stopping status occurs.

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

determines all pairs of distinguishable states, we get a minimum DFA.

REMINDER
Proposition 2.3
An equivalence relation 𝑅 ⊂ 𝐾 × 𝐾 satisfies 3 properties: reflexive, symmetric and

transitive.

Given an equivalence relation 𝑅, the equivalence class of state 𝑝 ∈ 𝐾 is

𝑅𝑝 = {𝑞 ∈ 𝐾 : 𝑞 𝑅 𝑝} = {𝑞 ∈ 𝐾 : (𝑝, 𝑞) ∈ 𝑅}.

On any set 𝐾 , if we could define an equivalence relation 𝑅

then we can build up equivalence classes {𝑅𝑘 } and


⋃︀
they give a partition of 𝐾 : 𝐾 = 𝑅𝑘 .
𝑘∈𝐾 ♠

Multi-steps approach for

CONSTRUCTION of Equivalent automata

MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 80

∙ ALGORITHM 2.1: Transform an NFA 𝑀0 to a new DFA 𝑀 ; done.

∙ Then min (DFA) Problem means Minimization of 𝑀 to a minimal DFA 𝑀1.

(Minimal in the sense of minimum number of states).

Minimization of automaton 𝑀 includes

ALGORITHM 2.2: Find all equivalence classes of 𝑀

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

eliminated without changing accepted language

∙ ALGORITHM 2.3: Construct the minimal DFA 𝑀1.

MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 81

Algorithm 2.2 Equivalence-Classes-DFA(𝑄, Σ, {𝑞0 }, 𝛿, 𝐹 )) - Procedure mark, REF.2.

Input: A DFA 𝑀 = (𝑄, Σ, {𝑞0 }, 𝛿, 𝐹 ).

Output: all equivalence classes of nodes in the graph 𝑇 (𝑀 ) of 𝑀 .

1) Avoid redundancy: Remove all inaccessible states, by

enumerating all simple paths of 𝑇 (𝑀 ) starting at the initial state 𝑞0 . Any state not part of some path is inac-

cessible.

2) Loop 𝑛 = 1: Create equivalence classes: Consider all pairs of states (𝑝, 𝑞 ) in 𝑇 (𝑀 ).

If 𝑝 ∈ 𝐹 and 𝑞 ̸∈ 𝐹 or vice versa, we mark the pair (𝑝, 𝑞) as distinguishable (they are in distinct equivalence

classes). So there are at least two equivalence classes.

3) Loop 𝑛 ≥ 2 to find all equivalence classes of states: Repeat the following step:

For all pairs (𝑝, 𝑞) and all symbol 𝑎 ∈ Σ, compute

𝛿(𝑝, 𝑎) = 𝑝𝑎 and 𝛿(𝑞, 𝑎) = 𝑞𝑎 .


If the new pair (𝑝𝑎 , 𝑞𝑎 ) is marked as distinguishable, we mark (𝑝, 𝑞) as distinguishable.

Until Stopping condition valid: No previously unmarked pairs are marked. In other words, denote 𝑆𝑛 and

𝑆𝑛+1 be the sets of equivalent classes at loop 𝑛,


if 𝑆𝑛 = 𝑆𝑛+1 , then stop and return 𝑆𝑛 as an equivalent partition.

REMARK: Indistinguishability classes of machine 𝑀 are equivalence classes of nodes in graph 𝑇 (𝑀 ).


MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 82

♦ EXAMPLE 2.17 (Use ALGORITHM 2.2 to find indistinguishability classes).

Consider the top-left automaton 𝑀 as follows.

Given a deterministic automaton M

We find a minimum DFA M1 of M

Indistinguishability classes of machine 𝑀 are equivalence classes of nodes in graph 𝑇 (𝑀 ).

In Step 2 we get two equivalence classes 𝐼 = {𝑞2 , 𝑞4 } = 𝐹 and 𝐼𝐼 = {𝑞0 , 𝑞1 , 𝑞3 } = 𝐹 𝑐 .

MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 83

In Step 3, use action 𝑎 = 0 on states 𝑞0 , 𝑞1 :

𝛿(𝑞0, 0) = 𝑞1 and 𝛿(𝑞1, 0) = 𝑞2, the outputs are distinguishable,

so we must split the old 𝐼𝐼 = {𝑞0 , 𝑞1 , 𝑞3 } into new 𝐼𝐼 = {𝑞0 } and 𝐼𝐼𝐼 = {𝑞1 , 𝑞3 }.

Next on states 𝑞2 , 𝑞4 :

𝛿(𝑞2, 0) = 𝑞1 and 𝛿(𝑞4, 0) = 𝑞4, the outputs are again distinguishable,

so we must split class 𝐼 = {𝑞2 , 𝑞4 } into new 𝐼 = {𝑞2 } and 𝐼𝑉 = {𝑞4 }.

No further splitting is needed, obtain 4 nodes in total.

We could identify (label) 𝐼 as number 2, node 𝐼𝐼 as 0, 𝐼𝐼𝐼 as series 1 3 . . . ■

MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 84

Given a deterministic automaton M

We find a minimum DFA M1 of M

ALGORITHM 2.3 [Construction of the minimal DFA- Procedure reduce, REF.2.]

MATHEMATICAL MODELING
Methods and Applications
2.6. PART C: Equivalence of DFA and NFA 85

Algorithm 2.3 Construction of the minimal DFA(𝑄, Σ, {𝑞0 }, 𝛿, 𝐹 ))


Input: A DFA 𝑀 = (𝑄, Σ, {𝑞0 }, 𝛿, 𝐹 ).

Output: A reduced DFA 𝑀1 = (𝑄1 , Σ, 𝑞* , 𝛿1 , 𝐹1 ) such that |𝑄1 | ≤ |𝑄|.

1) Find distinguishable classes:

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.

If 𝑞 ∈ 𝐶𝑘 = {𝑞𝑖 , 𝑞𝑗 , . . . , 𝑞𝑘 } and 𝑝 ∈ 𝐶𝑛 = {𝑞𝑙 , 𝑞𝑚 , . . . , 𝑞𝑛 } where class 𝐶𝑛 disjoint class 𝐶𝑘 we then symboli-

cally set

rule 𝛿1 as 𝛿1 (𝐶𝑘 , 𝑎) = 𝐶𝑛 , or 𝛿1 (𝑖 𝑗 · · · , 𝑎) = 𝑙 𝑚 · · · 𝑛.

4) Locate the new initial state 𝑞* :

New initial state 𝑞* of 𝑀1 is one of state 𝐶𝑘 including the 0.

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

♦ EXAMPLE 2.18 (Use ALGORITHM 2.3 to find min DFA).

Given a deterministic automaton M

We find a minimum DFA M1 of M

From EXAMPLE 2.17, steps 1) and 2) are done by ALGORITHM 2.2.

In step 3) we define the transition rule for the bottom-right automaton 𝑀1 .

For example with 𝑎 = 0, choose 𝐶𝑘 = 𝐼𝐼𝐼 = {𝑞1 , 𝑞3 },

then 𝛿(𝑞1 , 0) = 𝑞2 ∈ 𝐼 , and class 𝐼 ∩ 𝐶𝑘 = ∅.

So there is an edge labeled 0 from state 𝐼𝐼𝐼 ≡ 1 3 to state 𝐼 ≡ 2.

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 .

How about the node of initial state 𝑞* and 𝐹1 ?

Step 4): the class 𝐼𝐼 = {𝑞0 } in 𝑇 (𝑀 ) give node initial state 𝑞* = 0 in 𝑀1 .

Step 5): 𝐹 = {𝑞2 , 𝑞4 } so the new final set of 𝑀1 is

𝐹1 = {𝐶𝑛 : 𝑖 ∈ 𝐶𝑛 ∧ 𝑞𝑖 ∈ 𝐹 } = {2, 4}.

We obtain fully the reduced DFA 𝑀1 = (𝑄1 , Σ, 𝑞* , 𝛿1 , 𝐹1 ).

See slides 4.50 and 4.51 in REF.1 for more example.

MATHEMATICAL MODELING
Methods and Applications
2.7. Determine regular expression given automata 88

2.7 Determine regular expression given automata

Recall Problem 4: finding a regular expression given an automaton

Definition 2.11 suggests that the connection

between regular languages and regular expressions [as in Definition 2.3]

is a mutually close one. The two concepts are essentially the same:

(i) for every regular language there is a regular expression, and

(ii) for every regular expression there is a regular language.

2.7.1 Regular Expressions denote Regular Languages

Because of the equivalence of NFA’s and DFA’s, a language is also regular if it is accepted

by some NFA.

Theorem 2.1 claims the existence of a NFA𝑀 (𝑟), given 𝑟 :

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

(NFA) that accepts the language 𝐿(𝑟).”

♦ EXAMPLE 2.19. Given 3 states 𝑄 = {𝑞0, 𝑞1, 𝑞2}, and the alphabet Σ = {𝑎, 𝑏},

we construct an NFA that recognizes the language 𝐿(𝑟) where the regular

𝑟 = (𝑎 + 𝑏𝑏)* (𝑏𝑎* + 𝜀).

We can use this theorem to build 𝑀 = 𝑀1 · 𝑀2 , the concatenation of 𝑀1 , 𝑀2 . Indeed,

𝑀1 [fig. (a)] accepts the language 𝐿1 = 𝐿((𝑎 + 𝑏𝑏)*),

𝑀2 [fig. (b)] accepts the language 𝐿2 = 𝐿(𝑏𝑎* + 𝜀).

The product language 𝐿 = 𝐿1 𝐿2 is accepted by the NFA 𝑀 .

MATHEMATICAL MODELING
Methods and Applications
2.7. Determine regular expression given automata 90

Step 2: Building up the grand NFA (as a


product or concatenation of M1, M2)
Step 1: Construct NFA of compnents,
M1 accepts L1= L(a+bb)...

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

2.7.2 Regular Languages gives Regular Expressions

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.

COMPLICATION: by the existence of cycles in 𝑇 (𝑀 ) that can be traversed arbitrarily.

IDEAS: use generalized transition graphs (GTG).

The graph 𝑇 (𝑀 )) of any NFA 𝑀 can be considered a new generalized transition graph

𝐺𝑇 (𝑀 ) if the edge labels are interpreted properly.

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

𝑎, while an edge labeled with multiple symbols 𝑎, 𝑏, . . . is interpreted as


an edge labeled with the expression 𝑎 + 𝑏 + . . ..

Definition 2.14 (Generalized Transition Graph (GTG))


(I) A generalized transition graph 𝐺𝑇 (𝑀 ) of an NFA 𝑀 is a transition graph whose edges

are labeled with regular expressions.

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

(II) A complete GTG is a graph in which all edges are present.

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

state at a time, until only two states are left.

♦ EXAMPLE 2.20. Figure 2.9 represents a generalized transition graph 𝐺𝑇 (𝑀 ).

The language accepted by 𝐺𝑇 (𝑀 ) is 𝐿 = 𝐿(𝑅) = 𝐿(𝑎* + 𝑎* (𝑎 + 𝑏) 𝑐* ),

as clearly seen from an inspection of the graph.

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

A simple a generalized transition graph of language L,


giving the regular expression R

Figure 2.9: A simple GTG, language 𝐿 and its regular expression

We could have labeled this edge 𝑎* without changing the language accepted by the graph.

(since the label of every walk in a GTG is a regular expression). ■

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

This automaton M returns a regular expression?

Figure 2.10: A simple NFA and its regular expression?

Can we check that the regular expression 𝑅 from this GTG is

𝑅 = 𝑟1* 𝑟2 (𝑟3 𝑟1* 𝑟2 + 𝑟4)*? (2.6)

Using double indexes for edges, in this complete GTG with 4 arcs, we can replace

regular expression 𝑟1* by 𝑟𝑖* 𝑖 , 𝑟2 by 𝑟𝑖 𝑗 , 𝑟3 by 𝑟𝑗 𝑖 , and finally 𝑟4 by 𝑟𝑗 𝑗 . ■

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 𝐿

Output: A regular expression 𝑅 such that 𝑀 = 𝑀 (𝑅) or 𝐿 = 𝐿(𝑅)

[ IDEA: Perform the process 𝑀 −→ 𝐺𝑇 (𝑀 ) −→ 𝑅]

(1) Conversion: Convert 𝑀 into a complete GTG 𝐺𝑇 (𝑀 ) = (𝑉, 𝐴).

Put label 𝑟𝑖 𝑗 to the edge from 𝑞𝑖 ∈ 𝑉 to 𝑞𝑗 ∈ 𝑉 .

(2) Checking the number of nodes and making decision:

2a): If the GTG has only two states, with 𝑞𝑖 as its initial state and 𝑞𝑗 its final state, its associated regular

expression [extended from Equation 2.6] is


)︀*
𝑅 = 𝑟𝑖* 𝑖 𝑟𝑖 𝑗 𝑟𝑗 𝑖 𝑟𝑖* 𝑖 𝑟𝑖 𝑗 + 𝑟𝑗 𝑗
(︀
(2.7)

2b) If the GTG has three states, with initial state 𝑞𝑖 , final state 𝑞𝑗 , and third state 𝑞𝑘 , we create new edges

(between 𝑞𝑖 , 𝑞𝑗 ), labeled

𝑟𝑝 𝑘 𝑟𝑘* 𝑘 𝑟𝑘 𝑞 + 𝑟𝑝 𝑞 ≡ 𝑟𝑝 𝑞 + 𝑟𝑝 𝑘 𝑟𝑘* 𝑘 𝑟𝑘 𝑞 , 𝑝 = 𝑖, 𝑗, 𝑞 = 𝑖, 𝑗; (2.8)

and remove vertex 𝑞𝑘 and its associated edges.

MATHEMATICAL MODELING
Methods and Applications
2.7. Determine regular expression given automata 97

2c) If the GTG has at least 4 states, pick a state 𝑞𝑘 to be removed.

Apply rule 2b) for all pairs of states (𝑞𝑖 , 𝑞𝑗 ), 𝑖 ̸= 𝑘 , and 𝑗 ̸= 𝑘 . At each step apply the simplifying rules

[wherever possible, when this is done, remove state 𝑞𝑘 ]:



𝑟 + ∅ = 𝑟,






⎪ 𝑟 · ∅ = 𝑟,



⎩ ∅* = 𝜀,

(3) Loop and Stop:

Repeat Step 2 until the correct regular expression is obtained.

Therefore, for arbitrary GTGs we remove one state at a time

until only two states are left.

Then we apply Equation (2.6) to get the final regular expression.

♦ 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

(II) The new and equivalent GTG G1,


(I) A complete GTG G0
obtained from G0, by removing q2

Figure 2.11: Reduce node of a complete GTG

To remove 𝑞2 , we first introduce some new edges, exploit Equation 2.8, 𝑖 = 1, 𝑗 = 3:

create loop at 𝑞1 : 𝑒 + 𝑎 𝑓 * 𝑏, then create loop at 𝑞3 : ?

edge from 𝑞1 to 𝑞3 : ℎ + 𝑎 𝑓 * 𝑐,

MATHEMATICAL MODELING
Methods and Applications
2.7. Determine regular expression given automata 99

edge from 𝑞3 to 𝑞1 : 𝑖+?

When this is done, we remove 𝑞2 and all associated edges,

and get new GTG 𝐺1 in Figure 2.11.II. ■

REMINDER:

1) ALGORITHM 2.4 (NFA to regular expression) essentially includes

Step 1: Converting FA 𝑀 or language 𝐿 to a complete GTG 𝐺𝑇 (𝐿)

Step 2: Reducing complete GTG and making regular expression 𝑅.

2) Notation 𝑛𝑥 (𝑤) = the number of letter 𝑥 in string 𝑤.

♦ EXAMPLE 2.22. Find a regular expression 𝑅 for the language

𝐿 = {𝑤 ∈ {𝑎, 𝑏}* : 𝑛𝑎(𝑤) is even, and 𝑛𝑏(𝑤) is odd}.

MATHEMATICAL MODELING
Methods and Applications
2.7. Determine regular expression given automata 100

Define the states (nodes) 𝑉 and the arcs 𝐴 of the graph 𝐺𝑇 (𝐿) = (𝑉, 𝐴)?

1. Step 1: Converting a language to a complete GTG

In the graph 𝐺𝑇 (𝐿) = (𝑉, 𝐴), 𝑉 has 4 nodes

{𝑞1 = 𝐸𝐸, 𝑞2 = 𝑂𝐸, 𝑞3 = 𝑂𝑂, 𝑞4 = 𝐸𝑂)}

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

The complete GTG of L has 4 nodes, and 4^2 = 16 arcs

Figure 2.12: A complete GTG with 4 nodes

Define the arcs 𝐴?

The graph 𝐺𝑇 (𝐿) = (𝑉, 𝐴) =: 𝐺0 is complete, so |𝐴| = 16 arcs, as in Figure 2.12. We

represented a conversion of 𝐿 to a complete generalized transition graph 𝐺𝑇 (𝐿).

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

2. Step 2: Reducing complete GTG and making regular expression 𝑅

GTG has 4 states, pick a state 𝑞2 = 𝑂𝐸 to be removed, use Step 2c).

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

𝑟𝐸𝐸 = ∅ + 𝑎 ∅* 𝑎 = 𝑎𝑎

[by using Eqn. 2.8 : 𝑟𝑝 𝑞 + 𝑟𝑝 𝑘 𝑟𝑘* 𝑘 𝑟𝑘 𝑞 , 𝑝 = 𝑖, 𝑗; 𝑞 = 𝑖, 𝑗.]

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.

Equation 2.7 provides the correct regular expression 𝑅 = 𝑏 + 𝑎𝑏 (𝑏𝑏)* 𝑎.

PRACTICE 2.10.

Find a regular expression corresponding to a given finite automaton 𝑀 .

MATHEMATICAL MODELING
Methods and Applications
2.8. Reviewed Problems 104

The transition graph 𝑇 (𝑀 )

𝑏
0 1
𝑎
𝑎, 𝑏 𝑏
𝑎
3 𝑎 2 𝑏

HINT: Find the GTG 𝐺𝑇 (𝑀 ) from 𝑇 (𝑀 ), then apply Step 2 of ALGORITHM 4.

Answer:

With 𝑋 = 𝑎* 𝑏 + 𝑎* 𝑏(𝑎 + 𝑏𝑏* 𝑎)𝑎; 𝑌 = (𝑎 + 𝑏𝑏* 𝑎) ;

then 𝑅 = 𝑋(𝑌 (𝑎 + 𝑏)𝑋)* + 𝑋𝑌 ((𝑎 + 𝑏)𝑋𝑌 )* .

MATHEMATICAL MODELING
Methods and Applications
2.8. Reviewed Problems 105

2.8 Reviewed Problems

1. Consider the language 𝐿 determined by an automaton 𝑀 on Σ = {𝑎, 𝑏} as follows.


𝑎

𝑏
0 1
𝑎
𝑎, 𝑏 𝑏
𝑎
3 𝑎 2 𝑏

a/ Choose a better conclusion between statements:

i) This automaton is not a DFA since the number of states is not finite.

ii) This automata is a NFA since it is not deterministic.

b/ Is this automaton a NFA or DFA? Why?

c/ Which of the following strings is valid (accepted): 𝑎𝑎𝑏𝑏, 𝑎𝑎𝑏𝑎𝑏𝑏𝑎𝑏, or 𝑎𝑎𝑏𝑏𝑎?

MATHEMATICAL MODELING
Methods and Applications
2.8. Reviewed Problems 106

d/ Which string is not valid? 𝑎𝑏𝑎𝑏𝑎𝑏, 𝑎𝑎𝑏𝑏𝑏𝑎𝑎𝑏𝑏𝑎𝑏, or 𝑎𝑎𝑏𝑏𝑏𝑏𝑎𝑎𝑎?

e/ Which regular expression Z corresponds to the considering finite automaton

(i) 𝑋 = 𝑎* 𝑏; 𝑌 = 𝑋(𝑎 + 𝑏𝑏* 𝑎) ; 𝑍 = 𝑋(𝑌 (𝑎 + 𝑏)𝑋)*

(ii) 𝑋 = 𝑎* 𝑏 + 𝑎* 𝑏(𝑎 + 𝑏𝑏* 𝑎)𝑎; 𝑌 = (𝑎 + 𝑏𝑏* 𝑎) ; 𝑍 = 𝑋(𝑌 (𝑎 + 𝑏)𝑋)* + 𝑋𝑌 ((𝑎 + 𝑏)𝑋𝑌 )*

f/ When using determinisation algorithm [ALGORITHM 1] to convert NFA into DFA, how

many states are there in the new DFA?

6, 7, 10, or None of the others.


g/ How many states are there in the minimized/optimized DFA (which is equivalent to the

above NFA)? 6, 7, 10, or None of the others.

2. Find the correct statement

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.

3. Do the following automaton 𝑀


𝑞0

𝑏
𝑎 𝑎
𝑏
𝑞1 𝑞2
𝑎
𝑏

and regular expression 𝐸 = ((𝑎𝑎)* + 𝑏𝑏* 𝑎(𝑎𝑎)* 𝑏(𝑎𝑏)* )* present the same language 𝐿?

If not, give a counter-example.

Your choice:

(a) They are equivalent.

(b) They are not equivalent.

MATHEMATICAL MODELING
Methods and Applications
The counter-example is 𝑏𝑎𝑎?.

4. Are two regular expressions 𝐸1 = (𝑎 + 𝑏)* and 𝐸2 = (𝑎𝑎 + 𝑎𝑏 + 𝑏𝑎 + 𝑏𝑏)* are equivalent?

If not, give a counter-example.

Your choice:

(a) They present the same language

(b) 𝐸1 ⊆ 𝐸2

(c) They are not equivalent, the counter-example is 𝑎?.

5. Let’s consider Σ = {𝑎, 𝑏, 𝑐} and language 𝐿 = {𝑎, 𝑎𝑎𝑏, 𝑏𝑏𝑐, 𝑏𝑎}.

Which string does not belong to 𝐿4 ?

i) 𝑎𝑎𝑏𝑎𝑏𝑏𝑐; ii) 𝑏𝑎𝑎𝑎𝑎𝑎𝑏

iii) 𝑎𝑏𝑎𝑎𝑎𝑏𝑏𝑎 ; iv) 𝑎𝑏𝑏𝑐𝑎𝑎𝑏

You might also like