View
219
Download
0
Category
Tags:
Preview:
Citation preview
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
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 illegalCopyright © 2014 - Curt Hill
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
Definition• An output-less finite state machine
is 5 tupleM=(S,I,f,s0,F)
• S is a set of states• I is the set of inputs• f is the transition function• s0 is the initial state, s0S• F is the set of final states, FS
Copyright © 2011-2014 - Curt Hill
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
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
Which are not legal?
Copyright © 2011-2014 - Curt Hill
s0s1
s2
a b
b
a
a
b
s0
s1
s2
ba
s0
s0
s1
s1 s2
s2
• aaabb• bbaa• abaab• bababba• abababa• bbbbabab
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
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
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
Kleene Closure• The Kleene Closure is the set
consisting of all strings made up by concatenating of strings from a set of characters– If the set of characters is A then the
Kleene Closure is A*
• This closure is all possible strings from that set:
Copyright © 2014 - Curt Hill
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
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
Example
• Suppose that S0 is the start state and S1 and S3 are final states
• What language does this accept?• What productions?
Copyright © 2014 - Curt Hill
S0 S1
0S2
1
1 0
S3
0,1
0,1
Other Way• Can we construct a DFM that
recognizes all bit strings where there are not two successive ones?
Copyright © 2014 - Curt Hill
Result• What we want is a DFM with node
that is obtained with a one but only accepts zeros from there
• Start is S0 and final is S1 and S2
Copyright © 2014 - Curt Hill
S0
S11
S2
0
1
0
S30,1
1
0
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
Example
• State S0 is the start state and S1 is the final state– S0 has no two 1 transitions
– S1 has no transitions
– S2 has two 1 transitions
– S3 has no 1 transitionCopyright © 2014 - Curt Hill
S0 S1
0,1S2
0
1
1
S3
1
0
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 worksCopyright © 2014 - Curt Hill
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
Example
• Suppose that S0 is the start state and S1 is the final state
• What language does this accept?• What productions?• What errors are possible
Copyright © 2014 - Curt Hill
S0 S1
1S2
0
0,1
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
constructionCopyright © 2014 - Curt Hill
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 2n nodes• Each node in D will be labeled by a
subset of the nodes from N
Copyright © 2014 - Curt Hill
Building the States• Add {s0} to SD – this is the start node• While there are still states to be defined
– Choose s in SD – 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 SD representing the above
add it• Define a new state corresponding to this
• Define fD as any state in SD that corresponds to a subset containing any final state in N
Copyright © 2014 - Curt Hill
Easy Example
• There are two states that have incomplete specification, S0 and S1
• All we need to do is generate an error state that captures
Copyright © 2014 - Curt Hill
S0 S1
1S2
0
0,1
Easy Example
Copyright © 2014 - Curt Hill
S0 S1
1S2
0
0,1
S0 S1
1S2
0
0,1
Becomes:
Serr
0 1
0,1
Does not matter if we have 1 or 2 error states
Harder
Copyright © 2014 - Curt Hill
S0 S1
0,1S2
0
1
1
• No missing transitions, but two 1’s coming from S0
• State S0 is start, S1 is final
Harder
Copyright © 2014 - Curt Hill
S0 S1
0,1S2
0
1
1
S0 S1
0
S2
1
1
S3
Serr
0,1
0,1
S3
1
0
0 0,1
Six states and three final states.S1 and S3 could have been merged
Recommended