1 - 2 - 2. Informal Introduction to Finite Automata (11 Min.)

Embed Size (px)

Citation preview

In this lecture, we're going to talk aboutthe finite automaton. Primarily, I'm goingto give you an example of designing anautomaton. It's gonna be based on,scoring, a game of tennis. But I want tostart off by talking a little bit about,some of the applications, that finiteautomaton are, are used for. A finiteautomaton is a mathematical model.However, it's not anything that youshould. Find very unfamiliar, in fact,their very much like graphs. We can alsosee them as a table. The finite automatonis simple because it stores only a finiteamount of information. That can be bad,because, in many applications, there is nolimit on the amount of information we needto remember about what has happened in thepast. When that is the case, the finiteautomaton is not a useful model. But thefiniteness of memory is great when themodel can be used. Because we can do anumber of things that, with finite[inaudible] that we cannot do with programin general. For example, given a program,you cannot really tell anything about it.What it does, or whether there is ashorter program that does the same thing.On the other hand, with [inaudible]automaton, you can tell whether two[inaudible] do the same thing. And you canfind a smallest automaton that does anygiven thing that an automaton can do. Thatability let's us tell, for example,whether there are input sequences thatcause an atomaton to get into an errorstate which in turn let's us check whetherprotocols or other simple systems haveflaws. Okay, a finite atomaton is builtaround a finite collection of states. Eachstate has a name, and that name representswhat is remembered about its history.States change in response to inputs.Inputs, in many examples are characters,A, B, C, or zero and one, and so on. Andthese are useful if we were doing thingslike processing texts. Inputs can also beevents which could be appropriate lets sayif we were modeling a communicationprotocol. There are rules that tell us,how to state changes in response to eachinput. Okay, these rules are calledtransitions. The finite automaton isuseful in a number of computingapplications, including design andverification of communication protocolsand digital circuits. Together with therelated formalism called regularexpressions, they are an important in textsearching algorithms. They are essentialfor a portion of a compiler that breaksthe input into tokens. That isidentifiers, keywords like if, and so on.You will find the Tomada in regularexpressions and many other applications aswell. Typically, where a simple languageis needed to describe patterns that aresequences of symbols or events of somesort. To see the power and alsolimitations of the [inaudible] automatonwe shall take up an example scoring a gameof tennis. If you don't play tennis it'salmost like ping pong except you arereally tiny and you stand on the table.Depending on which page comes first inresponse to your search query tennis wasinvented either in the twelfth century orin 1879, but by people who evidently hadtoo much time on their hands. The scoringsystem is our king, which matchesconsisting of sets, which consists ofgames. Games consist of points, where oneplayer or the other wins by causing theother player to hit the ball off the courtor into the net. Okay. We'll talk aboutscoring a game. One player is serverthroughout the game and two win the point,the game, you must score at least fourpoints. But, you also must win by at leasttwo points. Okay, so the inputs to ourautomaton are going to be S, which meansthat the server wins a point. And an O,meaning that the opponent wins a point. Itis common to represent the finiteautomaton by a graph, with notes forstates, and arrows labeled by the inputfor transitions. Here is the first stateof the automaton that scores tennis games.The name of the state is love. You mayask, what's love got to do, got to do withit. But that's what zero is called intennis. Love represents the history inwhich nothing has happened and we indicatethat history begins with a state by anarrow labeled start. [sound]. The firstpoint will be won by one of the twoplayers. So there are two transitions outof love. One labeled S, the other labeledO. Here are the transitions in the newstates. You might think the names of thestates would be one zero and zero one. Bythe way, the server's score is alwayslisted first in, scoring games. But that'snot quite right. In tennis, there's afiction that you score fifteen for winninga point. And zero of course is the zero,it's luck. Now the next point can lead tothree states. Two and one player has wonboth the points. And one where they'retied one each. Here are the states withtheir names. There's something interestingabout the [inaudible] all states. It isforgotten how we got there. We know thesequence of inputs was either s-o or o-s.But we don't know which. It doesn't matterof course. That's a good thing about[inaudible] at a time. They only rememberwhat must be remembered. And in statefifteen all, the question on who won firston the two points can't have any effect onthe outcome. After another point there arefour new states the game could be in. Theyhave the excepted names except people aretoo lazy to say'45' so they just say' 40'.Okay, now let's look at the transitionsfrom the state 40-love. The server's wellahead and can win on the next point, ifthe server wins, we go to a stateindicating that win. The game is over andthe atomaton has no further moves. Weindicate this output of the atomaton bythis state a final state and we indicateit is final by a double circle. There isanother final state reachable by the statelove-40 if the next indi-, input indicatesthat the opponent won the fourth point.Okay now there are three other new statesas well they're called 40 fifteen 30 alland fifteen 40 now each indicates thatfour points have been played with threetwo or one of these points one by theserver. From the 40 fifteen state, if theserver wins the point you go to the serverone state. But if the opponent wins thepoint. We go to a new state called 40 30.Similar things happen from fifteen 40. Andfrom 30 all, we can go either to 40 30 orthe 30 40 state. Now let's look at thestate 40 30. If the [inaudible] wins thenext point. They've won the game. But ifthe opponent wins the game is tied. Thename for this tied state is deuce. The dostate is quite interesting. It remembersthe game is tied. But it remembers neitherthe sequence of wins and losses of points,nor even how many points have been played.The 30, 40 state is handled similarly asthe same two transitions out. Now let'ssee what happens in deuce. You have to winby two points, so it's impossible foreither player to win immediately. If theserver wins they are ahead by one point,although we don't know how many pointstotal have been played. The strange namefor this state add-in, or advantage-in.And "in" refers to the server.Symmetrically if the opponent wins instate deuce we go to state add-out theadd... The out refers to the opponent. Nowlet's look at state add in. Okay, if theserver wins the next point they win thegame. But if the opponent wins, thenyou're back to deuce. Okay, likewise fromadd out a server we put you back in[inaudible] but when an opponent win givesthe opponent the game. We can now look atthe entire transition diagram for thefinite automaton. While most of it justallows flow away from the start state, theloops involving deuce add in and add out,allow for cycles, and for an infinitenumber of possible strings of S's andzeros that lead to one of the finalstates. The job of an [inaudible] is toprocess strings of input symbols or inputstrings. We always begin at the startstate and we read each input symbol inorder. For each input symbol, we allow thetransition from the state we were in todiscover what the new state is. We acceptthe string if we wind up in the finalstate after processing the entire input.Here is an example. We start in the,initial state as indicated by the, star.And the input is this sequence of S's andO's, so you can sort of see what hashappened. The server wins and the opponentwins, and the server wins, and they keepgoing back and forth. And then finally, atthe end, the opponent, I'm sorry, theserver wins, two points in a row. Andthereby, wins the game. So, we are in the,okay, we're in the start state. We'rereading an S, so we follow the transition.There, out of the, starred state on the S.And we go to the state fifteen Love. Nowwe are in the state fifteen Love, and, thenext input symbol is the O, which you cansee right there. And. From fifteen love onan O we're going to go to a fifteen allstate now we're in the fifteen all statewe see an S again so we follow it. To 30fifteen. Then from 30 fifteen, you see thestar is at. The third, is at 30 fifteen.We're reading an O. So it goes 30 all. Andhere is the sequence of, jump around quitea bit. Wind up in deuce. So we're going towin, we're going to add in. We're back todeuce, and we're back to add-in again. Nowwe're back to deuce. Finally we're back toserver wins gets us to add-in, yet again,but now the server wins and we wind up inthe server wins the game state. Now, let'sget a bit more formal. Okay, the job ofthe [inaudible] automaton is to processstrings of inputs, and accept or rejectthem. It accepts a string if it leads fromthe starred state to a final state. Andotherwise, it, rejects. Okay. Acceptingstate, by the way, is a synonym for finalstate. I'll use both of theminterchangeably. I think, it's fairlycommon. Nobody really knows which is thebest term for that idea. Okay, now, alanguage in the world of automata theory,is simply any set of strings whatsoever.It's got to be over some particular finitealphabet. But basically, it's just any,any set of strings, it could be a finiteset or an infinite set of strings. Andeach atomaton accepts some set of stringsthat is a language and we'll denote thatset of strings by, the notation will beLA. Now. In our tennis example, we callthe two state where one of the player winsthe final states. If that's our choice offinal states, and the language of thisfiner atomaton is a set of strings ofoutcomes that is strings over the alphabetS and zero. That in the game, and we don'tcare who wins. Okay. Now we could havemade another choice of final stage. Forexample if we had made only the[inaudible] final state then the[inaudible] will define a differentlanguage that is the set of outcomes thatlead to a win by the server in particular.Or we can make only the opponent winsstate the final. And then we would havethe language of sequences of points thatcause the opponent to win.