Document

advertisement
Module #16 – Finite State Machines
Modeling Computation
Rosen 5th ed., ch. 11
Ref: Wikipedia
Fall 2004
1
Module #16 – Finite State Machines
Finite State Machines (FSM)
Model machines (or components in a
computer) using a particular structure
Classification


FSM with no output: determine whether the input
is accepted (recognized) or not
FSM with output: generate output from the given
input
Representations (p.752)


Fall 2004
State diagram
State transition table
2
Module #16 – Finite State Machines
FSM with Output
Definition: M = (S, I, O, f, g, s0)
S: finite set of states
I, O: input/output alphabets
f: transition function, f: S  I  S
g: output function
s0: initial state





Mealy machine: g: SI O
Moore machine:g: S O
Fall 2004
3
Module #16 – Finite State Machines
Simple Example (p.753)
Fall 2004
4
Module #16 – Finite State Machines
Generating Output
Input string: x = x1x2…xk
s1 = f(s0, x1), s2 = f(s1, x2), …, sk = f(sk-1, xk)
These state transition produces output y =
y1y2…yk
y1 = g(s0, x1), y2 = g(s1, x2), …, yk = g(sk-1, xk)
Fall 2004
5
Module #16 – Finite State Machines
Another Example
start
Input: 101011
Output: 001000
Fall 2004
6
Module #16 – Finite State Machines
Ex: vending machines
[description]
State table
Fall 2004
7
Module #16 – Finite State Machines
Vending Machine: state diagram
Fall 2004
8
Module #16 – Finite State Machines
Ex: Unit Delay Machine
Input: x1x2…xk; Output: 0x1x2…xk-1
state
s0
s1
s2
Fall 2004
f
0
s2
s2
s2
g
1
s1
s1
s1
0
0
1
0
Example & how the machine is
designed (p.755)
1
0
1
0
9
Module #16 – Finite State Machines
Ex: FSM for Addition
Design:


s0: to remember
that the previous
carry is 0
s1: to remember
that the previous
carry is 1
[example]
Fall 2004
10
Module #16 – Finite State Machines
FSM with No Output
Language recognition; design and
implementation of compilers

A string is recognized IFF it takes the
starting state to one of the final states
Def: Finite-state Automata: do not
produce output, but have a set of final
states
Fall 2004
11
Ex: automaton to recognize
“nice”
Module #16 – Finite State Machines
Fall 2004
12
Module #16 – Finite State Machines
Finite-State Automata
M = (S, I, f, s0, F)





S: finite set of states
I: input alphabets
f: transition function, f: S  I  S
s0: initial state
F: final states, subset of S (indicated by
double circles)
Fall 2004
13
Module #16 – Finite State Machines
Example: construct the state
diagram
Fall 2004
14
Module #16 – Finite State Machines
Recognizing Language
A string x is said to be recognized by
the machine M = (S, I, f, s0, F) if f(s0, x)
is a state in F
The language recognized (accepted) by
the machine M, denoted by L(M), is the
set of all strings accepted by M.
Fall 2004
15
Module #16 – Finite State Machines
Deterministic
finite automaton
Example
The following example is of a DFA M,
with a binary alphabet, which
determines if the input contains an
even number of 0s
Start
Fall 2004
16
Module #16 – Finite State Machines
Transformations from/to
State Diagram
It is possible to draw a state diagram from the table.
Draw the circles to represent the states given.
For each of the states, scan across the corresponding
row and draw an arrow to the destination state(s).
There can be multiple arrows for an input character if
the automaton is an NFA.
Designate a state as the start state. The start state is
given in the formal definition of the automaton.
Designate one or more states as accept state. This is
also given in the formal definition.
Fall 2004
17
Module #16 – Finite State Machines
Example
L(M1) = {1n | n = 0,1,2,…}
Fall 2004
18
Module #16 – Finite State Machines
Example (cont)
L(M2) = {1, 01}
Fall 2004
19
Module #16 – Finite State Machines
Example (cont)
L(M3) = {0n,0n10x | n = 0,1,2,…, x is
any string}
Fall 2004
20
Download