What Are They? Who Needs ‘em? An Example: Scoring in Tennis Finite Automata What Are They? Who Needs ‘em? An Example: Scoring in Tennis Today we begin with an informal introduction to finite automata. I’ll offer some brief remarks about their uses, and then move to an extended example of an automaton that describes how a game of tennis is scored.
What is a Finite Automaton? A formal system- graphs & tables Remembers only a finite amount of information. Information represented by its state. State changes in response to inputs. Rules that tell how the state changes in response to inputs are called transitions. Click 1 The finite automaton is a mathematical model. But fortunately, it is a model that should be quite familiar. You can think of it either as a graph or a table. Click 2 The finite automaton is simple because it stores only a finite amount of information. That can be bad because in many applications there is no limit on the amount of information we need to remember about what has happened in the past. When that is the case, the finite automaton is not a useful model. But the finiteness of memory is great when the model can be used, because we can do a number of things with finite automata that we cannot do with programs in general. For example, given a program, you cannot really tell anything about it – what it does, or whether there is a shorter program that does the same thing. However, you can tell whether two automata do the same thing, or whether there is a smaller automaton that does the same as a given automaton. That ability lets us tell, for example, whether there are input sequences that cause an automaton to get into an error state, which in turn lets us check whether protocols or other simple systems have flaws. Click 3 A finite automaton is built around a finite collection of STATES. Each state has a name, and that name represents what is remembered about its history. Click 4 States change in response to INPUTS. Inputs are either characters, if we are doing something like processing text, or events, if we are modeling something like a communication protocol. Click 5 The rules that give the new state for each current state and input are called the TRANSITIONS.
Why Study Finite Automata? Used for both design and verification of circuits and communication protocols. Used for many text-processing applications. An important component of compilers. Describes simple patterns of events, etc. Sequence of symbols The finite automaton is useful in a number of computing applications. Click 1 We mentioned the design and verification of communication protocols and digital circuits. Click 2 Together with the related formalism called regular expressions, they are important in text-searching algorithms. Click 3 They are essential for the portion of a compiler that breaks the input into tokens – identifiers, keywords like “if,” and so on. Click 4 You find automata and regular expressions in many other applications as well – typically where a simple language is needed to describe patterns that are sequences of symbols or events of some sort.
Tennis Match = 3-5 sets. Set = 6 or more games. Game will show as a FA To see the power and also limitations of a FA we shall take up an example: scoring a game of tennis. Click 1 If you don’t play tennis, it is almost like ping pong, except you are really tiny and you stand on the table. Depending on which page comes first in response to your search query, it was invented in the 12th century or 1879 by people who evidently had too much time on their hands. Click 2 The scoring system is arcane, with matches consisting of sets, Click 3 which consist of games. Games consist of points, where one player or the other wins by causing the other player to hit the ball off the court or into the net.
Scoring a Game One person serves throughout. To win, you must score at least 4 points. You also must win by at least 2 points. Inputs are s = “server wins point” and o = “opponent wins point.” Click 1 We’ll talk about scoring a game. One player is server throughout the game. Click2 To win the game, you must have at least four points. Click 3 But you must also win by at least two points. Click 4 The states we are going to use for the scoring automaton represent the numbers of points won by each player, and they have strange names which we’ll see as we go. The inputs are events in which one player wins a point --- s for “server” and o for “opponent.”
Server Wins Opp’nt s o s o Love-40 15-30 30-15 40-Love s o deuce s o 30-40 40-30 s o Ad-out Ad-in s o 40-15 15-40 30-all s o Love-30 15-all 30-Love s o Start Love-15 15-Love s o Love It is common to represent a FA by a graph, with nodes for states and arrows labeled by the input for transitions. Here’s the first state of the automaton that scores tennis games. The name of this state is LOVE. You may ask what’s love got to do -- got to do -- with it, but that’s what “zero” is called in tennis. Click 1 The state “Love” represents the history in which nothing has happened, and we indicate that history begins with this state by an arrow labeled START. Click 2 The first point will be won by one of the two players, so there are two transitions out of LOVE, one labeled s the other o. Here are the transitions and new states. You might think the names of the states would be 1-0 and 0-1 – the server’s score always goes first. But they’re not. In tennis, there is the fiction that you score 15 for winning a point. And 0 isn’t 0; it’s LOVE. Click 3 The next point can lead to three states, two where one player has won both points, and one where they’re tied at one each. Here are the states with their names. There is something interesting about the 15-all state. It has forgotten how we got there. We know the sequence of inputs was either s-o or o-s, but we don’t know which. It doesn’t matter, of course. That’s a good thing about FA; they only remember what must be remembered. In state 15-all, the question of who won the first of the two points can’t have any effect on the outcome. Click 4 After another point, there are four new states the game could be in. They have the expected names, except people are too lazy to say “45” so they just say “40.” Click 5 Now, let’s look at the transitions from the state 40-love. The server is well ahead and can win on the next point. If the server wins, we go to a state indicating that win. The game is over, and the automaton has no further moves. We indicate this “output” of the automaton by calling this state a FINAL state, and we indicate it is final by a double circle. There is another final state reachable from the state love-40, if the next input indicates the opponent won the fourth point. Click 6 There are three other new states as well, called 40-15, 30-all, and 15-40. Each indicates that four points have been played, with 3, 2, or 1 of these points won by the server. Click 7 From the 40-15 state, if the server wins the point, we go to the “server won” state, but if the opponent wins the point we go to a new state called 40-30. A similar thing happens from 15-40, and from 30-all we can go to either the 40-30 or the 30-40 state. Click 8 Now, let’s look at state 40-30. If the server wins the next point, they’ve won the game, but if the opponent wins, then the game is tied. The name for this state is DEUCE. The deuce state is quite interesting. It remembers that the game is tied, but it remembers neither the sequence of wins and losses of points nor even how many points have been played. The 30-40 state is handled similarly. Click 9 Next, consider what happens in DEUCE. You have to win by two points, so it is impossible for either player to win immediately. If the server wins the next point, they are ahead by one point, although we don’t know how many points in total have been played. The strange name for this state is AD-IN (advantage “in”). “In” refers to the server. Symmetrically, if the opponent wins in state DEUCE, we go to state AD-OUT --- the “out” refers to the opponent. Click 10 Then, in state ad-in, if the server wins the next point they win the game. But if the opponent wins, you are back to deuce. Likewise, from ad-out, a server win puts you back in deuce, but an opponent win gives the opponent the game. We can now look at the entire TRANSITION DIAGRAM for the FA. While most of it just allows flow away from the start state, the loops involving deuce, ad-in, and ad-out allow for cycles and for an infinite number of possible strings of s’s and o’s to lead to one of the final states.
Acceptance of Inputs Given a sequence of inputs (input string ), start in the start state and follow the transition from each symbol in turn. Input is accepted if you end up in a final (accepting) state after all inputs have been read. The job of an automaton is to process STRINGS of input symbols, or “input strings.” Click 1 We always begin at the start state, and we read each input symbol, in order. For each input symbol, we follow the transition from the state we are in, to discover what the new state is. Click 2 We ACCEPT a string if we wind up in a final state after processing the entire input. Here is an example…
Example: Processing a String s o s o s o s o s o s s Love Start Love-15 15-Love s o Love-30 15-all 30-Love Love-40 15-30 30-15 40-Love Server Wins Opp’nt 40-15 15-40 30-all 30-40 40-30 deuce Ad-out Ad-in Here is our input string (POINT). It represents a game in which the server and opponent alternate winning points, until at the very end (POINT) the server wins two in a row. We’ll mark the current state by the star (POINT). Initially the current state is the start state. That’s where all finite automata start out. The arrow (POINT) indicates which input we are about to process. So here, we are about to process the first event, where the server wins the first point. We’re going to follow the transition out of state LOVE labeled s (POINT). *
Example: Processing a String s o s o s o s o s o s s Love Start Love-15 15-Love s o Love-30 15-all 30-Love Love-40 15-30 30-15 40-Love Server Wins Opp’nt 40-15 15-40 30-all 30-40 40-30 deuce Ad-out Ad-in * Here, we’ve made the first transition. The next input is o (POINT), and we’re in state 15-love (POINT). The transition from that state on o is to state 15-all.
Example: Processing a String s o s o s o s o s o s s Love Start Love-15 15-Love s o Love-30 15-all 30-Love Love-40 15-30 30-15 40-Love Server Wins Opp’nt 40-15 15-40 30-all 30-40 40-30 deuce Ad-out Ad-in * In state 15-all, we see another s on the input, so we go to state 30-15.
Example: Processing a String s o s o s o s o s o s s Love Start Love-15 15-Love s o Love-30 15-all 30-Love Love-40 15-30 30-15 40-Love Server Wins Opp’nt 40-15 15-40 30-all 30-40 40-30 deuce Ad-out Ad-in * An o takes us to state 30-all.
Example: Processing a String s o s o s o s o s o s s Love Start Love-15 15-Love s o Love-30 15-all 30-Love Love-40 15-30 30-15 40-Love Server Wins Opp’nt 40-15 15-40 30-all 30-40 40-30 deuce Ad-out Ad-in * Then on input s we go to state 40-30.
Example: Processing a String s o s o s o s o s o s s Love Start Love-15 15-Love s o Love-30 15-all 30-Love Love-40 15-30 30-15 40-Love Server Wins Opp’nt 40-15 15-40 30-all 30-40 40-30 deuce Ad-out Ad-in * from there, on o, to Deuce.
Example: Processing a String s o s o s o s o s o s s Love Start Love-15 15-Love s o Love-30 15-all 30-Love Love-40 15-30 30-15 40-Love Server Wins Opp’nt 40-15 15-40 30-all 30-40 40-30 deuce Ad-out Ad-in * And from Deuce on s to Ad-in.
Example: Processing a String s o s o s o s o s o s s Love Start Love-15 15-Love s o Love-30 15-all 30-Love Love-40 15-30 30-15 40-Love Server Wins Opp’nt 40-15 15-40 30-all 30-40 40-30 deuce Ad-out Ad-in * From there on o back to Deuce.
Example: Processing a String s o s o s o s o s o s s Love Start Love-15 15-Love s o Love-30 15-all 30-Love Love-40 15-30 30-15 40-Love Server Wins Opp’nt 40-15 15-40 30-all 30-40 40-30 deuce Ad-out Ad-in * And another cycle on s and o between Ad-in and Deuce.
Example: Processing a String s o s o s o s o s o s s Love Start Love-15 15-Love s o Love-30 15-all 30-Love Love-40 15-30 30-15 40-Love Server Wins Opp’nt 40-15 15-40 30-all 30-40 40-30 deuce Ad-out Ad-in * (JUST CLICK)
Example: Processing a String s o s o s o s o s o s s Love Start Love-15 15-Love s o Love-30 15-all 30-Love Love-40 15-30 30-15 40-Love Server Wins Opp’nt 40-15 15-40 30-all 30-40 40-30 deuce Ad-out Ad-in * Now come the first of the two s’s. This s takes us to Ad-in again.
Example: Processing a String s o s o s o s o s o s s Love Start Love-15 15-Love s o Love-30 15-all 30-Love Love-40 15-30 30-15 40-Love Server Wins Opp’nt 40-15 15-40 30-all 30-40 40-30 deuce Ad-out Ad-in * But the second s takes us to the state where the Server is declared the winner of the game.
Example: Processing a String * s o s o s o s o s o s s Love Start Love-15 15-Love s o Love-30 15-all 30-Love Love-40 15-30 30-15 40-Love Server Wins Opp’nt 40-15 15-40 30-all 30-40 40-30 deuce Ad-out Ad-in Good going server.
Language of an Automaton The set of strings accepted by an automaton A is the language of A. Denoted L(A). Different sets of final states -> different languages. Example: As designed, L(Tennis) = strings that determine the winner. Click 1 Now let’s get a bit more formal. The job of the FA is to process strings of inputs and accept or reject them. It accepts the string if it leads from the start state to a final state. “Accepting state” is a synonym for “final state.” A “language” is simply a set of strings in the formalism used for automata. Click 2 The language accepted by an automaton A is denoted L(A). Click 3 In our tennis example, we called the two states where one of the players wins the final states. In that case the language of the FA is the set of strings of esses and ohs that end the game, no matter who wins. Click 4 We could change the set of final states, say by making only the “Server-Wins” state be final. Then, the automaton would have a different language: the set of esses and ohs that lead to a win by the server. Or, we could make only “Opponent-Wins” be final and have the language of ways the opponent can win.