Deterministic Finite Automata Lecture 4 1
Input Accepted by a DFA We say that M accepts w ∈ Σ * if M , on input w , starting from the start state s , reaches a final state i.e., δ * ( s,w ) ∈ F L ( M ) is the set of all strings accepted by M i.e., L ( M ) = { w | δ * ( s,w ) ∈ F } Called the language accepted by M CS 374 2
Input Accepted by a DFA What kind of language is accepted by FSM? - Automatic (it is an automaton after all)! - We will use: REGULAR (not a coincidence) Language is regular iff -it is accepted by a finite state automaton CS 374 -it is described by a regular expression 3
Warning “ M accepts language L ” does not mean simply that M accepts each string in L . “ M accepts language L ” means M accepts each string in L and no others! L ( M ) = L CS 374 4
Examples: What is L ( M ) ? 0 1 0 0 1 0 1 abbreviation 1 0 0 1 1 1 1 0,1 0 2 3 2 0 0*11* Reject state odd #0 and odd #1 B A B 0 1 2 3 4 A B B A A AB ABB ABBA A CS 374 A B (A+B)*ABBA 5
Building DFAs 6
State = Memory First, decide on Q The state of a DFA is its entire memory of what has come before The state must capture enough information to complete the computation on the suffix to come When designing a DFA, think “what do I need to know at this moment?” That is your state. CS 374 7
DFA Construction Exercise L ( M ) = { w | w contains 00 } (0+1)*00(0+1)* Is it regular?? What should be in the memory? s a CS 374 8
DFA Construction Exercise L ( M ) = { w | w contains 00 } (0+1)*00(0+1)* Is it regular?? What should be in the memory? 1 s a CS 374 9
DFA Construction Exercise L ( M ) = { w | w contains 00 } (0+1)*00(0+1)* Is it regular?? What should be in the memory? 1 0 s a CS 374 1 10
DFA Construction Exercise L ( M ) = { w | w contains 00 } (0+1)*00(0+1)* Is it regular?? What should be in the memory? 1 0 0 s a b CS 374 1 11
DFA Construction Exercise L ( M ) = { w | w contains 00 } (0+1)*00(0+1)* Is it regular?? What should be in the memory? 0,1 1 0 0 s a b CS 374 1 12
DFA Construction Exercise L ( M ) = { w | w contains 00 } - s : I haven’t seen a 00, previous symbol was 1 or undefined. - a: I haven’t seen a 00, previous symbol was a 0 0,1 - b: I have seen a 00 1 0 0 s a b CS 374 1 • We have exhausted of all strings. Either accepted (with 00) or not. 13
DFA construction • Make sure you interpret all the cases! • How about design a DFA for L ( M ) = { w | w contains 001100110011111001101101 }? • There is algorithm to minimize the DFA, but when you are asked to do it, try to be clear versus succinct. • Try to be “stupid”, do brute force!!! • When you are just trying to prove that a language is regular —> DFA for the language exists. Write an algorithm like CS 374 we did for multiple of 5! 14
A More Complicated example L ( M ) = { w | w contains 00 and then 11} CS 374 15
A More Complicated example L ( M ) = { w | w contains 00} 0,1 1 0 0 s a b 1 CS 374 16
A More Complicated example L ( M ) = { w | w contains 11} 0,1 0 1 1 s’ a’ b’ 0 CS 374 17
A More Complicated example L ( M ) = { w | w contains 00 and then 11} 1 0 0 s 0 00 1 CS 374 18
A More Complicated example L ( M ) = { w | w contains 00 and then 11} 0 1 0 0 s 0 00 1 CS 374 19
A More Complicated example L ( M ) = { w | w contains 00 and then 11} 0 1 0 1 0 00,1 s 0 00 1 CS 374 20
A More Complicated example L ( M ) = { w | w contains 00 and then 11} 0 1 0 1 0 00,1 s 0 00 1 0 CS 374 21
A More Complicated example L ( M ) = { w | w contains 00 and then 11} 0 1 0 1 0 1 00,1 s 0 00 00,11 1 0 CS 374 22
A More Complicated example L ( M ) = { w | w contains 00 and then 11} 0 1 0 1 0 1 00,1 s 0 00 00,11 1 0 CS 374 23
A More Complicated example L ( M ) = { w | w contains 00 and then 11} 0 0,1 1 0 1 0 1 00,1 s 0 00 00,11 1 0 CS 374 24
A More Complicated example L ( M ) = { w | w contains 00 and then 11} 0 0,1 1 0 1 0 1 00,1 s 0 00 00,11 1 0 • If A and B are regular, then AB is regular. Does the same hold for DFA? CS 374 25
A More Complicated example L ( M ) = { w | w contains 00 and then 11} 0 0,1 1 0 1 0 1 00,1 s 0 00 00,11 1 0 • If A and B are regular, then AB is regular. Does the same hold for DFA? CS 374 • NO! you cannot glue two DFAs together in general like that. This was a special case 26
What about the complement? L ( M ) = { w | w contains no 11 after 00} 0 0,1 1 0 1 0 1 00,1 s 0 00 00,11 1 0 CS 374 27
What about the complement? L ( M ) = { w | w contains no 11 after 00} 0 0,1 1 0 1 0 1 00,1 s 0 00 00,11 1 0 CS 374 28
What about the complement? L ( M ) = { w | w contains no 11 after 00} 0 0,1 1 0 1 0 1 00,1 s 0 00 00,11 1 0 •If L is regular, then Σ *\L is regular •Make the accepting states into non-accepting CS 374 and the non-accepting states into accepting 29
L = {w: w contains 00 and 11}? 0, 1 0 0 s a b 0 1 s’ • I want to build a machine that decides if a string contains two zeroes in a row AND two ones in a row. 1 0 • I want to run both machines at the same time. a’ • At the end of the string, if I am on the accept state for machine 1 AND on the accept state for machine 2, then I accept. 1 CS 374 • How many states total? b’ 0,
L = {w: w contains 00 and 11}? 0, 1 0 0 s a b 0 1 L ( M 1 ) contains 00 s’ 1 0 a’ 1 CS 374 b’ L ( M 2 ) :contains 11 0, 31
L = {w: w contains 00 and 11}? 0, 1 0 0 s a b 0 1 L ( M 1 ) contains 00 s’ 0 1 0 a’ 1 CS 374 b’ L ( M 2 ) :contains 11 0, 32
L = {w: w contains 00 and 11}? 0, 1 0 0 s a b 0 1 L ( M 1 ) contains 00 s’ 0 0 1 0 a’ 1 CS 374 b’ L ( M 2 ) :contains 11 0, 33
L = {w: w contains 00 and 11}? 0, 1 0 0 s a b 0 1 L ( M 1 ) contains 00 s’ 0 0 1 0 1 a’ 1 CS 374 b’ L ( M 2 ) :contains 11 0, 34
L = {w: w contains 00 and 11}? 0, 1 0 0 s a b 0 1 L ( M 1 ) contains 00 s’ 0 0 0 1 0 1 a’ 1 CS 374 b’ L ( M 2 ) :contains 11 0, 35
L = {w: w contains 00 and 11}? 0, 1 0 0 s a b 0 1 L ( M 1 ) contains 00 s’ 0 0 0 1 0 1 a’ 1 CS 374 b’ L ( M 2 ) :contains 11 0, 36
L = {w: w contains 00 and 11}? 0, 1 0 0 s a b 0 1 L ( M 1 ) contains 00 s’ 0 0 0 1 0 1 a’ 1 1 CS 374 b’ L ( M 2 ) :contains 11 0, 37
L = {w: w contains 00 and 11}? 0, 1 0 0 s a b 0 1 L ( M 1 ) contains 00 s’ 0 0 0 1 0 1 a’ 1 1 CS 374 b’ L ( M 2 ) :contains 11 0, 38
L = {w: w contains 00 and 11}? 0, 1 0 0 s a b 0 1 L ( M 1 ) contains 00 s’ 0 0 0 1 0 1 a’ 1 1 CS 374 b’ L ( M 2 ) :contains 11 0, 39
L = {w: w contains 00 and 11}? 0, 1 0 0 s a b 0 1 L ( M 1 ) contains 00 s’ 0 0 0 1 0 0 1 0 1 1 0 a’ 1 1 1 1 0 0 1 CS 374 b’ 1 L ( M 2 ) :contains 11 0,1 0, 40
L = {w: w contains 00 and 11}? 0, 1 0 0 s a b 0 1 L ( M 1 ) contains 00 s’ 0 0 0 1 0 0 1 0 1 1 0 a’ 1 1 1 1 0 0 1 CS 374 b’ 1 L ( M 2 ) :contains 11 0,1 0, 41
The Product Construction Formally, given two DFAs M 1 = ( Σ , Q 1 , s 1 , A 1 , δ 1 ) and M 2 = ( Σ , Q 2 , s 2 , A 2 , δ 2 ) Where M 1 accepts L 1 M 2 accepts L 2 M = ( Σ , Q , s , A , δ ) accepts L 1 ∩ L 2 Q = Q 1 × Q 2, s = ( s 1 , s 2 ) A = {(q 1 ,q 2 ): q 1 ∈ A 1 and q 2 ∈ A 2 } CS 374 δ : (Q 1 × Q 2 ) ×Σ —>Q 1 × Q 2 δ ( ( q 1 , q 2 ), a ) = ( , ) 42
The Product Construction Formally, given two DFAs M 1 = ( Σ , Q 1 , s 1 , A 1 , δ 1 ) and M 2 = ( Σ , Q 2 , s 2 , A 2 , δ 2 ) Where M 1 accepts L 1 M 2 accepts L 2 M = ( Σ , Q , s , A , δ ) accepts L 1 ∩ L 2 Q = Q 1 × Q 2, s = ( s 1 , s 2 ) A = {(q 1 ,q 2 ): q 1 ∈ A 1 and q 2 ∈ A 2 } CS 374 δ : (Q 1 × Q 2 ) ×Σ —>Q 1 × Q 2 δ ( ( q 1 , q 2 ), a ) = ( δ 1 ( q 1 , a ), δ 2 ( q 2 , a ) ) 43
L = {w: w contains 00 and 11}? 0, 1 0 0 s a b 0 1 s’ 0 0 0 1 0 1 0 1 1 0 a’ 1 1 1 0 0 1 CS 374 b’ 1 0,1 0, 44
L = {w: w contains 00 and 11}? 0, 1 0 0 s a b Or 0 1 s’ 0 0 0 1 0 1 0 1 1 0 a’ 1 1 1 0 0 1 CS 374 b’ 1 0,1 0, 45
L = {w: w contains 00 and 11}? 0, 1 0 0 s a b Or 0 1 s’ 0 0 0 1 0 1 0 1 1 0 a’ 1 1 1 0 0 1 CS 374 b’ 1 0,1 0, 46
The Product Construction Formally, given two DFAs M 1 = ( Σ , Q 1 , s 1 , A 1 , δ 1 ) and M 2 = ( Σ , Q 2 , s 2 , A 2 , δ 2 ) Where M 1 accepts L 1 M 2 accepts L 2 L 1 ∪ L 2 M = ( Σ , Q , s , A , δ ) accepts L 1 ∩ L 2 Q = Q 1 × Q 2, s = ( s 1 , s 2 ) A = {(q 1 ,q 2 ): q 1 ∈ A 1 and q 2 ∈ A 2 } CS 374 δ : (Q 1 × Q 2 ) ×Σ —>Q 1 × Q 2 δ ( ( q 1 , q 2 ), a ) = ( δ 1 ( q 1 , a ), δ 2 ( q 2 , a ) ) 47
Recommend
More recommend