Upload
shawn-potter
View
215
Download
0
Tags:
Embed Size (px)
Citation preview
§12.2 – Finite State Machines with Output
Giving credit where credit is due:
• Most slides based on lecture notes created Most slides based on lecture notes created by by – Michael P. Frank, University of Florida Michael P. Frank, University of Florida – Longin Jan Latecki, Temple UniversityLongin Jan Latecki, Temple University– Carla Gomes, Cornell UniversityCarla Gomes, Cornell University
Introduction
• Finite-State Machines Finite-State Machines – mathematical models of computation used to mathematical models of computation used to
design computer programsdesign computer programs
Applications
• Finite-State Machines Finite-State Machines – used in a variety of applications such as used in a variety of applications such as
• spell checking programs; spell checking programs;
• grammar checking; grammar checking;
• indexing and searching large text files;indexing and searching large text files;
• speech/language recognition; speech/language recognition;
• network protocolsnetwork protocols
• A computation can be modeled as a transition A computation can be modeled as a transition function function TT: : SS××II→S→S××OO??– If the state set If the state set SS is finite (not infinite), we call this is finite (not infinite), we call this
system a system a finite state machinefinite state machine..
• If the domain If the domain SS××II is reasonably small, then we can is reasonably small, then we can specify specify TT explicitly by writing out its complete explicitly by writing out its complete graph.graph.
Modeling Computation
Types of Finite-State Machines
• Finite-State Machines with OutputFinite-State Machines with Output– MealyMealy: : Output determined by state and inputOutput determined by state and input– MooreMoore: : Output determined by state aloneOutput determined by state alone
• Finite-State Machines with No OutputFinite-State Machines with No Output– Also known Also known as finite-state automataas finite-state automata– There are two types of finite-state automataThere are two types of finite-state automata
• DeterministicDeterministic: Each state-input pair dictates a unique transition : Each state-input pair dictates a unique transition into another stateinto another state
• Non-deterministicNon-deterministic: Each state-input pair can lead to several : Each state-input pair can lead to several possible statespossible states
Vending Machine Example
• Suppose a certain vending machine Suppose a certain vending machine accepts nickels, dimes, and quarters.accepts nickels, dimes, and quarters.– If >30If >30¢ is deposited, change is¢ is deposited, change is
immediately returned.immediately returned.
• When When there is 30there is 30¢ deposited, ¢ deposited,
if the if the ““cokecoke”” button is pressed button is pressed
the machine drops a coke.the machine drops a coke.– It can then accept a new payment.It can then accept a new payment.
Ignore any otherbuttons, bills,out of change,etc.
Modeling the Machine
• Input symbol set: Input symbol set: II = { = {nnickel, ickel, ddime, ime, qquarter, uarter, bbutton}utton}
• Output symbol set:Output symbol set: OO = { = {, 5¢, 10¢, 15¢, 20¢, 25¢, coke}, 5¢, 10¢, 15¢, 20¢, 25¢, coke}
• State set:State set: SS = {0, 5, 10, 15, 20, 25, 30} = {0, 5, 10, 15, 20, 25, 30}–Representing how much money has been taken. Representing how much money has been taken.
Transition Function Table
Old Old statestate InputInput
New New statestate OutputOutput
00 nn 55
00 dd 1010
00 qq 2525
00 bb 00
55 nn 1010
55 dd 1515
55 qq 3030
55 bb 55
Old Old statestate InputInput
New New statestate OutputOutput
1010 nn 1515
1010 dd 2020
1010 qq 3030 55¢ ¢
1010 bb 1010
1515 nn 2020
1515 dd 2525
1515 qq 3030 1010¢ ¢
1515 bb 1515
Transition Function Table cont.
Old Old statestate InputInput
New New statestate OutputOutput
2020 nn 2525
2020 dd 3030
2020 qq 3030 1515¢ ¢
2020 bb 2020
2525 nn 3030
2525 dd 3030 5¢ 5¢
2525 qq 3030 20¢ 20¢
2525 bb 2525
Old Old statestate InputInput
New New statestate OutputOutput
3030 nn 3030 55¢¢
3030 dd 3030 1010¢ ¢
3030 qq 3030 2525¢ ¢
3030 bb 00 cokecoke
Another Format: State Table
Old Old statestate
Input SymbolInput Symbol
nn dd qq bb
00 5,5, 10,10, 25,25, 0,0,
55 10,10, 15,15, 30,30, 5,5,
1010 15,15, 20,20, 30,530,5¢¢ 10,10,
1515 20,20, 25,25, 30,1030,10¢¢ 15,15,
2020 25,25, 30,30, 30,1530,15¢¢ 20,20,
2525 30,30, 30,530,5¢¢ 30,2030,20¢¢ 25,25,
3030 30,530,5¢¢ 30,1030,10¢¢ 30,2530,25¢¢ 0,coke0,coke
Each pair showsnew state,output symbol
Directed-Graph State Diagram
• As you can see, these can get kind of busy.As you can see, these can get kind of busy.
0 5 10 15 20 25 30
q,5¢
n n ndq d
q
b b b b b b
n n n
q,25¢d,10¢n,5¢
d
d,5¢
q,20¢
q,15¢
q,10¢b,coke
Formalizing FSMs
• Just like the general transition-function definition from Just like the general transition-function definition from earlier, but with the output function separated from the earlier, but with the output function separated from the transition function, and with the various sets added in, transition function, and with the various sets added in, along with an initial state.along with an initial state.
• A A finite-state machinefinite-state machine MM=(=(SS, , II, , OO, , ff, , gg, , ss00))– SS is the state set is the state set– II is the alphabet (vocabulary) of input symbols is the alphabet (vocabulary) of input symbols– OO is the alphabet (vocabulary) of output symbolsis the alphabet (vocabulary) of output symbols– ff is the state transition function is the state transition function– gg is the output function is the output function– ss00 is the initial state is the initial state
• Our transition function from before is Our transition function from before is TT = ( = (ff,,gg))..