Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

chap2-fa February 15, 2024 1 chap2-fa February 15, 2024 2 chap2-fa February 15, 2024 3

Formal Languages Chapter Outline


1 Deterministic Finite Accepters

Chapter 2 Finite Automata 2 Nondeterministic Finite Accepters

3 Equivalence of Deterministic and Nondeterministic


Finite Accepters
Wuu Yang
4 Reduction of the Numbers of States in Finite

National Chiao-Tung University, Taiwan, R.O.C. Automata


5 Finite State Transducers
first draft: August 16, 2005
6 The minimal dfa of a regular language is unique

current version: February 15, 2024

©February 15, 2024 by Wuu Yang. All rights reserved. Figure 1: A first automaton (machine)

chap2-fa February 15, 2024 4 chap2-fa


In this chapter we willFebruary
discuss 15, 2024
a very simple accepter, 5 chap2-fa February 15, 2024 6

one that has no storage. §2.1 Deterministic Finite Accepters


A finite amount of information can be retained in the Example. The Coke finite automaton.
automaton without storage by placing the automaton in a
specific state.
Without an (infinite) storage device, an automaton can
remember only a limited number of input symbols by
encoding them in the internal states.
For example, if an fa has two states, it essentially can
remember one bit of information or one of two possible
input symbols. If an fa has four states, it can remember
two bits of information or one of four possible input
symbols. (On the other hand, if the input vocabulary
contains only two symbols, then the fa can remember two
previous symbols.)
(If there are n internal states, the automaton can Figure 3: The Coke machine
Figure 2: A general automaton
remember only logk n input symbols, where k is the size of
the input vocabulary.)
Finite-state automata are used in model checking. It is an
chap2-fa February 15, 2024 7 abstract notation for defining
chap2-fa February requirements
15, 2024 and design. 8 chap2-fa February 15, 2024 9
Example. A game machine. Example. A tic-tac machine.
Example. The coffee machine.

Figure 4: The coffee machine

Figure 5: A game machine Figure 6: A tic-tac machine


chap2-fa February 15, 2024 10 chap2-fa February 15, 2024 11 chap2-fa February 15, 2024 12
Example. A finite automaton. Example. A finite automaton.

Example. A flip-flop.

chap2-fa February 15, 2024 13 chap2-fa February 15, 2024 14 chap2-fa February 15, 2024 15
Definition. A deterministic finite automaton (dfa) is
defined by a quintuple M =def (Q, Σ, δ, q0 , F ), where
• Q is a finite, non-empty set of internal states.
Example. A vacuum-cleaner.
• Σ is a finite, non-empty set of input symbols, called
Example. This is a finite automaton.
input alphabet.
initial state, accepting states, hidden trap states,
• δ : Q × Σ → Q is a total function, called the transition
sentences.
function.
• q0 ∈ Q is the initial state of the automaton.
• F ⊆ Q is a non-empty set of accepting states.
In the beginning, the automaton is in the initial state q0
and the read head is positioned at the very first (that is,
leftmost) input cell. During each step, the automaton is in
a certain state, say q. It reads the symbol, say c, currently
under the read head, moves the read head forward (to the
right) one cell, changes its state to δ(q, c).
The read head moves only to the right (i.e. forward),
never to the left.
Each move consumes one input cell. When all input cells
are consumed, if the automaton is in one of the accepting
chap2-fa February 15, 2024
Because δ is a total function, every transition is uniquely16 chap2-fa February 15, 2024 17 states, it will accept theFebruary
chap2-fa input 15,
string.
2024 Otherwise, the input18

determined, Hence, the automaton is deterministic. string is rejected.


It is convenient to combine several transition steps into a
The read head moves from left to right. Each cell is read bigger step. Thus, we define δ ∗ : Q × Σ∗ → Q by (where
exactly once. a ∈ Σ, u ∈ Σ∗ )
The transition function δ may be represented as a
2-dimensional transition table (left part below) or as a This dfa accepts strings with a suffix of the form: 0 δ ∗ (q, λ) =def q
transition graph (right part below). concatenated with an odd number of 1’s and ended with
δ (q, au) =def δ ∗ (δ(q, a), u)

In a transition graph, vertices represent states and 1, such as 01000111, 0001111000111, but not 1000,
labelled edges, transitions. The initial state is designated 1011, 010001110, etc. This dfa also accepts strings with Since concatenation is associative, we may verify that
by an arrow without a tail, as state q0 in the following an odd number of 1’s but not 0’s, such as 11111.
graph. Accepting states are designated by double circles, Question. What if we change δ(q1 , 0) =def q1 ? δ ∗ (q, wb) = δ(δ ∗ (q, w), b)
as state q1 .
δ ∗ (q, αβ) = δ ∗ (δ ∗ (q, α), β)
Furthermore, since δ is a total function, so is δ ∗ .
Sometimes we draw (a part of) the graph of δ ∗ , which is
called the generalized transition graph.
chap2-fa February 15, 2024 19 chap2-fa February 15, 2024 20 chap2-fa February 15, 2024 21
Example of a transition graph.

Definition. The language accepted by a dfa M is the set


of strings that are accepted by the dfa. That is,
A convention in a transition graph. If there are two edges
L(M) =def {w ∈ Σ∗ | δ ∗ (q0 , w) ∈ F } from vertex (i.e., state) s to t labelled a and b,
respectively, they will be replaced with a single edge from
Equivalently, we have the complement of L(M): s to t labelled “a, b”. The edge from q1 to q2 is labelled
“a, b” in the above graph.
L(M) =def {w ∈ Σ∗ | δ ∗ (q0 , w) ̸∈ F } Since δ is a total function, for every symbol c in the input
Figure 7: Generalized transition graph vocabulary and for every vertex s, there is an out-going
Note that L = Σ∗ − L. edge from s that is labelled c.
In the above graph, whenever the dfa enters state q2 , it
will not be possible to reach an accepting state any more.
Such a state as q2 is called a trap state. We may
eliminate all trap states and all edges that enter them with
the understanding that transitions not explicitly drawn in
the transition graph are assumed to enter a trap state. For
chap2-fa February 15, 2024 22 chap2-fa February 15, 2024 23 example,
chap2-fa part (b) above
The state-transition shows
February
table may 15, such
2024 a simplified transition
be viewed as a program.24
graph. 2
Furthermore, constructing a dfa is not that different from
writing a C program.
Trap states Example. Find a dfa that recognizes all and only strings
In an automaton, we implicitly use a trap state. Theorem 2.1. Let M =def (Q, Σ, δ, q0 , F ) be a dfa. Let GM with prefix ab.
be its transition graph. Then for any qi , qj ∈ Q and
w ∈ Σ+ , δ ∗ (qi , w) = qj if and only if there is a path from qi
to qj labelled with w.
Proof. By induction on the length of w. (You may
try this at home.) 2

Example. Find a dfa that recognizes all and only strings


Figure 8: The implicit trap state in an automaton without a substring 001.

chap2-fa February 15, 2024 25 chap2-fa February 15, 2024 2 26 Example.


chap2-fa Find a dfa that recognizes
February 15, 2024 all and only strings in 27
Example. Show that the language L is regular.
which the number of a’s is a multiple of 3.
Solution. Note that L2 = {auaawa | u, w ∈ Hint. The set of all strings may be partitioned
Remember that a language is a set of strings. {a, b}∗ }. into three classes: [0 mod 3], [1 mod 3], and
Definition. A language is regular if and only if it is [2 mod 3]. There will be a state for each class.
accepted by a dfa. There could also be other auxiliary states.
Example. Show that the language Example. Let Σ = {a, b, c, d}. Define L1 as the set of all
Example.
strings with Find a dfa number
an even that recognizes all andL2only
of a’s. Define strings
as the set of
L =def {awa | w ∈ {a, b}∗ } is regular.
all strings in which the number of b’s is a multiple ofan
which contain the same number of a’s as b’s. (See 3.
Solution. We construct a dfa for L. example
Define L3on
=defslide 1-20.)
L1 ∩ (Can you
L2 . Define L4 =find it?)
def L1 ∪ L2 . Draw the
Example. Findlanguages.
fa’s for all four a dfa that recognizes all and only strings
aa . . . abb . . . b which contains the same number of a’s as
2 b’s. (This language is more restrictive than the above
Note that nondeterminism in state 2. language.)
2 A sentence such as abbaaabba may be interpreted in two Homework. Construct the dfa for the language {w | the
ways: number of a’s in w is a prime number }. (Solving this
• abba · aabba problem requires identifying prime numbers.)
• abbaa · abba Example. What are the strings that are accepted by the
Thus, it is naturally accepted by an nfa. It is easier to following dfa?
chap2-fa February 15, 2024 28 chap2-fa February 15, 2024 29 chap2-fa February 15, 2024
Definition. A nondeterministic finite automaton (nfa) is 30
defined by a quintuple M =def (Q, Σ, δ, q0 , F ), where
§2.2 Nondeterministic Accepters δ : Q × (Σ ∪ {λ}) → 2Q
Nondeterministic means that a finite automaton may have In contrast, for a dfa, we have δ : Q × Σ → Q
more than one possible next move in some situations. For There are three significant differences:
instance, suppose the following automaton is in state p • There could be λ transitions, such as δ(p, λ). (λ is
and the next input symbol is a. It may go to state q or part of the domain for δ.)
state r at this step. • There could be multiple next moves, such as
δ(p, a) = {q, r , s}. (The range of δ is 2Q , rather than
Q.)
• There could be no next moves at all, such as
δ(p, a) = { }. (The value of δ could be an empty set.)
Suppose δ(p, λ) = {q}. The automaton is able to transit
to state q without consuming any input symbol. Of course,
the automaton may elect not to make a λ-transition at all.
Suppose δ(p, a) = {q, r }. The automaton is free to
select state q or r as the next state. It is impossible to
predict which would be the next state.
Finally, suppose δ(p, a) = { }. This means that the
chap2-fa February 15, 2024 31 chap2-fa February 15, 2024 32 chap2-fa February 15, 2024
Example 2.9.
automaton has Figure
no way2.10to goshows
underan nfa,
this accepts 33
which situation.
specific
Example 2.8. Figure 2.9 shows an nfa, which accepts strings +
{a }. Note {2}.
An nfa can also be that δ(1, a) =as
represented However,graph.
a transition
strings λ, 1010, but not 101. Note there is a λ transition. δAn∗
(1, = {1, 2, a3}.
a)accepts Furthermore, δ(2, a) = {}. However,
nfa string w if there is at least one transition
There are two possible transitions at state 2 on the input ∗
δpath a) = {1, with
(2, labelled 2, 3}.w that leads from the initial state to an
(1) An application of nfs: We can use λ-transitions to 0. For the input 10, the nfa may end up in state 1 or state
accepting state. Otherwise the string will be rejected.
construct nfa for LṀ, as follows: 3. According to our definition, the nfa will accept 10.
Example 2.7. Fig 2.8 shows an nfa. This nfa accepts
strings {aaa, aa(aa)∗ }.

Specifically, we define the λ-closure of a state q as


[
(2) With λ transitions, we may assume that an nfa has δ ∗ (q, λ) = {q} ∪ {δ ∗ (r , λ) | q →λ r }
exactly one accepting state.
The transition function δ may be extended to strings Then we define the extended transition on a single
(called δ ∗ ), similar to the transition function of dfas. symbol a and on a string uv , as follows:
Note that, when considering δ ∗ , we may add an arbitrary [
number of λ’s into arbitrary places in a string. That is, δ ∗ (q, a) = {δ ∗ (r , λ) | p →a r , p ∈ δ ∗ (q, λ)}
[
uv = λuλλv λλλ. δ ∗ (q, uv ) = {δ ∗ (p, v ) | p ∈ δ ∗ (q, u)} (uv ̸= λ)

chap2-fa February 15, 2024 34 chap2-fa February 15, 2024 35 chap2-fa February 15, 2024 36

Scanning an input symbol a with an nfa from state q:


Note a string may be written as uv and st. For instance
the string abca may be written as (ab) · (ca) or as
Scanning the input string abc with an nfa from state (a) · (bca). We need to show the above definition of δ ∗ is
0: consistent.
Lemma. Suppose uv = st, where u, v , s, t ∈ Σ∗ . For every
state q, we have δ ∗ (q, uv ) = δ ∗ (q, st). That is,
[ [
{δ ∗ (p, v ) | p ∈ δ ∗ (q, u)} = {δ ∗ (p, t) | p ∈ δ ∗ (q, s)}

Proof. ????? 2
This lemma justifies the definition of δ ∗ .
chap2-fa February 15, 2024 37 chap2-fa February 15, 2024 38 chap2-fa February 15, 2024 39
Next we study how long a path labelled with w could be. Nondeterminism
If there is no λ transition edge in the transition graph, the
length of the path is exactly |w|.
Now suppose there are k λ-edges in the transition graph. Definition. The language accepted by an nfa M is
If there is a path labelled with w, then there must be a defined as follows:
path labelled with w that contains at most k + (1 + k)|w|
L(M) =def {w ∈ Σ∗ | δ ∗ (q0 , w) ∩ F ̸= ∅}
edges.
Solution. Intuitively, we will avoid λ circles. The Example. The language accepted by the nfa in figure 2.9 Consider the nfa in Figure 2.8. It accepts aaa by following
first k denotes k λ-edges before the first input is {(10)n | n ≥ 0}. the upper path and accepts aaaa by following the lower
symbol is consumed. (Each λ-edge is traversed Note that, in an nfa, the automaton may stop before path. Suppose the input is aaa. Upon seeing the first a,
at most once.) Then for every symbol, there could scanning all the input symbols (since δ may end up as an the nfa needs to decide whether it should take the upper
be a path of 1 + k edges for that symbol. There empty set). We say such a situation as a dead path or the lower path. There is not any information that
are |w| input symbols. Then the total length is at configuration. the nfa may make use of. The only useful hint is for it to
most k + (1 + k)|w|. 2 look ahead a few more input symbols.
Based on this observation, when computing δ ∗ (q, w), we Nondeterminism allows us to have the good luck of
need to consider only paths of lengths at most always choosing the right path without worrying about the
k + (1 + k)|w|. tedious operation of look-ahead.

chap2-fa February 15, 2024 40 chap2-fa February 15, 2024 41 chap2-fa February 15, 2024
Why nondeterminism? If the first alternative leads to failure, we will undo what 42
A nondeterministic automaton seems more difficult to we did and try the second alternative in a similar way.
understand. On the other hand, digital computers are This is called a trial-and-error approach (also known as
Remember we define that a nondeterministic automaton always deterministic—their states, though complicated, back-tracking).
accepts a string if it is possible for the automaton to reach are always predictable from the initial states and their A nondeterministic algorithm hides the tedious
an accepting state when that string is the input. input. trial-and-error work and serves as a simplified
This definition endows the magic power to a computational model. Nondeterminism simplifies (and
nondeterministic automaton in that it can always choose a Why do we want to introduce nondeterminism into automata? hence clarifies) the algorithm of a difficult problem.
good transition (that is, a transition that leads to an The solution to a problem consists of two parts:
The class of deterministic automata is a subset of the • [outer layer] the algorithm (that is, the method)
accepting state) when facing multiple next moves. Though
class of nondeterministic automata. Hence, • [core] the implementation of the algorithm, e.g.,
we do not know how the nondeterministic automaton
nondeterministic automata should be at least as powerful backtracking
makes a clever choice, we may assume that it is always
as deterministic ones.
immensely clever and knows where it should go. Assume the machine (cpu) is endowed with the power of
Will nfas be more powerful (in what sense)? nondeterminism. The algorithm for a problem can be
Many deterministic algorithms requires that one makes a formulated easier to understand. But later we will face the
choice at some stage. Consider a game-playing program. problem of implementing a nondeterministic algorithm on
Though we can always find a best move, frequently, the a deterministic machine by trial-and-error.
best move can be only found by exhaustive search. When From this point of view, nondeterminism is a primitive, or a
several alternatives are possible, we pick the first one and weapon, that we can use to attack problems. However, we
chap2-fa February 15, 2024
In this way, solving a problem consists in two stages: 43 follow it until it is clear whether
chap2-fa February 15,we
2024will win the game. 44 postpone the task of building
chap2-fa the2024
February 15, weapon until later. 45

• find an algorithm (assuming we have the power of Similarly, nondeterminism is an effective mechanism for
nondeterminism) describing some complicated language concisely.1
• implement the nondeterminism (with trial-and-error) nfa vs. dfa. Finally, nondeterminism is useful for a technical reason.
and the algorithm Certain results are easier to establish for nfa’s than for
Nondeterminism is an abstraction, similar to the dfa’s. Nondeterminism usually simplifies the arguments.
for-loops in C. Nondeterminism is not unique to finite automata. We may
In terms of finite automata, we will find that designing a introduce nondeterminism into grammars and
nondeterministic automaton is usually easier than programming languages. If possible, we even want to
designing an equivalent deterministic one. introduce nondeterminism into hardware.
Nondeterminism allows us a simpler automaton (i.e., an Note that nondeterminism is different from probabilistic
algorithm). algorithms in that probabilistic algorithms do not
Ex. nfa and dfa for the language {awa | w ∈ {a, b}∗ }. guarantee a correct answer. A common probabilistic
algorithm is for integer factoring.

1
The keyword is concisely. Without nondeterminism we can still
describe the same language, but in a more awkward way. For
example, C is more concise than the assembly language.
chap2-fa February 15, 2024 46 chap2-fa February 15, 2024 47 chap2-fa February 15, 2024 48
Definition. Two accepters, M1 and M2 , are equivalent if
§2.3 nfa = dfa and only if L(M1 ) = L(M2 ).
Though nfa is equipped with the powerful Example. Two equivalent accepters, for the same
Summary
nondeterminism, surprisingly, nondeterminism did not language {(10)n | n ≥ 0}.
GOOD: non-determinism = hiding back-tracking bring extra recognition power. That is, a langauge that can
be recognized by an nfa can also be recognized by a dfa.
BAD: non-determinism = hidden back-tracking For finite automata, nondeterminism only brings in the
convenience of modelling.
good: simpler notation.
For the same language, there could be many accepters.
bad: heavy overhead.
The following two automata accept the same language
{a(ba)∗ }. Note that a dfa is a special kind of an nfa, one without
From the definition of nondeterminism, we may always λ-transitions nor multiple choices. Thus, every language
assume that a (deterministic or nondeterministic) fa has a definable by a dfa can be defined by an nfa.
unique initial state and a unique accepting state.
Here we want to show that every language definable by
an nfa can be defined by a dfa. We do this by constructing
a dfa that is equivalent to a given nfa.

chap2-fa February 15, 2024 49 chap2-fa February 15, 2024 50 chap2-fa February 15, 2024 51
Example. Consider the nfa on the left of Figure 2.12.
Since an nfa is nondeterministic, it could be in one of After reading the string aa, the nfa could be in one of the
The main idea behind the construction several possible states after reading a string w. This set, states {1, 2}. Hence we have a state denoted as {1, 2}.
Each new state in the constructed dfa is a subset of the called sw , of possible states could be precisely computed. Similarly, after reading the string aaa, the nfa could be in
states in the original nfa. We may similarly compute swa , the set of possible states one of the states {1, 2}. There will be a transition from
after reading the string wa. {1, 2} to {1, 2}, labelled with a.
Hence, there will be a transition from sw to swa labelled Similarly, after reading the string aab, the nfa could be in
with a. one of the states in {0}. There will be a transition from
{1, 2} to {0}, labelled with b.
In this way, we can gradually construct a dfa, shown in the
right of Figure 2.12. The starting state sλ is {0}. The state
In this way, we may derive more and more states and labelled with an empty set means a trap state.
more and more transitions.
Furthermore, since an nfa has only a finite number of
states, there are only a finite number of sets of states.
The starting state would be sλ .

chap2-fa February 15, 2024


First we define a closure operation. Let s be a set of 52 scan-abc.png
chap2-fa February 15, 2024 53 chap2-fa February 15, 2024 54

states. closure(s) is the set of states that are reachable Example of a Construction. Consider the nfa in Figure
from a state in s by some λ-transitions. Formally, 2.14. Note there is no λ-transition. The starting state is 0.
closure({0}) = {0}. From {0} on input a, we may reach
closure(s) =def {y | x ∈ s, x →λ∗ y}
one of {0, 1}. From {0} on input b, we may reach one of
We can prove the following lemma. {1}. From {0, 1} on input a, we may reach one of
Lemma. closure(closure(s)) = closure(s). {0, 1, 2}. From {0, 1} on input b, we may reach one of
Second we define the target of a transition from a set s of {1, 2}. From {1} on input a, we may reach one of {2}.
states on a symbol a as follows: From {1} on input b, we may reach one of {2}. From
{0, 1, 2} on input a, we may reach one of {0, 1, 2}. From
{0, 1, 2} on input b, we may reach one of {1, 2}. From
transa (s) = closure({y | x ∈ closure(s), x →a y})
{1, 2} on input a, we may reach one of {2}. From {1, 2}
Let q0 be the initial state of the nfa. We first compute on input b, we may reach one of {2}. From {2} on input
closure({q0 }), which will serve as the initial state of the a, we may reach one of {}. From {2} on input b, we may
constructed dfa. reach one of {2}. State {0} is the initial state and states
{1}, {0, 1}, {1, 2}, and {0, 1, 2} are accepting states.
From a state s of the dfa, we add a new state transa (s)
(and a new transition s →a transa (s)) for every a ∈ Σ.
chap2-fa February 15, 2024 55 chap2-fa February 15, 2024 56 chap2-fa February 15, 2024 57

Example. Convert an NFA to a DFA.


Example.
Given an nfa MN , use the above method to construct a
dfa, MD .

MN → MD
Every state of MD has exactly |Σ| outgoing edges, one for
each symbol in Σ.
A state s of MD is designated as an accepting state if and
only if s contains an accepting state of MN .

chap2-fa February 15, 2024 58 chap2-fa February 15, 2024


Theorem. MN and MD are equivalent. That is, We can use the transformation method to determine if 59 chap2-fa February 15, 2024 60

L(MN ) = L(MD ). two regular languages have common sentences. That is,
Proof. Suppose string w is accepted by nfa MN . their intersection is not empty.
Example. Here are three equivalent finite automata.
There is a path from the initial state q0 to an ac- Draw the nfa’s for the two given regular languages. Add a
cepting state, say p. Then there is a correspond- new initial state which has λ-transitions to the initial states
ing path from the initial state closure({q0 }) to a of the two nfa’s. This results in a combined nfa. Then
state that contains p, which is an accepting state transform the combined nfa into a dfa. If there is a state in
in MD . the resulting dfa that contains accepting states of both
Conversely, Suppose string w is accepted by nfa’s, then the two given regular languages have common
dfa MD . There is a path from the initial state sentences, and vice versa.
Example. Consider the combined nfa shown below, in Figure 9: Equivalent finite automata.
closure({q0 }) to a state that contains an accept-
ing state, say p. Then there is a corresponding which the top part is for the regular language ab∗ a and
path from the initial state q0 to p in MN . the bottom part is for abab∗ . In the equivalent dfa, there is Question. How to determine if two fa’s accept the same
A more detailed proof makes use of mathematical an accepting state {3, 7}, which contains the accepting language?
induction on the lengths of the paths. 2 states for both regular languages. This means that there
are sentences common to both regular languages.
In Figure 2-14 and 2-15, consider the path
0 → 0 → 0 → 1.

chap2-fa February 15, 2024 61 chap2-fa February 15, 2024 62 chap2-fa February 15, 2024 63
§2.4 Reducing the number of states
Many dfa’s accept the same language.
Example. The two dfa’s in Figure 2.17 are equivalent.
Note that state 5 is really useless. Note that states 1 and 2 are indistinguishable though Example. All trap states can be collapsed into a single
their regular expressions are quite different: state.

L(M, state 1) = b(a|b)∗ |aa∗ b(a|b)∗

L(M, state 2) = a∗ b(a|b)∗


Usually dfa’s with fewer states are easier to understand
and implement as a computer program. So we prefer the
smallest dfa among all equivalent dfa’s.
chap2-fa February 15, 2024 64 chap2-fa February 15, 2024 65 chap2-fa February 15, 2024 66
Definition. Two states p and q of a dfa are To find a minimal dfa that is equivalent to a given dfa, we
indistinguishable if and only if may combine indistinguishable states.
1. Initially, partition all the states into two groups: one
Now we may relax the strict definition of a dfa. Given a δ ∗ (p, w) ∈ F implies δ ∗ (q, w) ∈ F containing all and only the accepting states, the other
dfa M, there are some accepting states. If p is the initial containing the remaining states. The two groups are
state, the dfa will accept a language, denoted as L(M, p). and distinguished by λ.
Similarly, if q is the initial state, the dfa will accept another δ ∗ (p, w) ̸∈ F implies δ ∗ (q, w) ̸∈ F 2. repeat
language, denoted as L(M, q). When different states are for all w ∈ Σ∗ . If, on the other hand, there exists w ∈ Σ∗ 3. for every group G do
denoted as initial states, M will accept different such that 4. for every input symbol a ∈ Σ do
languages. These languages, such as L(M, p), L(M, q), δ ∗ (p, w) ∈ F and δ ∗ (q, w) ̸∈ F 5. Partition G into several subgroups as follows:
etc., may or may not be identical. In the special case that 6. two states p, q are in the same subgroup only if
or vice versa, then p and q are said to be distinguishable δ(p, a) and δ(q, a) are in the same group.
L(M, p) = L(M, q), we will say the two states p and q are
by the string w. 7. end for
indistinguishable states.
This definition is valid in that two states are either 8. end for
distinguishable or indistinguishable, but not both. 9. until no more group can be partitioned.
Furthermore, the property of being indistinguishable is an States in the same group means that they will accept
equivalence relation (that is, reflexive, symmetric, and exactly the same set of input strings, that is, they are
transitive). indistinguishable.

chap2-fa February 15, 2024 67 chap2-fa February 15, 2024 68 chap2-fa February 15, 2024 69

Example. Figure 10 shows a partitioning procedure.


Example. Figure 2-17 shows a partitioning procedure. Answer. Answer to the above problem.
Example. Figure 2-18 shows a partitioning procedure.

Figure 11: The minimized dfa for the previous page.

Figure 10: A dfa for minimization.

chap2-fa February 15, 2024 70 chap2-fa


Theorem 2.3. The above procedure, applied to a dfa Repeated applicationsFebruary
of the15,partitioning
2024
algorithm is of71 chap2-fa February 15, 2024
Corollary 2.5. All equivalent dfa’s with the least number72
M =def {Q, Σ, δ, q0 , F }, terminates and determines all no use: of states are isomorphic.
pairs of indistinguishable states. M2 = M3 = . . . Proof. Combine the two equivalent minimum dfa’s
Proof. Since there are only a finite number of M1 and M2 . Add a new initial state q0 and two λ-
states in Q, partitioning must terminate. Assume transitions from q0 to the respective initial states
that the partitioning procedure terminates after k of the two given dfa’s. Call the resulting nfa N.
iterations of the repeat loop. We may use mathe- Then perform subset construction and minimiza-
Figure 12: A sequence of partitionings.
matical induction on k to show two things: tion.
• For two distinguishable states p and q, they Lemma 2.4. The partitioning algorithm produces an Call the resulting dfa of subset construction D1 .
cannot belong to the same group after equivalent dfa with the fewest states. During subset construction, exactly one state of
partitioning. Proof strategy. M1 and exactly one state of M2 will form a subset
• For two indistinguishable states p and q, since M1 and M2 are deterministic.
they must belong to the same group after Call the resulting dfa of minimization D. In D, a
partitioning. state in M1 can be combined with exactly with one
state in M2 otherwise either (1) D is not minimum
Based on the two results, we may assert that the
or (2) at least one of M1 and M2 is not minimum.
dfa obtained by the above procedure is minimal.
Either case leads to a contradiction. 2
2
We can use this corollary to determine if two finite
chap2-fa February 15, 2024 73 chap2-fa
A more detailed proof.February 15, 2024 74 chap2-fa
(Discussion of states)February
Let α 15,
and 2024
β be two states of N1 . 75
Definition. The parallel composition of M1 and M2 , We may write α = {s1 , s2 } and β = {t1 , t2 }, where s1 and
denoted as paracomp(M1 , M2 ), is the nfa shown in Figure t1 are states of M1 and s2 and t2 are states of M2 . (Note
13. that α and β may contain the initial state or accepting
Definition. Let M be a fa (dfa or nfa). The notation |M| state of paracomp(M1 , M2 ) but we may ignore them in this
means the numbers of states in M. proof.)
Definition. Let M be an fa. The notation subset(M) We claim that there cannot be two states α and β of N1 so
denotes the dfa obtained with the standard subset that α ∩ β ̸= ∅.
construction algorithm applied to M. Assume that there are be two states α and β of N1 so that
Lemma. If M is a dfa, subset(M) is exactly M. α ∩ β ̸= ∅.
Definition. Let M be a dfa. The notation minimize(M) If s1 = t1 then s2 ̸= t2 (otherwise α = β). If s1 = t1 , due to
denotes the dfa obtained with the standard minimization the subset construction, s1 , s2 and t2 are indistinguishable.
algorithm applied to M. This is a contradiction because M2 is assumed to be a
Assume M1 and M2 are equivalent minimum dfa’s for the minimum dfa, hence s2 and t2 cannot be
same regular language L. We want to prove that M1 and indistinguishable..
M2 are isomorphic. (Discussion of transitions) Furthermore, for any two states
Figure 13: Parallel composition of M1 and M2 is an nfa.
Let N1 denotes subset(paracomp(M1 , M2 )), which is a dfa. α = {s1 , s2 } and β = {t1 , t2 } of N1 , where s1 and t1 are
Due to the subset construction, every state of N1 contains states of M1 and s2 and t2 are states of M2 , there is an
exactly one state of M1 and one state of M2 . This is due to edge α →a β if and only there is an edge s1 →a t1 if and
chap2-fa February 15, 2024 76 the fact that both M1 andM
chap2-fa 2 are
February deterministic.
15, 2024 77 only there is an
chap2-fa
Finite-State Transducers →a t215,
edge s2February . 2024 78
We now conclude that N 1 , M1 and M2 are isomorphic.
Some finite automata are not just recognizers. They could
Becauseoutput,
N1 is a usually
minimum 1 ). 2
produce as dfa, so isover
a string minimize(N
some output
alphabet. Consider the following informal specification of
a program:
Additional Issues. An input is a string of only the symbols a and #.
Each state of a dfa accepts a language. The collection of The program should transform #a into A and ##
all languages for all the states forms a partition of Σ∗ . into @. The string ### signifies the end of the
(This is different from the notion of indistinguishable input. All other a’s should be left unchanged.
states. We attempt to use different states as the
accepting states.) Figure 14: Though the two dfa’s are equivalent, the right dfa is We can use the automaton in Figure 15 to restate this
more distinguishing. The left dfa is smaller and better if we do specification:
not want to distinguish the three states p, q, and r . Note state s
accepts the empty string.

Figure 15: A transducer.

Here the notation a/A means that a is the input and A is


chap2-fa
Example. An integer is February 15, 2024 79
represented as a string of 0’s and chap2-fa
More Examples. February 15, 2024 80 the output.
chap2-fa February 15, 2024 81

1’s in a computer. For instance, 12 is represented 01100. A finite automaton that produces output is called a finite
A negative number, such as -9, is the complement plus 1. state
L =deftransducer (FT). Formally,
For instance, -12 is represented as 10100. We can use a M =| def
{w w∈ (Q, Σ, δ, q0 , F , O, η), where O is the finite output
transducer for the translation. {a, b}∗ , w does
vocabulary and notη (eta) is thethree
contain output function a’s or b’s}.
consecutive
There is an easy translation. We scan the input from right η : Q × Σ → O∗.
to left (that is, from LSB to MSB). Digits are copied We may extend η in a natural way: η ∗ (q, λ) =def λ and
directly to the output up to (and including) the first 1. From η ∗ (q, xi) =def η ∗ (q, x) · η(δ(q, x), i).
Figure 17: An automaton.
this point on, every digit is copied in complemented form. A transducer is a translator that translate a sentence
Figure 16 is the automaton. written in the input vocabulary into a sentence in the
output vocabulary.
Definition. Let T be an FT. Define the translation
associated to T as Figure
 ∗ 20: An automaton.
Figure 18: An automaton. η (q0 , x) if δ ∗ (q0 , x) ∈ F
ηT (x) =def
undefined
How about the complement of L (i.e., otherwise
L̄)?
Prove that the following two regular languages are
equivalent:
Figure 16: An automaton for 2’s complement.
{bn xam | n > 1, m > 1, x ∈ {a, b}∗ }

chap2-fa February 15, 2024 82 chap2-fa February 15, 2024 83 chap2-fa February 15, 2024 84
A finite state machine in CPU design is shown below.
Homework (4th week).
Lemma. Let M =def (Q, Σ, δ, q0 , F ) be an fa (nfa or dfa)
and let n =def |Q|. The regular language accepted by M is
non-empty if and only if it accepts a string of length at
most n − 1.
Lemma. Let M =def (Q, Σ, δ, q0 , F ) be an fa (nfa or dfa)
and let n =def |Q|. The regular language accepted by M is
infinite if and only if it accepts a string w with
n ≤ |w| < 2n.
Lemma. (WRONG) If R is an equivalence relation, so is
the complement of R.
Lemma. If L is a regular language, so is the complement
of L.

chap2-fa February 15, 2024 85 chap2-fa February 15, 2024 86 chap2-fa February 15, 2024 87

Chapter review.
1 Deterministic Finite Accepters Example We use an example to show that the following
2 Nondeterministic Finite Accepters Appendix The minimal dfa of a regular language is language has an nfa (assuming L1 and L2 are regular, ⊗
3 Equivalence of Deterministic and Nondeterministic unique. is the bitwise exclusive-or operator)
Finite Accepters See the file “unique-mdfa.pdf”.
{w1 ⊗ w2 | w1 ∈ L1 , w2 ∈ L1 , |w1 | = |w2 |}
4 Reduction of the Numbers of States in Finite
Automata
5 Finite State Transducers

chap2-fa
Example We define a February 15, 2024
new operator ⋄ between two 88 chap2-fa February 15, 2024 89 chap2-fa February 15, 2024 90

strings: x ⋄ y is the set of strings obtained from randomly


inserting substrings of y into arbitrary positions in x but
these substrings must preserve their order in y. For
example abc ⋄ de =
{abcde, abdec, adebc, deabc, adbec, dabec, daebc, dabec, . . .}. Example. (Shuffle) We define a new operator on two
⋄ may be defined as follows: strings: x ▷ y =def x1 y1 x2 y2 x3 y4 . . . xk yk . . .. If x and y have
(1) x ⋄ λ = λ ⋄ x = {x} different lengths, whatever is left is appended to the end
(2) ax ⋄ by = {a} · (x ⋄ by) ∪ {b} · (ax ⋄ y ); of their shuffle. We may define the shuffle of two
Here are some properties: (1) x ⋄ y = y ⋄ x. (2) languages: L1 ▷ L2 =def {x ▷ y | x ∈ L1 , y ∈ L2 }.
|x ⋄ y | = |x| + |y|. Obviously, x ▷ y ̸= y ▷ x. x ▷ λ = x = λ ▷ x.
Assume L1 and L2 are regular languages whose fa’s are Assume both L1 and L2 are regular languages. What is
shown on the next page. Define L1 ⋄ L2 as follows: the fa for L1 ▷ L2 ?
[
L1 ⋄ L2 = def {x ⋄ y | x ∈ L1 , y ∈ L2 }

Is L1 ⋄ L2 regular?
S If so, find its finite automaton.
Notation. {a, b, c, d} means a ∪ b ∪ c ∪ d.
chap2-fa February 15, 2024 91 chap2-fa February 15, 2024 92 chap2-fa February 15, 2024 93

The fa’s for L1 and L2 .

chap2-fa February 15, 2024 94 chap2-fa February 15, 2024 95 chap2-fa February 15, 2024 96

chap2-fa February 15, 2024 97


(A sample research on finite-state machines) A
(finite-state deterministic) automaton is synchronizing if
there is a sequence of transitions which brings the
automaton to a fixed state from an arbitrary starting point;
in other words, the monoid generated by the transitions of
the automaton contains a constant function. Such a
sequence is called a reset word. The celebrated
conjecture asserts that if an n-state automaton has a
reset word, then it has one of length at most ???. An
approach to this conjecture (not so far successful!),
suggested by Ben Steinberg and ???, brings together
automata theory, permutation groups, representation
theory, graph homomorphisms, extremal combinatorics,
and finite geometry. The course will introduce the various
topics mentioned above and explain some of their
connections. An outline follows. (Prof. Peter J. Cameron,
Queen Mary, University of London)
Automata: Synchronization, the conjecture, the
road-colouring conjecture and its proof, applications to

You might also like