15-251 Great Theoretical Ideas in Computer Science Lecture 4: Deterministic Finite Automaton (DFA), Part 2 January 26th, 2017
Formal definition: DFA A deterministic finite automaton (DFA) is a 5-tuple M M = ( Q, Σ , δ , q 0 , F ) Q = { q 0 , q 1 , q 2 , q 3 } Σ = { 0 , 1 } δ : Q × Σ → Q δ 1 0 q 0 q 0 q 1 q 1 q 2 q 2 q 2 q 3 q 2 q 3 q 0 q 2 q 0 is the start state F = { q 1 , q 2 }
Formal definition: DFA accepting a string Let be a DFA. M = ( Q, Σ , δ , q 0 , F ) For , q ∈ Q, w ∈ Σ ∗ δ ( q, w ) = state we end up in when we start at q and read . w accepts if δ ( q 0 , w ) ∈ F. M w Otherwise rejects . M w
Definition: Regular languages Let be a DFA. M We let denote the set of strings that accepts . L ( M ) M Definition: A language is called regular if L for some DFA . L = L ( M ) M
Non-regular languages Theorem: L = { 0 n 1 n : n ∈ N } The language is not regular. Theorem: { a 2 n : n ∈ N } The language is not regular. L =
The big picture All languages P ( Σ ∗ ) Regular languages { 0 n 1 n : n ∈ N } { a 2 n : n ∈ N } . . . . . .
Regular languages Questions: 1 . Are all languages regular? (Are all decision problems computable by a DFA?) 2 . Are there other ways to tell if a language is regular?
Closure properties of regular languages
Closed under complementation Proposition: Let be some finite alphabet. Σ If is regular, then so is . L = Σ ∗ \ L L ⊆ Σ ∗ Proof: If is regular, then there is a DFA L M = ( Q, Σ , δ , q 0 , F ) recognizing . Then L M 0 = ( Q, Σ , δ , q 0 , Q \ F ) recognizes . So is regular. L L
Closed under complementation Closure properties can be used to show languages are not regular. Corollary: If is non -regular, then so is . L ⊆ Σ ∗ L Proof: By contrapositive: If is regular, then by the previous Proposition L is regular. L = L Examples: { 0 , 1 } ∗ \{ 0 n 1 n : n ∈ N } are non-regular. { a } ∗ \{ a 2 n : n ∈ N }
Closed under union Theorem: Let be some finite alphabet. Σ If and are regular, then so is . L 2 ⊆ Σ ∗ L 1 ⊆ Σ ∗ L 1 ∪ L 2 Proof: Let be a DFA deciding M = ( Q, Σ , δ , q 0 , F ) L 1 M 0 = ( Q 0 , Σ , δ 0 , q 0 and be a DFA deciding . 0 , F 0 ) L 2 We construct a DFA M 00 = ( Q 00 , Σ , δ 00 , q 00 0 , F 00 ) that decides , as follows: L 1 ∪ L 2 . . .
The mindset Imagine yourself as a DFA. Rules: 1) Can only scan the input once, from left to right. 2) Can only remember “constant” amount of information. should not change based on input length
Step 1 : Imagining ourselves as a DFA
Closed under union M 1 Example strings with even 0 q even L 1 = number of 1’s 1 1 strings with length L 2 = divisible by 3. 0 q odd 0 , 1 M 2 p 0 p 2 p 1 0 , 1 0 , 1
Closed under union M 1 Input: 101001 0 q even 1 1 0 q odd 0 , 1 M 2 p 0 p 2 p 1 0 , 1 0 , 1
Closed under union M 1 Input: 101001 0 q even 1 1 0 q odd 0 , 1 M 2 p 0 p 2 p 1 0 , 1 0 , 1
Closed under union M 1 Input: 101001 0 q even 1 1 0 q odd 0 , 1 M 2 p 0 p 2 p 1 0 , 1 0 , 1
Closed under union M 1 Input: 101001 0 q even 1 1 0 q odd 0 , 1 M 2 p 0 p 2 p 1 0 , 1 0 , 1
Closed under union M 1 Input: 101001 0 q even 1 1 0 q odd 0 , 1 M 2 p 0 p 2 p 1 0 , 1 0 , 1
Closed under union M 1 Input: 101001 0 q even 1 1 0 q odd 0 , 1 M 2 p 0 p 2 p 1 0 , 1 0 , 1
Closed under union M 1 Input: 101001 0 q even 1 1 0 q odd 0 , 1 M 2 p 0 p 2 p 1 0 , 1 0 , 1
Closed under union M 1 Input: 101001 0 q even 1 1 0 q odd 0 , 1 M 2 p 0 p 2 p 1 0 , 1 0 , 1
Closed under union M 1 Input: 101001 0 q even 1 1 Accept 0 q odd 0 , 1 M 2 p 0 p 2 p 1 0 , 1 0 , 1
Closed under union Main idea: M 1 Construct a DFA that keeps track of both at once. 0 q even 1 1 0 q odd 0 , 1 M 2 p 0 p 2 p 1 0 , 1 0 , 1
Closed under union Main idea: Construct a DFA that keeps track of both at once. q even q even q even p 0 p 1 p 2 q odd q odd q odd p 0 p 1 p 2
Closed under union Main idea: Construct a DFA that keeps track of both at once. q even q even q even p 0 p 1 p 2 0 ? q odd q odd q odd p 0 p 1 p 2
Closed under union Main idea: Construct a DFA that keeps track of both at once. 0 q even q even q even p 0 p 1 p 2 q odd q odd q odd p 0 p 1 p 2
Closed under union Main idea: Construct a DFA that keeps track of both at once. 0 q even q even q even p 0 p 1 p 2 1 ? q odd q odd q odd p 0 p 1 p 2
Closed under union Main idea: Construct a DFA that keeps track of both at once. 0 q even q even q even p 0 p 1 p 2 1 q odd q odd q odd p 0 p 1 p 2
Closed under union Main idea: Construct a DFA that keeps track of both at once. 0 q even q even q even p 0 p 1 p 2 1 ? 0 q odd q odd q odd p 0 p 1 p 2
Closed under union Main idea: Construct a DFA that keeps track of both at once. 0 q even q even q even p 0 p 1 p 2 1 0 q odd q odd q odd p 0 p 1 p 2
Closed under union Main idea: Construct a DFA that keeps track of both at once. 0 q even q even q even p 0 p 1 p 2 1 ? 1 0 q odd q odd q odd p 0 p 1 p 2
Closed under union Main idea: Construct a DFA that keeps track of both at once. 0 q even q even q even p 0 p 1 p 2 1 1 0 q odd q odd q odd p 0 p 1 p 2
Closed under union Main idea: Construct a DFA that keeps track of both at once. 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1
Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1
Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1
Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1
Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1
Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1
Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1
Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1
Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1
Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1
Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1
Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1
Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1
Closed under union Input: 101001 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1
Closed under union Input: 101001 Decision: Accept 0 0 0 q even q even q even p 0 p 1 p 2 1 1 1 0 0 0 q odd q odd q odd p 0 p 1 p 2 1
Step 2 : Formally defining the DFA
Closed under union Proof: Let be a DFA deciding M = ( Q, Σ , δ , q 0 , F ) L 1 M 0 = ( Q 0 , Σ , δ 0 , q 0 and be a DFA deciding . 0 , F 0 ) L 2 We construct a DFA M 00 = ( Q 00 , Σ , δ 00 , q 00 0 , F 00 ) that decides , as follows: L 1 ∪ L 2 - Q 00 = Q × Q 0 = { ( q, q 0 ) : q ∈ Q, q 0 ∈ Q 0 } - δ 00 (( q, q 0 ) , a ) = ( δ ( q, a ) , δ 0 ( q 0 , a )) - q 00 0 = ( q 0 , q 0 0 ) - F 00 = { ( q, q 0 ) : q ∈ F or q 0 ∈ F 0 } It remains to show that . L ( M 00 ) = L 1 ∪ L 2 L ( M 00 ) ⊆ L 1 ∪ L 2 : . . . L 1 ∪ L 2 ⊆ L ( M 00 ) : . . .
Closed under intersection Corollary: Let be some finite alphabet. Σ If and are regular, then so is . L 2 ⊆ Σ ∗ L 1 ⊆ Σ ∗ L 1 ∩ L 2 Proof: Follows from: - L 1 ∩ L 2 = L 1 ∪ L 2 - regular languages are closed under complementation - regular languages are closed under union
Closed under intersection Closure properties can be used to show languages are not regular. Example: Let be the language consisting of all words L ⊆ { 0 , 1 } ∗ with an equal number of 0’s and 1’s. We claim is not regular. Suppose it was regular. L { 0 n 1 m : n, m ∈ N } { 0 n 1 n : n ∈ N } ∩ L = regular regular regular contradiction
Recommend
More recommend