Presentation is loading. Please wait.

Presentation is loading. Please wait.

§12.2 – Finite State Machines with Output. Giving credit where credit is due: Most slides based on lecture notes created byMost slides based on lecture.

Similar presentations


Presentation on theme: "§12.2 – Finite State Machines with Output. Giving credit where credit is due: Most slides based on lecture notes created byMost slides based on lecture."— Presentation transcript:

1 §12.2 – Finite State Machines with Output

2 Giving credit where credit is due: Most slides based on lecture notes created byMost slides based on lecture notes created by –Michael P. Frank, University of Florida –Longin Jan Latecki, Temple University –Carla Gomes, Cornell University

3 Introduction Finite-State MachinesFinite-State Machines –mathematical models of computation used to design computer programs

4 Applications Finite-State MachinesFinite-State Machines –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

5 A computation can be modeled as a transition function T: S×I→S×O?A computation can be modeled as a transition function T: S×I→S×O? –If the state set S is finite (not infinite), we call this system a finite state machine. If the domain S×I is reasonably small, then we can specify T explicitly by writing out its complete graph.If the domain S×I is reasonably small, then we can specify T explicitly by writing out its complete graph. Modeling Computation

6 Types of Finite-State Machines Finite-State Machines with OutputFinite-State Machines with Output –Mealy: Output determined by state and input –Moore: Output determined by state alone Finite-State Machines with No OutputFinite-State Machines with No Output –Also known as finite-state automata –There are two types of finite-state automata Deterministic: Each state-input pair dictates a unique transition into another stateDeterministic: Each state-input pair dictates a unique transition into another state Non-deterministic: Each state-input pair can lead to several possible statesNon-deterministic: Each state-input pair can lead to several possible states

7 Vending Machine Example Suppose a certain vending machine accepts nickels, dimes, and quarters.Suppose a certain vending machine accepts nickels, dimes, and quarters. –If >30¢ is deposited, change is immediately returned. When there is 30¢ deposited,When there is 30¢ deposited, if the “ coke ” button is pressed the machine drops a coke. –It can then accept a new payment. Ignore any other buttons, bills, out of change, etc.

8 Modeling the Machine Input symbol set: I = {nickel, dime, quarter, button}Input symbol set: I = {nickel, dime, quarter, button} Output symbol set: O = { , 5¢, 10¢, 15¢, 20¢, 25¢, coke}Output symbol set: O = { , 5¢, 10¢, 15¢, 20¢, 25¢, coke} State set: S = {0, 5, 10, 15, 20, 25, 30}State set: S = {0, 5, 10, 15, 20, 25, 30} –Representing how much money has been taken.

9 Transition Function Table Old state Input New state Output 0n5 0d10 0q25 0b0 5n10 5d15 5q30 5b5 Old state Input New state Output10n15 10d20 10q30 5¢5¢5¢5¢ 10b10 15n20 15d25 15q30 10¢ 15b15

10 Transition Function Table cont. Old state Input New state Output 20n25 20d30 20q30 15¢ 20b20 25n30 25d305¢ 25q3020¢ 25b25 Old state Input New state Output30n30 5¢5¢5¢5¢ 30d30 10¢ 30q30 25¢ 30b0coke

11 Another Format: State Table Old state Input Symbol ndqb 0 5,  10,  25,  0,  5 10,  15,  30,  5,  10 15,  20,  30,5¢ 10,  15 20,  25,  30,10¢ 15,  20 25,  30,  30,15¢ 20,  25 30,  30,5¢ 30,20¢ 25,  30 30,5¢ 30,10¢ 30,25¢ 0,coke Each pair shows new state, output symbol

12 Directed-Graph State Diagram As you can see, these can get kind of busy.As you can see, these can get kind of busy. 051015202530 q,5¢ nnn d q d q bbbbbb n nn q,25¢ d,10¢ n,5¢ d d,5¢ q,20¢ q,15¢ q,10¢ b,coke

13 Formalizing FSMs Just like the general transition-function definition from earlier, but with the output function separated from the transition function, and with the various sets added in, along with an initial state.Just like the general transition-function definition from earlier, but with the output function separated from the transition function, and with the various sets added in, along with an initial state. A finite-state machine M=(S, I, O, f, g, s 0 )A finite-state machine M=(S, I, O, f, g, s 0 ) –S is the state set –I is the alphabet (vocabulary) of input symbols –O is the alphabet (vocabulary) of output symbols –f is the state transition function –g is the output function –s 0 is the initial state Our transition function from before is T = (f,g).Our transition function from before is T = (f,g).

14 Examples


Download ppt "§12.2 – Finite State Machines with Output. Giving credit where credit is due: Most slides based on lecture notes created byMost slides based on lecture."

Similar presentations


Ads by Google