Chap2-Fa 9
Chap2-Fa 9
©February 15, 2024 by Wuu Yang. All rights reserved. Figure 1: A first automaton (machine)
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
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.
chap2-fa February 15, 2024 34 chap2-fa February 15, 2024 35 chap2-fa February 15, 2024 36
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λ .
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
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 .
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.
chap2-fa February 15, 2024 67 chap2-fa February 15, 2024 68 chap2-fa February 15, 2024 69
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
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
chap2-fa February 15, 2024 94 chap2-fa February 15, 2024 95 chap2-fa February 15, 2024 96