INFO 2950 Prof Carla Gomes gomescs cornell edu
























































- Slides: 56
INFO 2950 Prof. Carla Gomes gomes@cs. cornell. edu Module Modeling Computation: Finite State Machines without Output Rosen, Chapter 12. 2 and 12. 3 1
Finite-State Machines with No Output
Definition: Concatenation of A and B are subsets of V*, where V is a vocabulary The concatenation of A and B is AB={xy: x string in A and y string in B} Example: A={0, 11} and B={1, 10, 110} AB={01, 010, 0110, 1110, 11110} What is BA? A 0={λ} An+1=An. A for n=0, 1, 2, …
Definition: Concatenation of A and B Example: A={1, 00} An ? n=1, 2, 3, … A 0={λ} A 1=A 0 A 1={λ} A ? A 1=A 0 A 1={λ} A={1, 00} A 2=A 1 A ={1, 00} = {11, 100, 001, 0000} A 3=A 2 A ={11, 100, 001, 0000}{1, 00} = {111, 1100, 1001, 10000, 001111, 00100, 00001, 000000}
Kleene Closure Let A be any subset of V*. Kleene closure of A, denoted by A*, is The set consisting of concatenations of arbitrarily many strings from A If B={0, 1}, B*=V*.
Kleene Closure What are the Kleen closures of the set A={0}; B={0, 1}, and C={11}? A*={ , 0, 000, …} ={0 n |n=0, 1, 2, …} If B={0, 1}, B*=V*. (The set of all strings over the alphabet V) C*={ , 1111, 111111, …} ={(11)n |n=0, 1, 2, …} ={12 n |n=0, 1, 2, …}
Finite State Automata Representations As with finite-state machines, finite-state automata have the following common representations – A state table is used to represent a finite-state automaton by giving the values of the function f. • Just like for finite-state machines, except the second half of the columns are omitted, since there is no output. – A state diagram is a directed graph representation of a finite-state automaton. • Final states are usually denoted by double-circles. • Values separated by commas denote several possible inputs, not inputs and outputs as with finite state machines.
Finite State Automata A finite state automation over an alphabet is illustrated by a state diagram: – a directed graph – edges are labeled with elements of alphabet, – some nodes (or states), marked as final of “accepting”. – one node marked as start state
Dealing with Input Strings Let x=x 1 x 2…xnÎI * (That is, x is a string over I) Then we can extend the transition function f to all state-input string pairs (rather than simply state-input pairs) in the obvious way – – – Assume the machine is in state S 0, Compute f(S 0, x 1) = Si 2 Next compute f(Si 2, x 2) = Si 3 Continue until you get f(Sin, xn) = Sin+1 We define f(S 0, x) = Sin+1 From now on, we will speak of the transition function f being applied to input strings, not just single inputs.
Finite Automaton Input String Output Finite Automaton “Accept” or “Reject”
Transition Graph initial state transition state accepting state
Initial Configuration Input String
Reading the Input
Input finished accept
Rejection
Input finished reject
Another Rejection
reject
Another Example
Input finished accept
Rejection Example
Input finished reject
Finite-State Automata Definition: A finite-state automaton is a 5 -tuple M=(S, I, f, S 0, F) where – S is a finite set of states – I is a finite input alphabet – f: S´I®S is a transition function from each state-input pair to a state – S 0 is the initial state – FÍS is a set of final states Note: automaton is the singular of automata.
Finite Automata ’ If end of input – If in accepting state => accept – Otherwise => reject If no transition possible (got stuck) => reject
Language Recognition Definition: A finite-state automaton accepts (or recognizes) a string x if f(S 0, x)ÎF. That is, the finite state automaton ends up in a final state. Definition: The language accepted (or recognized) by a finite-state automaton M, denoted by L(M), is the set of all strings recognized by M. Definition: Two finite-state automata are equivalent if they recognize the same language.
Example accept
Example accept
Example accept trap state
What is the Language? Example: What language is recognized by the following finite-state automaton? Input 0 or 1 • Solution: Since the only final state is the start state, and only an input of 1 will leave the machine in the start state, it is easy to see that L(M)={1 n: n=0, 1, 2, …}
What is the Language? Example: What language is recognized by the following finite-state automaton? • Solution: Notice that Any input that does not start with 0 cannot go to a final state The final state can only be arrived at if the last input is a 1 Any string can occur in between the first 0 and last 1. • Thus, we can see that L(M)={binary strings beginning with 0 and ending with 1}
FSM Examples Example: What language is recognized by the following finite-state automaton? 0 1 S 0 0 1 S 1 Accepts strings over alphabet {0, 1} that end in 1 44
Example: What language is recognized by the following finite-state automaton? a S 0 a b S 2 a 4 b b S 1 FSM Examples b b a 5 a Accepts strings over alphabet {a, b} that begin and end with same symbol 45
Example: What language is recognized by the following finite-state automaton? 0 S 1 Start 0 2 S 0 FSM Examples Accepts strings over {0, 1, 2} such that sum of digits is a multiple of 3 1 1 2 S 2 0 2 1 46
FSM Examples 0 0 1 Even Odd 1 Accepts strings over {0, 1} that have an odd number of ones 47
FSM Examples 1 0 1 1 0 '0' 0, 1 '00' '001' 0 Accepts strings over {0, 1} that contain the substring 001 48
Examples Design a FSM to recognize strings with an equal number of ones and zeros. – Not possible Design a FSM to recognize strings with an equal number of substrings "01" and "10". – Perhaps surprisingly, this is possible 49
FSM Examples 0 1 0 1 1 1 Accepts strings with an equal number of substrings "01" and "10" 0 0 50
Non-deterministic Finite Automaton (NDFA) a non-deterministic finite state machine or non-deterministic finite automaton (NDFA) is a finite state machine where for each pair of state and input symbol it assigns a set of states i. e. , from a pair of state and input symbol there are possibly two or more transitions to a next state. Every NDFA can be converted to a DFA
Nondeterministic Finite-State Automata Definition: A Nondeterministic fnite-state automaton is a 5 -tuple M=(S, I, f, S 0, F) where – S is a finite set of states – I is a finite input alphabet – f: S´I® P(S) is a transition function from each stateinput pair to a set of states – S 0 is the initial state – FÍS is a set of final states
0 0 S 1 1 Start S 3 0, 1 S 0 1 0 0 State F 0 F 1 S 0, S 2 S 1 S 3 S 4 S 2 1 S 4 S 3 53
S 1 1 Start 0 0 S 3 0, 1 S 0 1 0 0 S 2 1 S 4 What does it mean for a nondeterministic FSA (NFSA) to recognize a string? àT he NDFSA recognizes or accepts a string x if there is a final state in the set of all states that can be obtained from S 0, using x. 54
What language does it accept? 0 n 11 |n≥ 0 1 0 S 3 0 n |n≥ 0 S 2 1 0 0, 1 1 0 Start 0 S 1 S 4 0 n 01 |n≥ 0 55
Equivalence of DFSM and NFSM Theorem: – For each non-deterministic finite state machine N, we can construct a deterministic finite state machine D such that N and D accept the same language. – [proof omitted] Theorem: – Every deterministic finite state machine can be regarded as a non– deterministic finite state machine that just doesn’t use the extra non– deterministic capabilities. 56
F 0 F 1 S 0, S 2 S 1 S 3 S 4 S 2 S 0 S 3 S 4 S 3 0 S 2 {S 0, S 2} 0, 1 S 4 {S 1, S 4} 0 0, 1 1 0 Ø 1 {S 3} 0, 1 0 n |n≥ 0 0 n 01 |n≥ 0 1 S 3 {S 0} S 3 1 0 0 start 0 Start S 4 S 3 1 0 State S 1 {S 3, S 4} 0, 1 {S 1} {S 4} 0 n 11 |n≥ 0 1 57