Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2014 - Curt Hill Finite State Automata Again This Time No Output.

Similar presentations


Presentation on theme: "Copyright © 2014 - Curt Hill Finite State Automata Again This Time No Output."— Presentation transcript:

1 Copyright © 2014 - Curt Hill Finite State Automata Again This Time No Output

2 Copyright © 2014 - Curt Hill Recall… We last considered FSA Each has An input alphabet A finite number of states State transition function Output function Initial node They are often represented as –Graphs with nodes and arcs –State charts Now we are considering FSA without output

3 What is new? Now our FSMs do not produce output, so we do not need the Output function What we add instead is the requirement of a final node To be legal input we must start at an initial state and end at a final state Thus their output is based on final state –Legal or illegal Copyright © 2014 - Curt Hill

4 Why? FSA with output are usually used to model a simple machine and display intermediate results –These intermediate results may be all we are interested in The no output FSA are usually language recognizers –Does the input string conform to some predefined rule or not Copyright © 2014 - Curt Hill

5 Definition An output-less finite state machine is 5 tuple M=(S,I,f,s 0, F) S is a set of states I is the set of inputs f is the transition function s 0 is the initial state, s 0  S F is the set of final states, F  S Copyright © 2011-2014 - Curt Hill

6 Error States There are two possible errors that can occur with these If the state does not allow for this particular input this puts the machine in an error state –The book does not allow this one yet If the machine does not end in a designated final state this is also an error –There may be multiple final states Copyright © 2011-2014 - Curt Hill

7 Exercise Recall the FSM from previous presentation that we saw –I will show again on next slide Lets assume that the initial and terminal state is s0 Find three strings that this automaton accepts What is shortest string it may accept? What is the longest string it may accept? Copyright © 2011-2014 - Curt Hill

8 Exercise Copyright © 2011-2014 - Curt Hill s0 s1 s2 a b b a a b s0 s1 s2 ba s0 s1 s2

9 Which are not legal? Copyright © 2011-2014 - Curt Hill s0 s1 s2 a b b a a b s0 s1 s2 ba s0 s1 s2 aaabb bbaa abaab bababba abababa bbbbabab

10 Strings These FSA are language recognizers –That is, given an input string they pronounce it legal or illegal based on the state on which they stopped I* is the set of all strings, whose characters are composed solely from the input alphabet, I The language they accept is a subset of the set of all possible strings, I* Copyright © 2014 - Curt Hill

11 Definitions Suppose we have two sets of strings A,B both of which are subsets of I* The concatenation of A and B is AB –This is the set of every element of A concatenated with each element of B –Something like a Cartesian product but we end up with strings rather than ordered pairs Copyright © 2014 - Curt Hill

12 Example Suppose that A = {0, 1} and B={a,b,c} AB = {0a, 0b, 0c, 1a, 1b, 1c} BA = {a0, a1, b0, b1, c0, c1} AA = {00,01,10,11} BB = {aa, ab, ac, ba, bb, bc, ca, cb, cc} Copyright © 2014 - Curt Hill

13 Kleene Closure Copyright © 2014 - Curt Hill

14 Example Suppose that A={0,1}, B={a,b,c} A* = {0,1,00,01,10,11,000,001,…} –This is the set of all bit strings B* = {a,b,c,aa,ab,ac,ba,bb,bc,…} –This is the set of all strings composed of the three letters abc If C = {ab} what is C*? Copyright © 2014 - Curt Hill

15 Language Recognition Each FSM with starting and final states recognizes a language –A type 3 grammar to be exact If the machine ends on a final state the string is correct –If not the string is not in the language If this machine is denoted by M then the language is denoted by L(M) Copyright © 2014 - Curt Hill

16 Example Suppose that S 0 is the start state and S 1 and S 3 are final states What language does this accept? What productions? Copyright © 2014 - Curt Hill S0S0 S1S1 0 S2S2 1 1 0 S3S3 0,1

17 Other Way Can we construct a DFM that recognizes all bit strings where there are not two successive ones? Copyright © 2014 - Curt Hill

18 Result What we want is a DFM with node that is obtained with a one but only accepts zeros from there Start is S 0 and final is S 1 and S 2 Copyright © 2014 - Curt Hill S0S0 S1S1 1 S2S2 0 1 0 S3S3 0,1 1 0

19 Determinism All the FSMs we have looked at are deterministic –For each pair of state and input there is a unique new state The alternative is a non- deterministic finite state automaton –For any state-input pair there may be zero or more states A NDFA accepts a string if any choice of transitions accepts the string Copyright © 2014 - Curt Hill

20 Example State S 0 is the start state and S 1 is the final state –S 0 has no two 1 transitions –S 1 has no transitions –S 2 has two 1 transitions –S 3 has no 1 transition Copyright © 2014 - Curt Hill S0S0 S1S1 0,1 S2S2 0 1 1 S3S3 1 0

21 Commentary The understanding problem is the states that have multiple transitions or no transitions A NDFA can be viewed in several ways: –If any of the alternatives work the machine accepts the language –Multiple alternatives are pursued concurrently –Failed alternatives do not matter as long as one works Copyright © 2014 - Curt Hill

22 NDFA Non-Deterministic Finite Automata are useful in variety of theoretical contexts Often easier to define a NDFA for a language Many proofs are easier with NDFA Closures are also easier to compute Copyright © 2014 - Curt Hill

23 Example Suppose that S 0 is the start state and S 1 is the final state What language does this accept? What productions? What errors are possible Copyright © 2014 - Curt Hill S0S0 S1S1 1 S2S2 0 0,1

24 Equivalence Although NDFA have more flexibility than DFA the two have equivalent strength in regards to language recognition In particular for any NDFA and equivalent DFA may be constructed How is this done? –It is called the Powerset or subset construction Copyright © 2014 - Curt Hill

25 Construction Suppose we have a NDFA, N Converting it to a DFA, D, will have several characteristics The worst case is that if the N has n nodes then D will have 2 n nodes Each node in D will be labeled by a subset of the nodes from N Copyright © 2014 - Curt Hill

26 Building the States Add {s 0 } to S D – this is the start node While there are still states to be defined –Choose s in S D –For each a in the alphabet determine the set of states that are reachable from q on input a If there is no state in S D representing the above add it Define a new state corresponding to this Define f D as any state in S D that corresponds to a subset containing any final state in N Copyright © 2014 - Curt Hill

27 Easy Example There are two states that have incomplete specification, S 0 and S 1 All we need to do is generate an error state that captures Copyright © 2014 - Curt Hill S0S0 S1S1 1 S2S2 0 0,1

28 Easy Example Copyright © 2014 - Curt Hill S0S0 S1S1 1 S2S2 0 0,1 S0S0 S1S1 1 S2S2 0 Becomes: S err 0 1 0,1 Does not matter if we have 1 or 2 error states

29 Harder Copyright © 2014 - Curt Hill S0S0 S1S1 0,1 S2S2 0 1 1 No missing transitions, but two 1’s coming from S 0 State S 0 is start, S 1 is final

30 Harder Copyright © 2014 - Curt Hill S0S0 S1S1 0,1 S2S2 0 1 1 S0S0 S1S1 0 S2S2 1 1 S3S3 S err 0,1 S3S3 1 0 0 Six states and three final states. S 1 and S 3 could have been merged

31 Exercises 13.3 –1, 5, 9, 13, 17, 21, 45 Copyright © 2014 - Curt Hill


Download ppt "Copyright © 2014 - Curt Hill Finite State Automata Again This Time No Output."

Similar presentations


Ads by Google