Presentation is loading. Please wait.

Presentation is loading. Please wait.

Finite-State Machines with No Output

Similar presentations


Presentation on theme: "Finite-State Machines with No Output"— Presentation transcript:

1 Finite-State Machines with No Output
MSU CSE 260

2 Outline Introduction Set of strings Finite-State Automata
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

3 Introduction Language recognition Use final states instead of output
A string is recognized if it takes start state to a final state.

4 Set 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 A={0, 11}, B={1, 10, 110}. AB={01, 010, 0110, 111, 1110, 11110} BA={10, 111, 100, 1011, 1100, 11011} An is recursively defined by: A0={} An+1=AnA for n=0, 1, 2, …

5 Kleene 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* = k=0 Ak Examples. Let A={0}. A* = {, 0, 00, 000,…} = {0n | n=0,1,2…}. Let B={0,1}. B*={0,1}* is the set of all strings of 0s and 1s, including . Let C={11}. C* = {12n | n=0,1,2…}.

6 Finite-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.

7 Example - FA M=(S,I,f,s0,F) with S={s0,s1,s2,s3} I={0,1} F={s0,s3}
Input and state table and diagram: State 1 s0 s1 s2 s3 s1 1 1 Start s0 s3 1 The NFA is easier to build and understand than the equivalent FA. 0,1 s2 Strings accepted by FA M? , 0, 00, 10, 000, 010, 100, 110, …

8 Extended 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.

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

10 Language of FA - Example
Consider the FA M=(S, I, f , s0, F), with S={s0, s1, s2}, I={0, 1}, F={s2}, and the following state diagram: 1 1 Start s0 s1 s2 The NFA is easier to build and understand than the equivalent FA. 1 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.

11 Nondeterministic 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.

12 NFA - 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.

13 Example - NFA Consider the NFA M=(S, I, f , s0, F), with
S={s0, s1, s2}, I={0, 1}, F={s2}, and Input the following state table. Its state diagram is: State 1 s0 s0, s1 s1 s2 - 0,1 1 s0 s1 s2 Start The NFA is easier to build and understand than the equivalent FA.

14 Example – cont. What is the language accepted by the NFA M?
Processing input string: 11010 1 1 1 start s0 s0 s0 s0 s0 s0 s1 s2 accept s1 s2 stuck s1 stuck After processing the first symbol (1) of the input string, the NFA is in two active states: q0 and q1. What is the language accepted by the NFA M? The set of all strings of 1s and 0s that end with 10.

15 Another 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 S={s0, s1}, I={0, 1}, F={s1}, and the following state diagram: The NFA is easier to build and understand than the equivalent FA. 0,1 s0 s1 Start

16 NFA-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.

17 Construction of Equiv. FA
For NFA M0=(S0, I, f0 , s0, F0), let’s 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 s1={s0}, (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.

18 Construction of Equiv. FA
For NFA M0=(S0, I, f0 , s0, F0), let’s 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}.

19 Proof 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

20 Equivalent FA of NFA - Example
Consider the NFA M0=(S0, I, f0 , s0, F0), where: S0={s0, s1, s2}, I={0, 1}, F0={s2}, 0,1 1 s0 s1 s2 Start The NFA is easier to build and understand than the equivalent FA. Construct the equivalent FA M1=(S1, I, f1 , s1, F1)

21 Example – Solution S1  2S0 = {,{s0},{s1},{s2},{s0,s1},{s0,s2},{s1,s2},{s0,s1,s2}}. The initial state is s1={s0}. 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} States of Q1 can be labeled as subsets of Q.

22 Example - State Table State 1  {s0} {s0, s1} {s1} {s2} {s0, s2}
1 {s0} {s0, s1} {s1} {s2} {s0, s2} {s1, s2} {s0, s1, s2}

23 Example – State Diagram
{s0,s1,s2} 1 1 Start 1 {s0} {s0,s1} {s0,s2} 0,1 1 1 {s1,s2} 1 0,1 {s1} {s2}

24 Example – cont. The set of states of M1 is S1={{s0},{s0,s1},{s0,s2}};
The initial state s1={s0}. The input alphabet is I = {0, 1}. The set of final states is F1={{s0,s2}}. 1 {s0} {s0,s1} {s0,s2} Start The NFA is easier to build and understand than the equivalent FA.

25 Exercise 10.3


Download ppt "Finite-State Machines with No Output"

Similar presentations


Ads by Google