bu cs 332 theory of computation
play

BU CS 332 Theory of Computation Lecture 2: Reading: Deterministic - PowerPoint PPT Presentation

BU CS 332 Theory of Computation Lecture 2: Reading: Deterministic Finite Automata Sipser Ch 1.1-1.2 Regular Operations Non-deterministic FAs Mark Bun January 27, 2020 Deterministic Finite Automata 1/26/2020 CS332 - Theory


  1. BU CS 332 – Theory of Computation Lecture 2: Reading: • Deterministic Finite Automata Sipser Ch 1.1-1.2 • Regular Operations • Non-deterministic FAs Mark Bun January 27, 2020

  2. Deterministic Finite Automata 1/26/2020 CS332 - Theory of Computation 2

  3. A (Real-Life?) Example • Example: Car stereo • 𝑄 = Power button (ON/OFF) • 𝑇 = Source button (cycles through Radio/Bluetooth/USB) Only works when stereo is ON, but source remembered when stereo is OFF • Starts OFF in Radio mode • A computational problem: Does a sequence of button presses in {𝑄, 𝑇} ∗ leave the stereo ON in USB mode? 1/26/2020 CS332 - Theory of Computation 3

  4. Machine Models • Finite Automata (FAs): Machine with a finite amount of unstructured memory Input 𝑄 𝑇 𝑄 𝑇 … Control scans left-to-right Finite control 1/26/2020 CS332 - Theory of Computation 4

  5. A DFA for the car stereo problem 1/26/2020 CS332 - Theory of Computation 5

  6. A DFA for Parity Parity: Given a string consisting of 𝑏 ’s and 𝑐 ’s, does it contain an even number of 𝑏 ’s? Ʃ = {𝑏, 𝑐} 𝑀 = {𝑥 | 𝑥 contains an even number of 𝑏 ’s } 1/26/2020 CS332 - Theory of Computation 6

  7. Anatomy of a DFA 1 𝒓 𝟐 0 0,1 1 𝒓 𝟏 𝒓 𝟑 0 0 1 𝒓 𝟒 1/26/2020 CS332 - Theory of Computation 7

  8. Formal Definition of a DFA A finite automaton is a 5-tuple 𝑁 = (𝑅, Σ,  , 𝑟 0 , 𝐺) 𝑅 is the set of states Σ is the alphabet  ∶ 𝑅 × Σ → 𝑅 is the transition function 𝑟 0  𝑅 is the start state 𝐺 ⊆ 𝑅 is the set of accept states 1/26/2020 CS332 - Theory of Computation 8

  9. A DFA for Parity Parity: Given a string consisting of 𝑏 ’s and 𝑐 ’s, does it contain an even number of 𝑏 ’s? Ʃ = {𝑏, 𝑐} 𝑀 = {𝑥 | 𝑥 contains an even number of 𝑏 ’s } State set 𝑅 = Alphabet Ʃ = 𝑐 𝑐 Transition function 𝜀 𝜀 𝑏 𝑐 𝑏 𝑟 0 𝑟 0 𝑟 1 𝑟 1 𝑏 Start state 𝑟 0 Set of accept states 𝐺 = 1/26/2020 CS332 - Theory of Computation 9

  10. Formal Definition of DFA Computation A DFA 𝑁 = (𝑅, Σ,  , 𝑟 0 , 𝐺) accepts a string 𝑥 = 𝑥 1 𝑥 2 · · · 𝑥 𝑜 ∈ Σ ∗ (where each 𝑥 𝑗 ∈ Σ ) if there exist 𝑠 0 , . . . , 𝑠 𝑜 ∈ 𝑅 such that 𝑠 0 = 𝑟 0 1. 2. 𝜀(𝑠 𝑗 , 𝑥 𝑗+1 ) = 𝑠 𝑗+1 for each 𝑗 = 0, . . . , 𝑜 − 1, and 3. 𝑠 𝑜 ∈ 𝐺 𝑀(𝑁) = the language of machine 𝑁 = set of all (finite) strings machine 𝑁 accepts 𝑁 recognizes the language 𝑀(𝑁) 1/26/2020 CS332 - Theory of Computation 10

  11. Example: Computing with the Parity DFA 𝑐 𝑐 Let 𝑥 = 𝑏𝑐𝑐𝑏 Does 𝑁 accept 𝑥 ? 𝑏 𝑟 0 𝑟 1 𝑏 A DFA 𝑁 = (𝑅, Σ,  , 𝑟 0 , 𝐺) accepts a string 𝑥 = 𝑥 1 𝑥 2 · · · 𝑥 𝑜 ∈ Σ ∗ (where each 𝑥 𝑗 ∈ Σ ) if there exist 𝑠 0 , . . . , 𝑠 𝑜 ∈ 𝑅 such that 𝑠 0 = 𝑟 0 1. 𝜀(𝑠 𝑗 , 𝑥 𝑗+1 ) = 𝑠 𝑗+1 for each 𝑗 = 0, . . . , 𝑜 − 1, and 2. 3. 𝑠 𝑜 ∈ 𝐺 1/26/2020 CS332 - Theory of Computation 11

  12. Automata Tutor http://automatatutor.com/ 1/26/2020 CS332 - Theory of Computation 12

  13. Regular Languages Definition: A language is regular if it is recognized by a DFA 𝑴 = { 𝒙 ∈ 𝒃, 𝒄 ∗ | 𝒙 has an even number of 𝒃 ’s } is regular 𝑴 = { 𝒙 ∈ 𝟏, 𝟐 ∗ | 𝒙 contains 𝟏𝟏𝟐 } is regular Many interesting programs recognize regular languages NETWORK PROTOCOLS COMPILERS GENETIC TESTING ARITHMETIC 1/26/2020 CS332 - Theory of Computation 13

  14. Internet Transmission Control Protocol Let TCPS = { 𝑥 | 𝑥 is a complete TCP Session} Theorem. TCPS is regular 1/26/2020 CS332 - Theory of Computation 14

  15. Compilers Comments : Are delimited by /* */ Cannot have nested /* */ Must be closed by */ */ is illegal outside a comment COMMENTS = {strings over {0,1, /, *} with legal comments} Theorem. COMMENTS is regular. 1/26/2020 CS332 - Theory of Computation 15

  16. Genetic Testing DNA sequences are strings over the alphabet {𝑩, 𝑫, 𝑯, 𝑼}. A gene 𝒉 is a special substring over this alphabet. A genetic test searches a DNA sequence for a gene. GENETICTEST 𝒉 = {strings over {𝑩, 𝑫, 𝑯, 𝑼} containing 𝒉 as a substring} Theorem. GENETICTEST 𝒉 is regular for every gene 𝒉 . 1/26/2020 CS332 - Theory of Computation 16

  17. Arithmetic { [ ],[ ],[ ],[ ], 0 0 0 0 LET  3 = 0 0 1 1 0 1 0 1 [ ],[ ],[ ],[ ]} 1 1 1 1 0 0 1 1 0 1 0 1 • A string over  3 has three ROWS (ROW 1 , ROW 2 , ROW 3 ) • Each ROW 𝒄 𝟏 𝒄 𝟐 𝒄 𝟑 … 𝒄 𝑶 represents the integer 𝒄 𝟏 + 𝟑𝒄 𝟐 + … + 𝟑 𝑶 𝒄 𝑶 . ∗ | ROW 1 + ROW 2 = ROW 3 } • Let ADD = { 𝑻 ∈  𝟒 Theorem. ADD is regular. 1/26/2020 CS332 - Theory of Computation 17

  18. Regular Operations 1/26/2020 CS332 - Theory of Computation 18

  19. An Analogy In algebra, we try to identify operations which are common to many different mathematical structures Example: The integers ℤ = {… − 2, −1, 0, 1, 2, … } are closed under • Addition: 𝑦 + 𝑧 • Multiplication: 𝑦 × 𝑧 • Negation: −𝑦 • …but NOT Division: 𝑦 / 𝑧 We’d like to investigate similar closure properties of the class of regular languages 1/26/2020 CS332 - Theory of Computation 19

  20. Regular operations on languages Let 𝐵, 𝐶 ⊆ Σ ∗ be languages. Define Union: 𝐵 ∪ 𝐶 = Concatenation: 𝐵 ∘ 𝐶 = Star: 𝐵 ∗ = 1/26/2020 CS332 - Theory of Computation 20

  21. ҧ Other operations Let 𝐵, 𝐶 ⊆ Σ ∗ be languages. Define 𝐵 = Complement: Intersection: 𝐵 ∩ 𝐶 = Reverse: 𝐵 𝑆 = 1/26/2020 CS332 - Theory of Computation 21

  22. Closure properties of the regular languages Theorem: The class of regular languages is closed under all three regular operations (union, concatenation, star), as well as under complement, intersection, and reverse. i.e., if 𝐵 and 𝐶 are regular, applying any of these operations yields a regular language 1/26/2020 CS332 - Theory of Computation 22

  23. Proving Closure Properties 1/26/2020 CS332 - Theory of Computation 23

  24. Complement 𝐵 = 𝑥 𝑥 ∉ 𝐵} Complement: ҧ Theorem: If 𝐵 is regular, then ҧ 𝐵 is also regular Proof idea: 1/26/2020 CS332 - Theory of Computation 24

  25. Union Union: 𝐵 ∪ 𝐶 = 𝑥 𝑥 ∈ 𝐵 or 𝑥 ∈ 𝐶} Theorem: If 𝐵 and 𝐶 are regular, then so is 𝐵 ∪ 𝐶 Proof: Let 𝑁 𝐵 = (𝑅 𝐵 , Σ,  𝐵 , 𝑟 0 𝐵 , 𝐺 𝐵 ) be a DFA recognizing 𝐵 and 𝑁 𝐶 = (𝑅 𝐶 , Σ,  𝐶 , 𝑟 0 𝐶 , 𝐺 𝐶 ) be a DFA recognizing 𝐶 Goal: Construct a DFA 𝑁 = 𝑅, Σ,  , 𝑟 0 , 𝐺 that recognizes 𝐵 ∪ 𝐶 1/26/2020 CS332 - Theory of Computation 25

  26. Example 0 0 𝑵 𝑩 1 𝐵 𝐵 𝑟 1 𝑟 0 1 1 1 𝑵 𝑪 0 𝑵 = ? 𝐶 𝐶 𝑟 0 𝑟 1 0 1/26/2020 CS332 - Theory of Computation 26

  27. Closure under union proof (cont’d) Idea: Run both 𝑁 𝐵 and 𝑁 𝐶 at the same time “Cross - product construction” 𝑅 = 𝑅 𝐵 × 𝑅 𝐶 = {(𝑟 𝐵 , 𝑟 𝐶 ) |𝑟 𝐵 ∈ 𝐵 and 𝑟 𝐶 ∈ 𝐶}  ( (𝑟 𝐵 , 𝑟 𝐶 ),  ) = (  𝐵 (𝑟 𝐵 ,  ),  𝐶 (𝑟 𝐶 ,  )) 𝐵 , 𝑟 0 𝐶 ) 𝑟 0 = (𝑟 0 𝐺 = {(𝑟 𝐵 , 𝑟 𝐶 ) |𝑟 𝐵 ∈ 𝐺 𝐵 or 𝑟 𝐶 ∈ 𝐺 𝐶 } = 𝐺 𝐵 × 𝑅 𝐶 ∪ 𝑅 𝐵 × 𝐺 𝐶 1/26/2020 CS332 - Theory of Computation 27

  28. Example (cont’d) 0 𝑵 0 𝑵 𝑩 1 𝐵 𝐵 𝑟 1 𝑟 0 1 1 1 𝑵 𝑪 0 𝐶 𝐶 𝑟 0 𝑟 1 0 1/26/2020 CS332 - Theory of Computation 28

  29. Intersection Intersection: 𝐵 ∩ 𝐶 = 𝑥 𝑥 ∈ 𝐵 and 𝑥 ∈ 𝐶} Theorem: If 𝐵 and 𝐶 are regular, then so is 𝐵 ∩ 𝐶 Proof: Let 𝑁 𝐵 = (𝑅 𝐵 , Σ,  𝐵 , 𝑟 0 𝐵 , 𝐺 𝐵 ) be a DFA recognizing 𝐵 and 𝑁 𝐶 = (𝑅 𝐶 , Σ,  𝐶 , 𝑟 0 𝐶 , 𝐺 𝐶 ) be a DFA recognizing 𝐶 Goal: Construct a DFA 𝑁 = 𝑅, Σ,  , 𝑟 0 , 𝐺 that recognizes 𝐵 ∩ 𝐶 1/26/2020 CS332 - Theory of Computation 29

  30. Intersection Intersection: 𝐵 ∩ 𝐶 = 𝑥 𝑥 ∈ 𝐵 and 𝑥 ∈ 𝐶} Theorem: If 𝐵 and 𝐶 are regular, then so is 𝐵 ∩ 𝐶 Another Proof: ത 𝐵 ∩ 𝐶 = ҧ 𝐵 ∪ 𝐶 1/26/2020 CS332 - Theory of Computation 30

  31. Reverse Reverse: 𝐵 𝑆 = 𝑥 1 𝑥 2 · · · 𝑥 𝑜 𝑥 𝑜 · · · 𝑥 1 ∈ 𝐵} Theorem: If 𝐵 is regular, then 𝐵 𝑆 is also regular Proof idea: Let 𝑁 = (𝑅, Σ,  , 𝑟 0 , 𝐺) be a DFA recognizing 𝐵 ′ , 𝐺′ Goal: Construct a DFA 𝑁′ = 𝑅′, Σ,  ′, 𝑟 0 that recognizes 𝐵 𝑆 Define 𝑁′ as 𝑁 but • With the arrows reversed • With start and accept states swapped 1/26/2020 CS332 - Theory of Computation 31

  32. Example (Reverse) 0,1 1 0 𝑵 0 0 1 1 𝑵′ 1/26/2020 CS332 - Theory of Computation 32

  33. Closure under reverse 𝑁’ is not always a DFA! • It might have many start states • Some states may have too many outgoing edges, or none at all 1/26/2020 CS332 - Theory of Computation 33

  34. Nondeterminism 1 0,1 0 0 0 1 1 A Nondeterministic Finite Automaton (NFA) accepts if there is a way to make it reach an accept state. 1/26/2020 CS332 - Theory of Computation 34

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