cisc 4090 theory of computation
play

CISC 4090: Theory of Computation Chapter 1 Regular Languages - PowerPoint PPT Presentation

CISC 4090: Theory of Computation Chapter 1 Regular Languages Section 1.1: Finite Automata Xiaolan Zhang, adapted from slides by Prof. Werschulz Fordham University Department of Computer and Information Sciences Spring, 2014 1 / 95 2 / 95


  1. CISC 4090: Theory of Computation Chapter 1 Regular Languages Section 1.1: Finite Automata Xiaolan Zhang, adapted from slides by Prof. Werschulz Fordham University Department of Computer and Information Sciences Spring, 2014 1 / 95 2 / 95 What is a computer? Finite automata Models of computers with extremely limited memory ◮ Not a simple question to answer precisely ◮ Many simple computers have extremely limited memories and ◮ Computers are quite complicated are (in fact) finite state machines. ◮ We start with a computational model ◮ Can you name any? (Hint: several are in this building, but ◮ Different models will have different features, and may match a have nothing specifically to do with our department.) real computer better in some ways, and worse in others ◮ Vending machine ◮ Our first model is the finite state machine or finite state ◮ Elevators ◮ Thermostat automaton ◮ Automatic door at supermarket 3 / 95 4 / 95

  2. Automatic door Automatic door (cont’d) ◮ What is the desired behavior? Describe the actions and then front , rear , both rear , both , neither list the states. ◮ Person approaches, door should open front ◮ Door should stay open while person going through ◮ Door should shut if no one near doorway ◮ States are Open and Closed closed open ◮ More details about automatic door ◮ Components: front pad, door, rear pad ◮ Describe behavior now: neither ◮ Hint: action depends not only on what happens, but also on current state neither front rear both ◮ If you walk through, door should stay open when you’re on closed closed open closed closed rear pad open closed open open open ◮ But if door is closed and someone steps on rear pad, door does not open 5 / 95 6 / 95 More on finite automata A finite automaton M 1 1 0 0 1 q 1 q 2 q 3 ◮ How may bits of data does this FSM store? ◮ 1 bit: open or closed 0,1 ◮ What about state information for elevators, thermostats, vending machines, etc.? Finite automaton M 1 with three states: ◮ FSM used in speech processing, special character recognition, ◮ We see the state diagram compiler construction . . . ◮ Start state q 1 ◮ Have you implemented an FSM? When? ◮ Accept state q 2 (double circle) ◮ Several transitions ◮ Network protocol for the game “Hangman” ◮ A string like 1101 will be accepted if M 1 ends in accept state, and rejects otherwise. What will it do? ◮ Can you describe all strings that M 1 will accept? ◮ All strings ending in 1 , and ◮ All strings having an even number of 0 ’s following the final 1 7 / 95 8 / 95

  3. Formal definition of finite state automata Describe M 1 using formal definition 0 1 0 1 q 1 q 2 q 3 A finite (state) automaton (FA) is a 5-tuple ( Q , Σ , δ, q 0 , F ): 0,1 ◮ Q is a finite set of states ◮ Σ is a finite set, called the alphabet M 1 = ( Q , Σ , δ, q 0 , F ), where ◮ δ : Q × Σ → Q is the transition function ◮ Q = { q 1 , q 2 , q 3 } ◮ q 0 ∈ Q is the start state ◮ Σ = { 0 , 1 } ◮ q 1 is the start state ◮ F ⊆ Q is the set of accepting (or final ) states . ◮ F = { q 2 } (only one accepting state) ◮ Transition function δ given by δ 0 1 q 1 q 1 q 2 q 2 q 3 q 2 q 3 q 2 q 2 9 / 95 10 / 95 The language of an FA What is the language of M 1 ? ◮ We write L ( M 1 ) = A , i.e., M 1 recognizes A . ◮ If A is the set of all strings that a machine M accepts, then A ◮ What is A ? is the language of M . ◮ A = { w ∈ { 0 , 1 } ∗ : . . . } . ◮ Write L ( M ) = A . ◮ We have ◮ Also say that M recognizes or accepts A . ◮ A machine may accept many strings, but only one language. w ∈ { 0 , 1 } ∗ : w contains at least one 1 � A = ◮ Convention: M accepts strings but recognizes a language . � and an even number of 0 ’s follow the last 1 11 / 95 12 / 95

  4. What is the language of M 2 ? What is the language of M 3 ? 0 1 1 0 1 1 q 1 q 2 q 1 q 2 0 0 ◮ M 3 = {{ q 1 , q 2 } , { 0 , 1 } , δ, q 1 , { q 1 }} is M 2 , but with accept M 2 = {{ q 1 , q 2 } , { 0 , 1 } , δ, q 1 , { q 2 }} where state set { q 1 } instead of { q 2 } . ◮ I leave δ as an exercise. ◮ What is the language of M 3 ? ◮ What is the language of M 2 ? ◮ L ( M 3 ) = { w ∈ { 0 , 1 } ∗ : . . . } . ◮ L ( M 2 ) = { w ∈ { 0 , 1 } ∗ : . . . } . ◮ Guess L ( M 3 ) = { w ∈ { 0 , 1 } ∗ : w ends in a 0 } . ◮ L ( M 2 ) = { w ∈ { 0 , 1 } ∗ : w ends in a 1 } . Not quite right. Why? ◮ L ( M 3 ) = { w ∈ { 0 , 1 } ∗ : w = ε or w ends in a 0 } . 13 / 95 14 / 95 What is the language of M 4 ? Construct M 5 to do modular arithmetic ◮ M 4 is a five-state automaton (Figure 1.12 on page 38). ◮ Let Σ = {� reset � , 0 , 1 , 2 } . ◮ What does M 4 accept? ◮ All strings that start and end with a or start and end with b . ◮ Construct M 5 to accept a string iff the sum of each input ◮ More simply, L ( M 4 ) is all strings starting and ending with the symbol is a multiple of 3, and � reset � sets the sum back to 0. same symbol. ◮ Note that string of length 1 is okay. 15 / 95 16 / 95

  5. Now generalize M 5 Formal definition of acceptance ◮ Generalize M 5 to accept if sum of symbols is a multiple of i instead of 3. Let M = ( Q , Σ , δ, Q 0 , F ) be an FA and let w = w 1 w 2 . . . w n ∈ Σ ∗ . M = {{ q 0 , q 1 , q 2 , . . . , q i − 1 } , { 0 , 1 , 2 , � reset �} , δ i , q 0 , { q 0 }} , We say that M accepts w if there exists a sequence r 0 , r 1 , . . . , r n ∈ Q of states such that where ◮ r 0 = q 0 . ◮ δ i ( q j , 0 ) = q j . ◮ δ i ( q j , 1 ) = q k , where k = j + 1 mod i . ◮ δ ( r i , w i +1 ) = r i +1 for i ∈ { 0 , 1 , . . . , n − 1 } ◮ δ i ( q j , 2 ) = q k , where k = j + 2 mod i . ◮ r n ∈ F . ◮ δ i ( q j , � reset � ) = q 0 . ◮ Note: As long as i is finite, we are okay and only need finite memory (number of states). ◮ Could you generalize to Σ = { 0 , 1 , 2 , . . . , k } ? 17 / 95 18 / 95 Regular languages Designing automata ◮ You will need to design an FA that accept a given language L . ◮ Strategies: A language L is regular if it is recognized by some finite ◮ Determine what you need to remember (The states). automaton. ◮ How many states to determine even/odd number of 1 ’s in an ◮ That is, there is a finite automaton M such that L ( M ) = A , input? i.e., M accepts all of the strings in the language, and rejects ◮ What does each state represent? all strings not in the language. ◮ Set the start and finish states, based on what each state ◮ Why should you expect proofs by construction coming up in represents. ◮ Assign the transitions. your next homework? ◮ Check your solution: it should accept every w ∈ L , and it should not accept any w �∈ L . ◮ Be careful about ε . 19 / 95 20 / 95

  6. You try designing FA Regular operations Let A and B be languages. We define three regular operations : ◮ Design an FA to accept the language of binary strings having ◮ Union : A ∪ B = { x : x ∈ A or x ∈ B } . an odd number of 1 ’s (page 43). ◮ Concatenation : A · B = { xy : x ∈ A and y ∈ B } . ◮ Design an FA to accept all strings containing the ◮ Kleene star : A ∗ = { x 1 x 2 . . . x k : k ≥ 0 and each x i ∈ A } . substring 001 (page 44). ◮ What do you need to remember? ◮ Kleene star is a unary operator on a single language. ◮ A ∗ consists of (possibly empty!) concatenations of strings ◮ Design an FA to accept strings containing the substring abab . from A . 21 / 95 22 / 95 Examples of regular operations Closure Let A = { good , bad } and B = { boy , girl } . What are the ◮ A set of objects is closed under an operation if applying that following? operations to members of that set always results in a member ◮ A ∪ B = { good , bad , boy , girl } . of that set. ◮ A · B = { goodboy , goodgirl , badboy , badgirl } . ◮ The natural numbers N = { 1 , 2 , . . . } are closed under ◮ A ∗ = addition and multiplication, but not subtraction or division. { ε, good , bad , goodgood , goodbad , badgood , badbad , . . . } . 23 / 95 24 / 95

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend