BU CS 332 โ Theory of Computation
Lecture 2:
- Deterministic Finite
Automata
- Regular Operations
- Non-deterministic FAs
Reading: Sipser Ch 1.1-1.2
Mark Bun January 27, 2020
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
Lecture 2:
Automata
Reading: Sipser Ch 1.1-1.2
Mark Bun January 27, 2020
1/26/2020 CS332 - Theory of Computation 2
Only works when stereo is ON, but source remembered when stereo is OFF
presses in {๐, ๐}โ leave the stereo ON in USB mode?
1/26/2020 CS332 - Theory of Computation 3
unstructured memory
1/26/2020 CS332 - Theory of Computation 4
Input ๐ ๐ ๐ ๐ Finite control โฆ
Control scans left-to-right
1/26/2020 CS332 - Theory of Computation 5
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
1/26/2020 CS332 - Theory of Computation 7
๐๐ 0,1 1 1 1 ๐๐ ๐๐ ๐๐
1/26/2020 CS332 - Theory of Computation 8
๐ is the set of states ฮฃ is the alphabet ๏ค โถ ๐ ร ฮฃ โ ๐ is the transition function ๐0 ๏ ๐ is the start state ๐บ โ ๐ is the set of accept states
A finite automaton is a 5-tuple ๐ = (๐ , ฮฃ, ๏ค, ๐0, ๐บ)
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 9
๐0 ๐1 ๐ ๐ ๐ ๐ State set ๐ = Alphabet ฦฉ = Transition function ๐ Start state ๐0 Set of accept states ๐บ =
๐ ๐ ๐ ๐0 ๐1
1/26/2020 CS332 - Theory of Computation 10
๐(๐) = the language of machine ๐ = set of all (finite) strings machine ๐ accepts ๐ recognizes the language ๐(๐) A DFA ๐ = (๐ , ฮฃ, ๏ค, ๐0, ๐บ) accepts a string ๐ฅ = ๐ฅ1๐ฅ2 ยท ยท ยท ๐ฅ๐ โ ฮฃโ (where each ๐ฅ๐ โ ฮฃ) if there exist ๐
0, . . . , ๐ ๐ โ ๐ such that
1. ๐
0 = ๐0
2. ๐(๐
๐, ๐ฅ๐+1) = ๐ ๐+1 for each ๐ = 0, . . . , ๐ โ 1, and
๐ โ ๐บ
1/26/2020 CS332 - Theory of Computation 11
๐0 ๐1 ๐ ๐ ๐ ๐ A DFA ๐ = (๐ , ฮฃ, ๏ค, ๐0, ๐บ) accepts a string ๐ฅ = ๐ฅ1๐ฅ2 ยท ยท ยท ๐ฅ๐ โ ฮฃโ (where each ๐ฅ๐ โ ฮฃ) if there exist ๐
0, . . . , ๐ ๐ โ ๐ such that
1. ๐
0 = ๐0
2. ๐(๐
๐, ๐ฅ๐+1) = ๐ ๐+1 for each ๐ = 0, . . . , ๐ โ 1, and
๐ โ ๐บ
Let ๐ฅ = ๐๐๐๐ Does ๐ accept ๐ฅ?
1/26/2020 CS332 - Theory of Computation 12
http://automatatutor.com/
1/26/2020 CS332 - Theory of Computation 13
Definition: A language is regular if it is recognized by a DFA
๐ด = { ๐ โ ๐, ๐ โ| ๐ contains ๐๐๐ } is regular ๐ด = { ๐ โ ๐, ๐ โ | ๐ has an even number of ๐โs } is regular
Many interesting programs recognize regular languages
NETWORK PROTOCOLS COMPILERS GENETIC TESTING ARITHMETIC
1/26/2020 CS332 - Theory of Computation 14
Let TCPS = { ๐ฅ | ๐ฅ is a complete TCP Session}
1/26/2020 CS332 - Theory of Computation 15
Comments : Are delimited by /* */ Cannot have nested /* */ Must be closed by */ */ is illegal outside a comment
COMMENTS = {strings over {0,1, /, *} with legal comments}
1/26/2020 CS332 - Theory of Computation 16
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}
1/26/2020 CS332 - Theory of Computation 17
LET ๏3 =
๐๐ + ๐๐๐ + โฆ + ๐๐ถ๐๐ถ.
โ | ROW1 + ROW2 = ROW3 }
1 1 1 1 1 1 1 1 1 1 1 1
1/26/2020 CS332 - Theory of Computation 18
In algebra, we try to identify operations which are common to many different mathematical structures
1/26/2020 CS332 - Theory of Computation 19
Example: The integers โค = {โฆ โ 2, โ1, 0, 1, 2, โฆ } are closed under
Weโd like to investigate similar closure properties of the class of regular languages
Let ๐ต, ๐ถ โ ฮฃโ be languages. Define Union: ๐ต โช ๐ถ = Concatenation: ๐ต โ ๐ถ = Star: ๐ตโ =
1/26/2020 CS332 - Theory of Computation 20
Let ๐ต, ๐ถ โ ฮฃโ be languages. Define Complement: าง ๐ต = Intersection: ๐ต โฉ ๐ถ = Reverse: ๐ต๐ =
1/26/2020 CS332 - Theory of Computation 21
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
1/26/2020 CS332 - Theory of Computation 22
1/26/2020 CS332 - Theory of Computation 23
Complement: าง ๐ต = ๐ฅ ๐ฅ โ ๐ต} Theorem: If ๐ต is regular, then าง ๐ต is also regular Proof idea:
1/26/2020 CS332 - Theory of Computation 24
1/26/2020 CS332 - Theory of Computation 25
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 26
๐0
๐ต
๐1
๐ต
1 1
๐0
๐ถ
๐1
๐ถ
1 1
๐ต๐ฉ ๐ต๐ช
Idea: Run both ๐๐ต and ๐๐ถ at the same time โCross-product constructionโ ๐ = ๐ ๐ต ร ๐ ๐ถ = {(๐๐ต, ๐๐ถ) |๐๐ต โ ๐ต and ๐๐ถ โ ๐ถ} ๏ค( (๐๐ต, ๐๐ถ), ๏ณ) = (๏ค๐ต(๐๐ต, ๏ณ), ๏ค๐ถ(๐๐ถ, ๏ณ)) ๐0 = (๐0
๐ต, ๐0 ๐ถ)
๐บ = {(๐๐ต, ๐๐ถ) |๐๐ต โ ๐บ๐ต or ๐๐ถ โ ๐บ๐ถ} = ๐บ๐ต ร ๐ ๐ถ โช ๐ ๐ต ร ๐บ๐ถ
1/26/2020 CS332 - Theory of Computation 27
1/26/2020 CS332 - Theory of Computation 28
๐0
๐ต
๐1
๐ต
1 1
๐0
๐ถ
๐1
๐ถ
1 1
๐ต๐ฉ
๐ต๐ช
1/26/2020 CS332 - Theory of Computation 29
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 30
Intersection: ๐ต โฉ ๐ถ = ๐ฅ ๐ฅ โ ๐ต and ๐ฅ โ ๐ถ} Theorem: If ๐ต and ๐ถ are regular, then so is ๐ต โฉ ๐ถ Another Proof: ๐ต โฉ ๐ถ = าง ๐ต โช เดค ๐ถ
1/26/2020 CS332 - Theory of Computation 31
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
1/26/2020 CS332 - Theory of Computation 32
1 1 1 0,1
๐ต ๐ตโฒ
none at all
1/26/2020 CS332 - Theory of Computation 33
1/26/2020 CS332 - Theory of Computation 34
1 1 1 0,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 35
1
๐ป ๐ป
1/26/2020 CS332 - Theory of Computation 36
0,1 0,๐ป 1 0,1 1
1/26/2020 CS332 - Theory of Computation 37
๐ is the set of states ฮฃ is the alphabet ๏ค โถ ๐ ร ฮฃ๐ โ ๐(๐ ) is the transition function ๐0 ๏ ๐ is the start state ๐บ โ ๐ is the set of accept states
An NFA is a 5-tuple ๐ = (๐ , ฮฃ, ๏ค, ๐0, ๐บ)
๐ accepts a string ๐ฅ if there exists a path from ๐0 to an accept state that can be followed by reading ๐ฅ.
1/26/2020 CS332 - Theory of Computation 38
1 ๐ป ๐ป ๏ค(๐๐, ๐) = ๐ต = (๐น, ๐ป, ๏ค, ๐น๐, ๐ฎ) ๐น = {๐๐, ๐๐, ๐๐, ๐๐, ๐๐} ๐ป = {๐, ๐} ๐ฎ = {๐๐} ๏ค(๐๐, ๐) = ๐๐ ๐๐ ๐๐ ๐๐ ๐๐
1/26/2020 CS332 - Theory of Computation 39
0,1 0,๐ป 1 0,1 1 ๐๐ ๐๐ ๐๐ ๐๐ ๐ถ = (๐น, ๐ป, ๏ค, ๐๐, ๐ฎ) ๐น = {๐๐, ๐๐, ๐๐, ๐๐} ๐ป = {๐, ๐} ๐ฎ = {๐๐} ๏ค(๐๐, ๐) = ๏ค(๐๐, ๐) = ๏ค(๐๐, ๐) = ๏ค(๐๐, ๐ป) =
1/26/2020 CS332 - Theory of Computation 40
Ways to think about nondeterminism
parallel computation
computations
verifying the โrightโ choice Deterministic Computation Nondeterministic Computation accept or reject accept reject