cse 311 foundations of computing i lecture 21 finite state machines autumn 2011 cse 3111
TRANSCRIPT
CSE 311 Foundations of Computing I
Lecture 21Finite State Machines
Autumn 2011
Autumn 2011 CSE 311 1
Announcements
• Reading assignments– 7th Edition, Sections 13.3 and 13.4– 6th Edition, Section 12.3 and 12.4– 5th Edition, Section 11.3 and 11.4
• HW 8 is on-line
Autumn 2011 CSE 311 2
Last lecture highlights
Autumn 2011 CSE 311 3
Let R be a relation on a set A. There is a path of length n from a to b if and only if (a,b) Rn
Let R be a relation on a set A. The connectivity relation R* consists of the pairs (a,b) such that there is a path from a to b in R.
Transitive-Reflexive closure: Add the minimum possible number of edges to make the relation transitive and reflexive
The transitive-reflexive closure of a relation R is the connectivity relation R*
Finite state machines
StatesTransitions on inputsStart state and final statesThe language recognized by a machine is the set of strings that reach a final state
Autumn 2011 CSE 311 4
s0 s2 s3s1111
1
0,1
0
0
0State 0 1
s0 s0 s1
s1 s0 s2
s2 s0 s3
s3 s3 s3
Applications of Finite State Machines (a.k.a. Finite Automata)
• Implementation of regular expression matching in programs like grep
• Control structures for sequential logic in digital circuits
• Algorithms for communication and cache-coherence protocols– Each agent runs its own FSM
• Design specifications for reactive systems– Components are communicating FSMs
Autumn 2011 CSE 311 5
Applications of Finite State Machines (a.k.a. Finite Automata)
• Formal verification of systems– Is an unsafe state reachable?
• Computer games– FSMs provide worlds to explore
• Minimization algorithms for FSMs can be extended to more general models used in– Text prediction– Speech recognition
Autumn 2011 CSE 311 6
What language does this machine recognize?
Autumn 2011 CSE 311 7
s0
s2 s3
s1
1
1
1
1
0
0
0
0
3 Bit Shift register
Autumn 2011 CSE 311 8
001 011
111
110
101010000
100
1
11 0 1
1
1
1
000 1
0
0
00
Autumn 2011 CSE 311 9
001 011
111
110
101010000
100
1
11 0 1
1
1
1
000 1
0
0
00
10
00 01 10 11
11
1
0
0 0
0 0 0 01
1
1
1
Design a DFA that accepts strings with a 1 three positions from the end
Autumn 2011 CSE 311 10
Autumn 2011 CSE 311 11
How does the size of a DFA to recognize “10th character is a 1” compare with the size of a DFA to recognize “10th character from the end is 1”?
Strings over {0, 1, 2}*
M1: Strings with an even number of 2’s
M2: Strings where the sum of digits mod 3 is 0
Autumn 2011 CSE 311 12
s0 s1
t0 t2
t1
Recognize strings with an even number of 2’s and a mod 3 sum of
0
Autumn 2011 CSE 311 13
s0t0
s1t0
s1t2
s0t1
s0t2
s1t1
State machines with output
Autumn 2011 CSE 311 14
Input Output
State L R
s1 s1 s2 Beep
s2 s1 s3
s3 s2 s4
s4 s3 s4 Beep
S3 S4S1 S2
R
L
R
L
R
L
L
R
“Tug-of-war”
Vending Machine
Autumn 2011 CSE 311 15
Enter 15 cents in dimes or nickelsPress S or B for a candy bar
Vending Machine, Version 1
Autumn 2011 CSE 311 16
0 5 10 15
D D
N N N, D
B, S
Basic transitions on N (nickel), D (dime), B (butterfinger), S (snickers)
Vending Machine, Version 2
Autumn 2011 CSE 311 17
0’ B 5 10
15
Adding output to states: N – Nickel, S – Snickers, B – Butterfinger
15’ N
0
0” S
N
N
N
N
N
B
D
D
D
D
D B
S
S
Vending Machine, Final Version
Autumn 2011 CSE 311 18
0’ B 5 10
15
Adding additional “unexpected” transitions
15’ N
0
0” S
N
N
N
N
N
B
D
D
D
D
D B
S
S
15”
DS
B
B,S
B,S
B,S
B,S B,S
N
N
N
D
D
D