Download presentation
Presentation is loading. Please wait.
1
FSM: What’s it all about?
MA/CSSE 474 Theory of Computation FSM: What’s it all about? Show announcements at the beginning of class (on extended screen) Initially, do not print slides 20-22 Take to class: Markers A 2-up, 2-sided color page with slides Announcements
2
Instructor/Course Intro Tomorrow
…along with roll call and other “first day” stuff Today: A look at DFSMs to give you the flavor for some major course ingredients Turn in your reading quiz. Another one due tomorrow at start of class. Feel free to ask questions/make comments at any point. Don't wait until I stop and ask Optional Q&A session Tuesday afternoon: Answers to your questions about the review material. 4:20 PM in O257 Go to schedule page. Point out: Syllabus Reading assignments, quiz due Tuesday There will not be a reading quiz every day. HW1 due Friday. HW most Tuesdays and Fridays (Mondays on exam days) Extra session tomorrow afternoon. Quiz solutions available on Moodle
3
DFSM* Overview MA/CSSE 474 vs. MA375 Same concept
Some different perspectives Several different notations DFSM: a formal mathematical model of computation A DFSM can remember only a fixed amount of info That info is represented by the DFSM’s current state Its state changes in response to input symbols A transition function describes how the state changes We’ll provide more context, formalisms, and "why's" later. It can only describe certain limited kinds of computation. We will see more powerful models later. Models of computation is the main theme of this course. * DFSM stands for Deterministic Finite State Machine a.k.a. Deterministic Finite Automaton (DFA)
4
"Physical" DFSM Model Input is finite, head only moves right
5
Scoring Tennis(J.U. example)
One person serves throughout a game To win, you must score at least 4 points You also must win by at least 2 points Inputs are: s means “server wins a point” and o means “opponent wins a point” State names are pairs of scores (the names they are called in tennis: love, 15, 30, 40, …) 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.”
6
Consider the input: s o s o s o s o s o s s
s = server o = 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-all Here’s the first state of the automaton that scores tennis games. The name of this state is Love-Love. That’s what “zero” is called in tennis. When the Beatles sang, “All you need is Love”, they weren’t thinking Tennis scoring! Click 1 The state “Love-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. 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 doesn’t affect 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 Each indicates that four points have been played, with 3, 2, or 1 of these points won by the server. Click 7 From the 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 A similar thing happens from 15-40, and from 30-all we can go to either the or the state. Click 8 Now, let’s look at state 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 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. Consider the input: s o s o s o s o s o s s Accepting states (a.k.a. Final states)
7
Notation: Alphabet, String, Language
Alphabet Σ: finite set of symbols. Examples: ASCII, Unicode, signals, {0, 1}, {a, b, c}, {s, o} String over an alphabet Σ: a finite sequence of symbols. Examples: 011, abc, sooso, ε Note: 0 as string, 0 as symbol look the same Context determines type ε is the empty string (some authors use λ) Σ*: the set of all strings over the alphabet Σ A Language over Σ is any subset of Σ*
8
Convention: Strings and Symbols
… u, v, w, x, y, z will usually represent strings a, b, c,… will usually represent single input symbols When we write w=ua, we mean that a is the last symbol of string w, and that u is the substring consisting of everything in w that comes before that a This convention is similar to early FORTRAN, where variables beginning with I – N were INT and any other latter REAL. It lets us know the types of things without declaring types. In particular we can distinguish between strings and characters.
9
DFSM - formal definition
M = (K, Σ, δ, s, A) Σ is the (finite) alphabet K is the (finite) set of states (some authors: Q) s ∊ K is the start state A ⊆ K is the set of accepting states (some authors use F, for final states) δ: K × Σ→K is the transition function Usually specified as a table or graph
10
More on the Transition Function
δ takes two arguments: a state and an input symbol δ(q, a) = the state that the DFSM goes to next after it is in state q and the tape head reads input a. Note: there is always a next state – we add a dead state wherever there is no explicitly given transition (Example on next slide)
11
Tennis score DFSM after addition of dead state
Server Wins Opp’nt s o s o Love-40 15-30 30-15 40-Love s o deuce s o Dead s, o 30-40 40-30 s o 40-15 15-40 30-all s o Ad-out Ad-in s o Love-30 15-all 30-Love s o 15-Love Start s Love-all o Love-15 Here is our tennis example. Notice that the two final states have no transitions out (POINT). Click 1 So we add a dead state, and all the missing transitions go to that state. The transitions from the dead state are to itself on all possible input symbols.
12
Example: words ending in “ing”
other none saw i saw in saw ing Transition table Two ways of denoting δ, the transition function Graph created with JFLAP. Check it out! Jflap.org Download the JAR file, double-click it (must have Java installed). In graph: Trace a couple of strings. In transition table: Rows = states, columns = input symbols. First state listed = start state, Indicate accepting states by some method(bold, color, asterisks) Transition graph
13
Example: strings without 11
{w∊{0,1}* : w does not have two consecutive 1’s} Can you draw the state diagram? This example and the following slides were inspired by JU; significantly modified by CWA. start Saw 1 dead Answer on later slides.
14
Extending the δ function
If we consider (as in Python) a character to be a string of length 1, we can extend δ to δ: K × Σ* → K as follows δ(q, ε) = q for every state q If u is a string and a is a single symbol, δ(q, ua) = δ(δ(q, u), a) Consider δ(q0, 010) for this DFSM: Example: δ(q0, 010) = δ(δ(q0, 01), 0) = δ(δ(δ(q0, 0), 1), 0) = δ(δ(q0, 1), 0) = δ(q1, 0) = q0 δ(q0, 010) = δ(δ(q0, 01), 0) = δ(δ(δ(q0, 0), 1), 0) = δ(δ(q0, 1), 0) = δ(q1, 0) = q0
15
The Language of a DFSM If M is an automaton (any variety of automaton), L(M) means “the language accepted by M.” If M=(K, Σ, δ, s, A) is a DFSM, then i.e., the set of all input strings that take the machine from its start state to an accepting state. L(M) = {w ∊ Σ* : δ(s, w) ∊ A} If this is M, what is L(M)?
16
Proving Set Equivalence
Often, we need to prove that two sets S and T are in fact the same set. What is the general approach? Here, S is “the language accepted by this DFSM,” and Tis “the set of strings of 0’s and 1’s with no consecutive pair of 1’s.” Before Click 1 Many important facts about automata that we might want to prove are of the form that two sets, typically languages or sets of strings, are really the same. How, in general, do we show this? First S ⊆ T and then T ⊆ S After Click 1 I’m going to spend some time proving this simple result, because it will give you all the details of how one proves things about languages. In the future, I’m not going to be so focused on proofs, but I think it is important that everyone go through at least one of these proofs in all its gory detail. Write on the board: the definitions of S and T.
17
Details of proof approach
In general, to prove S = T, we need to prove: S ⊆ T and T ⊆ S. That is: If a string w is in S, then w is in T. If w is in T, then w is in S. Those are usually two separate proofs. Here, S = the language of our DFSM, and T = “strings with no consecutive pair of 1’s.” Click 1 To prove two sets S and T equal, we generally need to prove two things: that each is contained in the other. Click 2 That is, we start by assuming w is a member of one, say S, and we use that fact to prove w is in the other – T. Click 3 Then, we start all over, and we assume w is in T. We use that to prove w is also in S. Click 4 In what follows, we take S to be the language of the DFA we have been playing with, and T will be the set of binary strings without consecutive 1’s
18
Part A: S ⊆ T To prove: if w is accepted by M,
then w does not have consecutive 1’s. Proof is by induction on |w|, the length of w. Important trick: Expand the inductive hypothesis to be more general than the statement you are trying to prove. Click 4 It turns out that if we simply try to prove this statement on the slide, we fail, and I’ll point out in a few slides what goes wrong. A common trick for inductive proofs is to make a more general statement than you really want, because it makes the inductive proof work. Here, we need to distinguish whether an accepted string gets you to state q0 or q1, because we need to know whether or not the string ends in 1, even though the conclusion, “no 11’s” is true in both states q0 and q1.
19
Prove S⊆T by induction on |w| :
More general statement we will prove: Both of the following statements are true: If δ(q0, w) = q0, then w does not end in 1 and w has no pair of consecutive 1’s. If δ(q0, w) = q1, w ends in 1 and w has no pair of consecutive 1’s. Base case: |w| = 0; i.e., w = ε. (1) holds since ε has no 1’s at all. (2) holds vacuously, since δ(q0, ε) is not q1. Can you see that (1) and (2) imply S⊆T? The inductive hypothesis will have two parts. Click 1 Part (1) says that if w gets you to state q0, then not only is w “good,” in the sense that it doesn’t have consecutive 1’s, but it also doesn’t end in 1. Click 2 Part (2) says that if w gets you to state q1, then w is still good, but it must end in 1. Click 3 Remember the induction is on the length of w, so the basis case is when w is the empty string, the only string of length 0. Click 4 We’re going to use bars around a string to denote its length. Now, let us prove part (1) of the basis. Delta(q0,empty string) (POINT in item 1) does equal q0, andthe conclusion is true, since the empty string does not have consecutive 1’s. For (2), things are a little trickier. It is false that delta(q0, empty string) = q1 (POINT in item 2), but it is also false that the empty string ends in 1. Click 5 However, an important principle of logic is that the statement “false implies false” is TRUE. That is, whenever the “if” portion of the statement is false, then it doesn’t matter whether the “then” portion is true or not – the statement as a whole is true. Thus a statement like “If I am Superman, then I wear red undershorts” is a true statement, simply because I am not Superman. You don’t have to concern yourself with the color of my undershorts. The mathematical term for an if-then statement that is true because the if part is false is that the statement HOLDS VACUOUSLY. Important logic rule: If the “if” part of any “if..then” statement is false, the whole statement is true.
20
Inductive Step for S ⊆ T Let |w| be ≥ 1, and assume (1) and (2) are true for all strings shorter than w. Because w is not empty, we can write w = ua, where a is the last symbol of w, and u is the string that precedes that last a. Since |u| < |w|, IH (induction hypothesis) is true for u. Now let’s address the inductive step. Click 1 We assume that w is a string of length at least 1, and we assume that the inductive hypothesis – the statements (1) and (2) from the previous slide about strings that get the automaton to states q0 or q1 – is true for strings shorter than w. Click 2 Let w = ua, where by our convention, “a” is the last symbol of w and x is all the symbols – possibly none – up to but not including the last symbol of w. Click 3 Since u is shorter than w, we can assume the induction hypothesis for u. Reminder: What we are proving by induction:
21
Inductive Step: S ⊆ T (2) Need to prove (1) and (2) for w = ua, assuming that they are true for u. (1) for w is: If δ(q0, w) = q0, then w has no consecutive 1’s and does not end in 1. Show it: Since δ(q0, w) = q0, δ(q0, u) must be q0 or q1, and a must be 0 (look at the DFSM). By the IH, u has no 11’s. The a is a 0. Thus, w has no 11’s and does not end in 1. Click 1 We are going to prove both statements (1) and (2) for w, which remember we broke up as shorter string x followed by last symbol “a”. Click 2 Let’s start with (1), that is if delta(q0,w) = q0, then w is good – it has no consecutive 1’s -- and does not end in 1. Click 3 How can you get to q0 by reading string u followed by symbol “a”? Well look at the diagram. The only transitions into q0 are on input 0 (POINT), so symbol “a” must be 0. That immediately lets us conclude that w does not end in 1. Furthermore, these transitions to q0 are only from q0 and q1. Thus, u must get us to q0 or q1. Click 4 Regardless of whether u gets us to q0 or q1, we can conclude, using the inductive hypothesis, that u is “good,” – it has no consecutive 1’s. Click 5 Thus, w, which is u followed by a 0, also has no consecutive 1’s and surely does not end in 1.
22
Inductive Step : S ⊆ T (3) Now, prove (2) for w = ua: If δ(q0, w) = q1, then w has no 11’s and ends in 1. Since δ(q0, w) = q1, δ(q0, u) must be q0, and a must be 1 (look at the DFSM). By the IH, u has no 11’s and does not end in 1. Thus, w has no 11’s and ends in 1. Click 1 Now for part 2: if delta(q0,w) = q1, then w is good and ends in 1. Click 2 There is only one way to get to q1. You have to be in state q0 and the input has to be 1 (POINT). Thus if w = u followed by “a”, then u gets us to state q0, and symbol “a” is 1. We can therefore conclude that w ends in 1. Click 3 Apply the inductive hypothesis to u, and we conclude that x not only has no consecutive 1’s, but it doesn’t end in 1. Click 4 Any occurrence of 11 in w would either have to be at the end or lie completely within u. We know it doesn’t lie within u, by the inductive hypothesis. We know 11 cannot be at the end, because u does not end in 1, and “a” is only a single 1. We conclude that w does not have consecutive 1’s. Notice that if we don’t use this more complicated inductive hypothesis, where we distinguish between q0 and q1 according to whether the string u ends in 1, then we cannot make the inductive proof. If we know only that u gets us to q0 or q1, then we might think that u gets us to state q0 yet ends in 1, in which case w = ua would have two consecutive 1’s.
23
Part B: T ⊆ S X Now, we must prove: if w has no 11’s, then w is accepted by M Contrapositive : If w is not accepted by M then w has 11 as a substring. Y Key idea: contrapositive of “if X then Y” is the equivalent statement “if not Y then not X.” We’re not done. We still have to prove that T is contained in S. That is, if w is a “good” string, with no consecutive 1’s, then it is accepted by the automaton. It is helpful to restate what we need to prove in its contrapositive form, which is logically equivalent to the original. Click 1 The contrapositive of an if-then statement, say “if X then Y” is “if not Y then not X.” We can see why this is an equivalent statement, since if Y is false, it couldn’t be that X is true, because whenever X is true, Y is true. Click 2 In this case, X is the statement that w is a good string, with no 11’s. Click 3 And Y is the statement that w is accepted by the automaton. The contrapositive is that if w is NOT accepted by the automaton, then w is NOT a good string, that is, it contains 11 as a substring.
24
Using the Contrapositive
Contrapositive : If w is not accepted by M then w has 11 as a substring. Base case is again vacuously true. Because there is a unique transition from every state on every input symbol, each w gets the DFSM to exactly one state. The only way w can not be accepted is if it gets to q2. How can this happen? A deterministic automaton has exactly one transition from each state on each input symbol. Thus, any string w gets the automaton from the start state to exactly one state. So the only way w could not be accepted is if it gets this automaton to state q2.
25
Using the Contrapositive – (2)
Looking at the DFSM, there are two possibilities: (recall that w=ua) δ(q0,u) = q1 and a is 1. We proved earlier that if δ(q0,u) = q1, then u ends in 1. Thus w ends in 11. δ(q0,u) = q2. In this case, the IH says that u contains 11 as a substring. So does w=ua. Click 1 Notice that the only way to get the automaton to q2 is for some string u to get it to q1, and then for an input 1 to follow. Once in q2, you stay in q2, so anything can follow the u and 1. Call that y. That is, any string w that gets the automaton to q2 must be of the form x1y, where x gets to q1. Click 2 We already observed that the only way to get to q1 is by a string that ends in 1, since the only transition into q1 is on 1. Thus, u must be of the form z1 for some z. Click 3 Thus, w = z11y and we can conclude that if delta(q0,w) = q2, then w is “bad,” that is, it contains two consecutive 1’s.
26
Your 474 HW induction proofs
Can be slightly less detailed Many of the details here were about how the proof process works in general, rather than about the proof itself. You can assume that the reader knows the proof techniques. Must always make it clear what the IH is, and where you apply it. When in doubt about whether to include a detail, include it! Well-constructed proofs often contain more words than symbols.
27
This Proof as a 474 HW Problem
An example of how I would write up this proof if it was a 474 HW problem will be linked from the schedule page this afternoon. You do not need to copy it exactly in your proofs, but it gives an idea of the kinds of things to include or not include. Also, I will post another version of the slides that includes the parts that I wrote on the board today.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.