220 likes | 229 Views
Explore finite state machines' outputs and minimization algorithms, with examples on state transition tables and combining FSMs. Learn about state minimization process for DFAs. Dive into the world of state machines and automata.
E N D
CSE 311 Foundations of Computing I Lecture 22 Finite State Machines: Output and Minimization Autumn 2011 CSE 311
Announcements • Reading assignments • 7thEdition, Sections 13.3 and 13.4 • 6th Edition, Section 12.3 and 12.4 • 5th Edition, Section 11.3 and 11.4 CSE 311
011 001 1 0 1 1 1 010 101 111 000 1 1 0 1 0 0 100 110 1 0 0 0 0 Last lecture highlights Finite state machines • States, transitions, start state, final states • Languages recognized by FSMs 0 0 1 1 1 s0 s1 s2 s3 0 0,1 CSE 311
Last lecture highlights • Combining FSMs to check two properties at once • New states record states of both FSMs 0,1 0,1 2 s0 s1 s1t0 2 s0t1 0 0 2 1 1 2 1 0 s0t0 s1t1 2 0 0 t1 1 2 2 1 2 2 2 s1t2 s0t2 1 1 0 1 0 1 t0 t2 0 0 2 CSE 311
State Machines with Output Vending Machine Enter 15 cents in dimes or nickels Press S or B for a candy bar CSE 311
Vending Machine, Version 1 D D 0 N 5 10 15 N, D N B, S Basic transitions on N (nickel), D (dime), B (butterfinger), S (snickers) CSE 311
Vending Machine, Version 2 0 D N 15 D D B S 0’ B 5 10 N N N D 15’ N B S N D 0” S Adding output to states: N – Nickel, S – Snickers, B – Butterfinger CSE 311
Vending Machine, Final Version B,S 0 D N 15 B,S B,S B,S D D B D S N 0’ B 5 10 N N N D 15’N B N S D B,S N D N 0” S B 15” D S D Adding additional “unexpected” transitions CSE 311
State Minimization • Many different FSMs (DFAs) for the same problem • Take a given FSM and try to reduce its state set by combining states • Algorithm will always produce the unique minimal equivalent machine (up to renaming of states) but we won’t prove this CSE 311
State minimization algorithm • Put states into groups based on their outputs (or whether they are final states or not) • Repeat the following until no change happens • If there is a symbol s so that not all states in a group G agree on which group s leads to, split G into smaller groups based on which group the states go to ons G2 G1 G3 CSE 311
0 2 S0[1] S1 [0] 0 1 2 3 present next state output state 0 1 2 3 S0 S0 S1 S2 S3 1 S1 S0 S3 S1 S5 0 S2 S1 S3 S2 S4 1 S3 S1 S0 S4 S5 0 S4 S0 S1 S2 S5 1 S5 S1 S4 S0 S5 0 3 0 1 1 0 S2[1] S3 [0] 1 2 2 3 3 1 2 2 3 S4[1] S5 [0] 0 0 1 3 State Minimization Example state transition table Put states into groups based on their outputs (or whether they are final states or not) CSE 311
0 2 S0[1] S1 [0] 0 1 2 3 present next state output state 0 1 2 3 S0 S0 S1 S2 S3 1 S1 S0 S3 S1 S5 0 S2 S1 S3 S2 S4 1 S3 S1 S0 S4 S5 0 S4 S0 S1 S2 S5 1 S5 S1 S4 S0 S5 0 3 0 1 1 0 S2[1] S3 [0] 1 2 2 3 3 1 2 2 3 S4[1] S5 [0] 0 0 1 3 State Minimization Example state transition table Put states into groups based on their outputs (or whether they are final states or not) CSE 311
0 2 S0[1] S1 [0] 0 1 2 3 present next state output state 0 1 2 3 S0 S0 S1 S2 S3 1 S1 S0 S3 S1 S5 0 S2 S1 S3 S2 S4 1 S3 S1 S0 S4 S5 0 S4 S0 S1 S2 S5 1 S5 S1 S4 S0 S5 0 3 0 1 1 0 S2[1] S3 [0] 1 2 2 3 3 1 2 2 3 S4[1] S5 [0] 0 0 1 3 State Minimization Example state transition table Put states into groups based on their outputs (or whether they are final states or not) • If there is a symbol s so that not all states in • a group G agree on which group s leads to, • split G based on which group the states go • to ons CSE 311
0 2 S0[1] S1 [0] 0 1 2 3 present next state output state 0 1 2 3 S0 S0 S1 S2 S3 1 S1 S0 S3 S1 S5 0 S2 S1 S3 S2 S4 1 S3 S1 S0 S4 S5 0 S4 S0 S1 S2 S5 1 S5 S1 S4 S0 S5 0 3 0 1 1 0 S2[1] S3 [0] 1 2 2 3 3 1 2 2 3 S4[1] S5 [0] 0 0 1 3 State Minimization Example state transition table Put states into groups based on their outputs (or whether they are final states or not) • If there is a symbol s so that not all states in • a group G agree on which group s leads to, • split G based on which group the states go • to ons CSE 311
0 2 S0[1] S1 [0] 0 1 2 3 present next state output state 0 1 2 3 S0 S0 S1 S2 S3 1 S1 S0 S3 S1 S5 0 S2 S1 S3 S2 S4 1 S3 S1 S0 S4 S5 0 S4 S0 S1 S2 S5 1 S5 S1 S4 S0 S5 0 3 0 1 1 0 S2[1] S3 [0] 1 2 2 3 3 1 2 2 3 S4[1] S5 [0] 0 0 1 3 State Minimization Example state transition table Put states into groups based on their outputs (or whether they are final states or not) • If there is a symbol s so that not all states in • a group G agree on which group s leads to, • split G based on which group the states go • to ons CSE 311
0 2 S0[1] S1 [0] 0 1 2 3 present next state output state 0 1 2 3 S0 S0 S1 S2 S3 1 S1 S0 S3 S1 S5 0 S2 S1 S3 S2 S4 1 S3 S1 S0 S4 S5 0 S4 S0 S1 S2 S5 1 S5 S1 S4 S0 S5 0 3 0 1 1 0 S2[1] S3 [0] 1 2 2 3 3 1 2 2 3 S4[1] S5 [0] 0 0 1 3 State Minimization Example state transition table Put states into groups based on their outputs (or whether they are final states or not) • If there is a symbol s so that not all states in • a group G agree on which group s leads to, • split G based on which group the states go • to ons CSE 311
0 2 S0[1] S1 [0] 0 1 2 3 present next state output state 0 1 2 3 S0 S0 S1 S2 S3 1 S1 S0 S3 S1 S5 0 S2 S1 S3 S2 S4 1 S3 S1 S0 S4 S5 0 S4 S0 S1 S2 S5 1 S5 S1 S4 S0 S5 0 3 0 1 1 0 S2[1] S3 [0] 1 2 2 3 3 1 2 2 3 S4[1] S5 [0] 0 0 1 3 State Minimization Example state transition table Put states into groups based on their outputs (or whether they are final states or not) • If there is a symbol s so that not all states in • a group G agree on which group s leads to, • split G based on which group the states go • to ons CSE 311
0 2 S0[1] S1 [0] 0 1 2 3 present next state output state 0 1 2 3 S0S0S1S2S31 S1S0S3S1S50 S2S1S3S2S41 S3S1S0 S4S50S4S0S1S2S51S5S1S4 S0S50 3 0 1 1 0 S2[1] S3 [0] 1 2 2 3 3 1 2 2 3 S4[1] S5 [0] 0 0 1 3 State Minimization Example state transition table Can combine states S0-S4 and S3-S5. In table replace all S4 with S0 and all S5 with S3 CSE 311
present next state output state 0 1 2 3 S0S0S1S2S31 S1S0S3S1S30 S2S1S3S2S01 S3S1S0 S0S30 Minimized Machine 0 2 S0[1] S1 [0] 0 1 2 3 0 1,3 3 1,2 state transition table 0 S2[1] S3 [0] 1 2 3 CSE 311
Another way to look at DFAs Definition: The label of a path in a DFA is the concatenation of all the labels on its edges in order Lemma: x is in the language recognized by a DFA iff x labels a path from the start state to some final state 0 0 1 1 1 s0 s1 s2 s3 0 0,1 CSE 311
Nondeterministic Finite Automaton (NFA) • Graph with start state, final states, edges labeled by symbols (like DFA) but • Not required to have exactly 1 edge out of each state labeled by each symbol - can have 0 or >1 • Also can have edges labeled by empty string • Definition: x is in the language recognized by an NFA iff x labels a path from the start state to some final state 1 1 1 s0 s1 s2 s3 0,1 0,1 CSE 311
Design an NFA to recognize the set of binary strings that contain 111 or have an even # of 1’s CSE 311