Finite State Machines 2 Joseph Spring School of Computer Science 1COM0044 Foundations of Computation 1
Discussion Points In the last lecture we looked at: 1. Abstract Machines 2. Finite State Machines Informal 1. Components of an FSM 2. State Transition Diagrams 3. A Simple FSM 4. FSM s and Loops 5. FSM s and Multiple Transitions 6. FSM s and Traps / Multiple Loops 2
Recall We are interested in the interaction between languages and machines The machines we work with are abstract machines they eist as abstract models of real world machines. So we are involved in modelling and the modelling process The machines we eplore (finite state machines) are sometimes referred to as finite state automata 3
Informal FSM s: We saw that: There is a special relationship between any FSM and the largest language that it recognises. Any given FSM will recognise a particular language (and any languages which are subsets of this of course). We noted that as language acceptors If two machines recognise the same language, then there is no difference between them they were considered equivalent. They have the same behaviour (even though they may look different). 4
For eample: a 2 c 1 c 3 5 b 4 c Machine 1: A Simple FSM This accepts the language L 1 = {acc, bcc} 5
And: a, b 1 2 c 3 c 4 Machine 4: A FSM with Multiple Transitions between States This accepts the language L 4 = {acc, bcc} As Language Acceptors Machines 1 & 4 are equivalent 6
Informal FSM s: We also noted that: We can think of the machine as recognising a string from the language OR we can think of the strings a programs that control the machine. If we assume that we can see what states we are in the machines respond to the program by eecuting the strings (provided we give valid strings!!). 7
Discussion Points In this lecture we consider: 1. Informal FSM s 1. Equivalent FSM s 2. FSM s and Computation 2. Formal FSM s 1. Definitions 8
1.1 Equivalent FSM s Consider the formal language L 6 = {ca, cb} One machine that we could use is: c a, b 1 2 3 Machine 6 9
1.1 Equivalent FSM s Another machine that we could use for L 6 = {ca, cb} Machine 6a c 1 2 b a 4 3 10
1.1 An Alternative View As language acceptors Machines 6 and 6a are equivalent However there is another way of viewing the machines which makes more eplicit their potential for computation they embody some notion of memory which creates a distinction between machines 6 and 6a Machine 6 remembers less than machine 6a 11
1.1 An Alternative View To see this consider As a language acceptor all that we require is some indication (lets say a light) to tell us that the machine has stopped in a final accepting state Light on string accepted as part of language Light off string NOT accepted as part of language However If we are also interested in which string was presented ca or cb then machine 6 cannot distinguish between which of a or b affected the transition from state 2 to state 3 Machine 6a on the other hand could have a light on each of states 3 and 4 and could thus indicate which string was accepted. In this sense Machine 6a is able to remember more than machine 6 12
1.1 An Alternative View The machines Are finite Can only remember a finite number of things The number being determined by the design of the machine Can recognise infinite languages Via loops Loops do not track of the number of times that they have been used Machine 3 for eample accepts abc, abcabc, but does not distinguish between which string has been used 13
1.1 An Alternative View L 3 = {abc, abcabc, abcabcabc, } a 2 b 1 a 3 b 4 c Machine 3: An FSM with Larger Loops 14
1.2 FSM s & Computation The above observation gives us an insight into how we could use FSM s for direct computation 1 0 2 3 15
1.2 FSM s & Computation We note State 1 is obtained using strings,,,, 1, 5, 9, 13,17, 21, 25, State 2 is obtained using strings,,,, 2, 6, 10, 14,18, 22, 26, State 3 is obtained using strings,,,, 3, 7, 11, 15,19, 23, 27, State 4 is obtained using strings,,,, 4, 8, 12, 16,20, 24, 28, This machine can be used to find remainders when dividing positive integers by 4 16
1.2 FSM s & Computation 1 0 2 3 A Simple Remainder Calculating Machine 17
1.2 FSM s & Computation What about this machine? n n n n S 0 1 0 2 0 3 0 4 1 4 3 4 1 2 1 3 2 3 2 4 18
1.2 FSM s & Computation What about this machine? n n n n S 0 1 0 2 0 3 0 4 1 4 3 4 1 2 1 3 2 3 A More General Remainder Calculating Machine 2 4 19
1.2 FSM s & Computation Let Strings of the form nnn denote a number (divisor) Strings of the form denote another number (dividend) Then We may interpret nnn as 5 divided by 3 Giving a remainder 2 which provided we label our states as in the previous machine is given by the previous machine Note that we have had to denote the states very carefully: we could not simply label all of our remainder-2 states with a 2, or we would have interfered with the machines memory as to what number was being divided by. 20
1.2 FSM s & Computation Note The previous eample illustrates the point that we need to be very careful regarding the representations we use for, for eample numbers 21
2.1 Formal FSM s - Definition The formal definition of a deterministic Finite State Automaton is given in terms of five components: 1. Q is a finite set of states. 2. T is a finite input alphabet. 3. t is a partial function: Q T Q. This function is called the transition function because it defines what state the FSM moves to from a given state when a given symbol from the input alphabet is received. 4. q 0 ε Q is a designated start state. 5. F Q is a set of final accepting states. Any number of states in Q can be designated as final accepting states. 22
2.1 Formal FSM s - Definition For Machine 1 we have: Q = {1, 2, 3, 4, 5} T = {a, b, c} t = {(1,a) 2, (1,b) 4, (2,c) 3, (3,c) 5, (4,c) 3} q 0 = 1 F = {5} What of machines 2 and 5 and? 23
2.1 Formal FSM s - Definition a 2 c 1 c 3 5 b 4 c Machine 1: A Simple FSM This accepts the language L 1 = {acc, bcc} 24
2.2 Transition Functions in Tabulated Form We can equally well draw the transition functions in tabulated form: Current State M1 transition 1 2 3 4 a 2 b 4 c 3 5 3 25
Summary In this lecture we consider: 1. Informal FSM s 1. Equivalent FSM s 2. FSM s and Computation 2. Formal FSM s 1. Definitions 2. Transition Functions in Tabulated Form 26