Title: Finite-State Machines with No Output
1Finite-State Machines with No Output
2Outline
- Introduction
- Set of strings
- Concatenation, Kleene Closure
- Finite-State Automata
- Definition, Example
- Extended Transition Function
- Language Recognized by FA
- Nondeterministic FA
- Definition, Example, FA-NFA Equivalence
- Exercise 10.3
3Introduction
- Language recognition
- Use final states instead of output
- A string is recognized if it takes start state to
a final state.
4Set of strings - Concatenation
- Definition. Let A and B be subsets of V, where V
is a vocabulary. - The concatenation of A and B, denoted by AB, is
the set of all strings xy x?A ? y?B. - Example. Let A0, 11, B1, 10, 110.
- AB01, 010, 0110, 111, 1110, 11110
- BA10, 111, 100, 1011, 1100, 11011
- An is recursively defined by
- A0?
- An1AnA for n0, 1, 2,
5Kleene Closure
- Definition. Let A be a subset of V.
- The Kleene closure of A, denoted by A, is the
set consisting of concatenations of arbitrarily
many strings from A. - A ??k0 Ak
- Examples.
- Let A0. A ?, 0, 00, 000, 0n
n0,1,2. - Let B0,1. B0,1 is the set of all strings
of 0s and 1s, including ?. - Let C11. C 12n n0,1,2.
6Finite-State Automata
- Definition. A finite-state automaton
M(S,I,f,s0,F) consists of - a finite set S of states, with an initial (or
start) state s0, - a finite input alphabet I,
- a transition function f S?I ? S, which assigns
a next state to every pair of state and input
symbol, and - a subset F of S consisting of final (or
accepting) states. - FAs can be represented by
- state table, or
- state diagram final states indicated by double
circles.
7Example - FA
M(S,I,f,s0,F) with Ss0,s1,s2,s3 I0,1
Fs0,s3 Input and state table and diagram
State 0 1
s0 s0 s1
s1 s0 s2
s2 s0 s0
s3 s2 s1
s1
0
1
1
Start
0
s0
s3
1
0
0,1
s2
- Strings accepted by FA M? ?, 0, 00, 10, 000,
010, 100, 110,
8Extended Transition Function
- The transition function f can be extended
- f S?I ? S
- f assigns a next state to every pair of state and
a string of symbols. - If s is a state in S and x is a string from I,
then f(s, x) is the state obtained by using each
successive symbol of x, from left to right, as
input starting with state s.
9Language Recognized by FA
- Definition. A string x is said to be recognized
(or accepted) by the FA M(S,I,f,s0,F) if it
takes the initial state s0 to a final state, that
is, f(s0,x)?F. - The language recognized or accepted by the
machine M, denoted by L(M), is the set of all
strings that are recognized by M. - Two FSAs M1, M2 are equivalent if L(M1)L(M2).
10Language of FA - Example
- Consider the FA M(S, I, f , s0, F), with
- Ss0, s1, s2, I0, 1, Fs2, and
- the following state diagram
1
0
1
0
s0
s1
s2
Start
1
0
- Strings accepted by FA M? 10, 010, 110, 0110,
- What is the language accepted by the FA M?
- Set of all strings of 0s and 1s that end with 10.
11Nondeterministic Finite-State Automata
- All FAs discussed so far are deterministic
- A unique next state is assigned to every pair of
state and input symbol by the transition function
f S?I ? S. - The above constraint can be relaxed
- Nondeterministic finite-state automata NFA
- Zero or many possible next states are assigned to
every pair of state and input symbol by the
transition function f S?I ? 2S.
12NFA - Definition
- Definition. A nondeterministic finite-state
automaton M(S,I,f,s0,F) consists of - a finite set S of states, with an initial state
s0, - a finite input alphabet I,
- a transition function f S?I ? 2S, which assigns
a set of states (possibly empty) to every pair of
state and input symbol, and - a subset F of S consisting of final states.
- Starting with s0, on an input string x, an NFA
may have multiple transition paths, can be in
more than one state, and may get stuck. - x is accepted if at least one of the transition
paths normally ends in a final state.
13Example - NFA
- Consider the NFA M(S, I, f , s0, F), with
- Ss0, s1, s2, I0, 1, Fs2, and
- Input the following state table.
- Its state diagram is
State 0 1
s0 s0 s0, s1
s1 s2 -
s2 - -
Start
14Example cont.
- Processing input string 11010
1
1
0
1
0
s0
s0
s0
s0
s0
s0
start
s1
s2
accept
s2
s1
stuck
s1
stuck
- What is the language accepted by the NFA M?
- The set of all strings of 1s and 0s that end
with 10.
15Another Example
- Find an NFA that accepts the set of strings of
0s and 1s which contain at least one 0. - Such an NFA is M(S, I, f , s0, F), with
- Ss0, s1, I0, 1, Fs1, and
- the following state diagram
Start
16NFA-FA Equivalence
- Theorem. If a language L is recognized by a
nondeterministic NFA M0, then L is also
recognized by a deterministic FA M1. - Proof idea How would an FA simulate an NFA?
- It needs to keep track of all transition paths
by remembering all active states at a given point
in the input as NFA operates. - If the NFA has n states, there are 2n subsets of
states that need to be considered.
17Construction of Equiv. FA
- For NFA M0(S0, I, f0 , s0, F0), lets construct
an FA M1(S1, I, f1, s1, F1), where - Each state in M1 corresponds to a set of states
of M0 - The initial state of M1 is s1s0, (s0 initial
state of M0) - The input alphabet I of M1 is the same as that of
M0 - The transition function f1 of M1 is defined as
- f1(si1, si2, , sik, x) f0(si1, x) ? f0(si2,
x) ? ? f0(sik, x) - The states of M1 are subsets of S0 reachable from
s0 - The final states of M1 are those sets that
contain at least one final state of M0.
18Construction of Equiv. FA
- For NFA M0(S0, I, f0 , s0, F0), lets construct
an FA M1(S1, I, f1, s1, F1), where - The set of states of M1 is S1 ? 2S0
- The initial state of M1 is s1 s0
- The input alphabet I of M1 is the same as that of
M0 - The transition function f1 of M1 is defined as
- ?s?S1?a?I f1(s, a) ?p?s f0(p, a)
- union of the sets f0(p, a) for each p in s
(subset of S0) - The states of M1 are subsets of S0 reachable from
s0 - The set of final states of M1 is F1 s ? S1
s?F0 ? ? - s ? S1 s contains a final state of M0.
19Proof
- To prove that FA M1 accepts the same language as
NFA M0, we will prove that?x?I
f1(s1,x)f(s0,x). - Basis step f1(s1, ?) s1 s0 f0(s0, ?)
- Induction hypothesis f1(s1, x) f0(s0, x)
- Statement to be shown ?a?I f1(s1, xa) f0(s0,
xa) - f1(s1, xa) f1(f1(s1, x), a) by def. of f1 for
FA - f1(f0(s0, x), a) by induction
hypothesis - ?p? f0(s0, x) f0(p, a) by def.
of f1 for equiv. FA - f0(s0, xa) by def. of f0 for
NFA
20Equivalent FA of NFA - Example
- Consider the NFA M0(S0, I, f0 , s0, F0), where
- S0s0, s1, s2, I0, 1, F0s2,
Start
- Construct the equivalent FA M1(S1, I, f1 , s1,
F1)
21Example Solution
- S1 ? 2S0 ?,s0,s1,s2,s0,s1,s0,s2,s1,s
2,s0,s1,s2. - The initial state is s1s0.
- The input alphabet is I 0, 1.
- The transition function f1 is defined as
- f1(?, 0) ? f1(?, 1) ?
- f1(s0,0) s0 f1(s0,1) s0 , s1
- f1(s1,0) s2 f1(s1,1) ?
- f1(s2,0) ? f1(s2,1) ?
- f1(s0,s1,0) s0, s2 f1(s0,s1,1) s0, s1
- f1(s0,s2,0) s0 f1(s0,s2,1) s0, s1
- f1(s1,s2,0) s2 f1(s0,s1,1) ?
- f1(s0,s1,s2,0) s0, s2 f1(s0,s1,s2,1)
s0, s1
22Example - State Table
State 0 1
? ? ?
s0 s0 s0, s1
s1 s2 ?
s2 ? ?
s0, s1 s0, s2 s0, s1
s0, s2 s0 s0, s1
s1, s2 s2 ?
s0, s1, s2 s0, s2 s0, s1
23Example State Diagram
s0,s1,s2
1
1
0
0
0
Start
1
s0
s0,s1
s0,s2
0,1
1
1
0
?
s1,s2
1
0,1
s1
s2
0
0
24Example cont.
- The set of states of M1 is S1s0,s0,s1,s0,s
2 - The initial state s1s0.
- The input alphabet is I 0, 1.
- The set of final states is F1s0,s2.
25Exercise 10.3