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/29/2020 CS332


  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/29/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 ∗ leave the stereo ON in USB mode? presses in 1/29/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/29/2020 CS332 ‐ Theory of Computation 4

  5. A DFA for the car stereo problem 1/29/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/29/2020 CS332 ‐ Theory of Computation 6

  7. Anatomy of a DFA 1 𝒓 𝟐 0 0,1 1 𝒓 𝟏 𝒓 𝟑 0 0 1 𝒓 𝟒 1/29/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/29/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/29/2020 CS332 ‐ Theory of Computation 9

  10. Formal Definition of DFA Computation  A DFA accepts a string 0 ∗ (where each ) if there exist � � � � � , . . . , � such that 1. � � 2. ��� for each and � ��� 3. � = the language of machine = set of all (finite) strings machine accepts recognizes the language 1/29/2020 CS332 ‐ Theory of Computation 10

  11. Ex Exam ample: ple: Computing with the Parity DFA Let 𝑥 � 𝑏𝑐𝑐𝑏 Does 𝑁 accept 𝑥 ? 0 1  A DFA accepts a string 0 ∗ (where each ) if there exist � � � � � , . . . , � such that 1. � � 2. ��� for each and � ��� 3. � 1/29/2020 CS332 ‐ Theory of Computation 11

  12. Automata Tutor http://automatatutor.com/ 1/29/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/29/2020 CS332 ‐ Theory of Computation 13

  14. Internet Transmission Control Protocol Let TCPS = { | is a complete TCP Session} Theorem. TCPS is regular 1/29/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/29/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/29/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 𝟏 𝟐 𝟑 𝑶 𝑶 . 𝟏 𝟐 ∗  𝟒 • Let ADD = { | ROW 1 + ROW 2 = ROW 3 } Theorem. ADD is regular. 1/29/2020 CS332 ‐ Theory of Computation 17

  18. Regular Operations 1/29/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 are closed under • Addition: • Multiplication: × • Negation: • …but NOT Division: We’d like to investigate similar closure properties of the class of regular languages 1/29/2020 CS332 ‐ Theory of Computation 19

  20. Regular operations on languages ∗ be languages. Define Let Union: Concatenation: ∗ Star: 1/29/2020 CS332 ‐ Theory of Computation 20

  21. Other operations ∗ be languages. Define Let Complement: Intersection: � Reverse: 1/29/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/29/2020 CS332 ‐ Theory of Computation 22

  23. Proving Closure Properties 1/29/2020 CS332 ‐ Theory of Computation 23

  24. Complement Complement: Theorem: If is regular, then is also regular Proof idea: 1/29/2020 CS332 ‐ Theory of Computation 24

  25. Union Union: or Theorem: If and are regular, then so is Proof: �  𝐵 Let be a DFA recognizing and � 𝐵 𝐵 𝐵 �  𝐶 be a DFA recognizing � 𝐶 𝐶 𝐶  Goal: Construct a DFA � that recognizes 1/29/2020 CS332 ‐ Theory of Computation 25

  26. Example 0 0 𝑩 1 � � � � 1 1 1 𝑪 0 ? � � � � 0 1/29/2020 CS332 ‐ Theory of Computation 26

  27. Closure under union proof (cont’d) Idea: Run both 𝐵 and 𝐶 at the same time “Cross ‐ product construction” 𝐵 × 𝐶 � , � � �    𝐵 𝐵   𝐶 𝐶  𝐵 𝐶 � � � � � � , � � � 𝐵 𝐶 𝐵 × 𝐵 × 𝐶 𝐶 1/29/2020 CS332 ‐ Theory of Computation 27

  28. Example (cont’d) 0 0 𝑩 1 � � � � 1 1 1 𝑪 0 � � � � 0 1/29/2020 CS332 ‐ Theory of Computation 28

  29. Intersection Intersection: and Theorem: If and are regular, then so is Proof: �  𝐵 Let be a DFA recognizing and � 𝐵 𝐵 𝐵 �  𝐶 be a DFA recognizing � 𝐶 𝐶 𝐶  Goal: Construct a DFA � that recognizes 1/29/2020 CS332 ‐ Theory of Computation 29

  30. Intersection Intersection: and Theorem: If and are regular, then so is Another Proof: = 1/29/2020 CS332 ‐ Theory of Computation 30

  31. Reverse � Reverse: � � � � � � is also regular Theorem: If is regular, then Proof idea:  Let be a DFA recognizing � �  Goal: Construct a DFA � � that recognizes Define as but • With the arrows reversed • With start and accept states swapped 1/29/2020 CS332 ‐ Theory of Computation 31

  32. Example (Reverse) 0,1 1 0 𝑵 0 0 1 1 𝑵′ 1/29/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/29/2020 CS332 ‐ Theory of Computation 33

  34. Non 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/29/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