Algorithms & Models of Computation CS/ECE 374, Spring 29 Deterministic Finite Automata (DFAs) Lecture 3 Tuesday, January 22, 29 L A TEXed: December 27, 28 8:25 Chan, Har-Peled, Hassanieh (UIUC) CS374 Spring 29 / 36
Part I DFA Introduction Chan, Har-Peled, Hassanieh (UIUC) CS374 2 Spring 29 2 / 36
DFAs also called Finite State Machines (FSMs) The simplest model for computers? State machines that are common in practice. Vending machines Elevators Digital watches Simple network protocols Programs with fixed memory Chan, Har-Peled, Hassanieh (UIUC) CS374 3 Spring 29 3 / 36
A simple program Program to check if a given input string w has odd length int n = While input is not finished read next character c n n + endwhile If (n is odd) output YES Else output NO bit x = While input is not finished read next character c x flip(x) endwhile If (x = ) output YES Else output NO Chan, Har-Peled, Hassanieh (UIUC) CS374 4 Spring 29 4 / 36
A simple program Program to check if a given input string w has odd length int n = While input is not finished read next character c n n + endwhile If (n is odd) output YES Else output NO bit x = While input is not finished read next character c x flip(x) endwhile If (x = ) output YES Else output NO Chan, Har-Peled, Hassanieh (UIUC) CS374 4 Spring 29 4 / 36
Another view Machine has input written on a read-only tape Start in specified start state Start at left, scan symbol, change state and move right Circled states are accepting Machine accepts input string if it is in an accepting state after scanning the last symbol. Chan, Har-Peled, Hassanieh (UIUC) CS374 5 Spring 29 5 / 36
Graphical Representation/State Machine q3 q2, q q Directed graph with nodes representing states and edge/arcs representing transitions labeled by symbols in Σ For each state (vertex) q and symbol a Σ there is exactly one outgoing edge labeled by a Initial/start state has a pointer (or labeled as s, q or start ) Some states with double circles labeled as accepting/final states Chan, Har-Peled, Hassanieh (UIUC) CS374 6 Spring 29 6 / 36
Graphical Representation q q 3 q q 2, Where does lead?? Which strings end Figure up: indfa accepting M for problem state? 5 Can you prove it? Every string w has a unique walk that it follows from a given ange the state initial q by state reading to B? one letter of w from left to right. ange the set of final states to be {B} (with initial state A)? Chan, Har-Peled, Hassanieh (UIUC) CS374 7 Spring 29 7 / 36
Graphical Representation q q 3 q q 2, Where does lead?? Which strings end Figure up: indfa accepting M for problem state? 5 Can you prove it? Every string w has a unique walk that it follows from a given ange the state initial q by state reading to B? one letter of w from left to right. ange the set of final states to be {B} (with initial state A)? Chan, Har-Peled, Hassanieh (UIUC) CS374 7 Spring 29 7 / 36
Graphical Representation q q 3 q q 2, Where does lead?? Which strings end Figure up: indfa accepting M for problem state? 5 Can you prove it? Every string w has a unique walk that it follows from a given ange the state initial q by state reading to B? one letter of w from left to right. ange the set of final states to be {B} (with initial state A)? Chan, Har-Peled, Hassanieh (UIUC) CS374 7 Spring 29 7 / 36
Graphical Representation q q 3 q q 2, Where does lead?? Which strings end Figure up: indfa accepting M for problem state? 5 Can you prove it? Every string w has a unique walk that it follows from a given ange the state initial q by state reading to B? one letter of w from left to right. ange the set of final states to be {B} (with initial state A)? Chan, Har-Peled, Hassanieh (UIUC) CS374 7 Spring 29 7 / 36
Graphical Representation q q 3 q q 2, Definition A DFA M accepts Figure a string : wdfa iffmtheforunique problemwalk 5 starting at the start state and spelling out w ends in an accepting state. ange Definition the initial state to B? The language accepted (or recognized) by a DFA M is denote by L(M) and defined as: L(M) = {w M accepts w}. ange the set of final states to be {B} (with initial state A)? Chan, Har-Peled, Hassanieh (UIUC) CS374 8 Spring 29 8 / 36
Graphical Representation q q 3 q q 2, Definition A DFA M accepts Figure a string : wdfa iffmtheforunique problemwalk 5 starting at the start state and spelling out w ends in an accepting state. ange Definition the initial state to B? The language accepted (or recognized) by a DFA M is denote by L(M) and defined as: L(M) = {w M accepts w}. ange the set of final states to be {B} (with initial state A)? Chan, Har-Peled, Hassanieh (UIUC) CS374 8 Spring 29 8 / 36
Warning M accepts language L does not mean simply that that M accepts each string in L. It means that M accepts each string in L and no others. Equivalently M accepts each string in L and does not accept/rejects strings in Σ \ L. M recognizes L is a better term but accepts is widely accepted (and recognized) (joke attributed to Lenny Pitt) Chan, Har-Peled, Hassanieh (UIUC) CS374 9 Spring 29 9 / 36
Warning M accepts language L does not mean simply that that M accepts each string in L. It means that M accepts each string in L and no others. Equivalently M accepts each string in L and does not accept/rejects strings in Σ \ L. M recognizes L is a better term but accepts is widely accepted (and recognized) (joke attributed to Lenny Pitt) Chan, Har-Peled, Hassanieh (UIUC) CS374 9 Spring 29 9 / 36
Formal Tuple Notation Definition A deterministic finite automata (DFA) M = (Q, Σ, δ, s, A) is a five tuple where Q is a finite set whose elements are called states, Σ is a finite set called the input alphabet, δ : Q Σ Q is the transition function, s Q is the start state, A Q is the set of accepting/final states. Common alternate notation: q for start state, F for final states. Chan, Har-Peled, Hassanieh (UIUC) CS374 Spring 29 / 36
Formal Tuple Notation Definition A deterministic finite automata (DFA) M = (Q, Σ, δ, s, A) is a five tuple where Q is a finite set whose elements are called states, Σ is a finite set called the input alphabet, δ : Q Σ Q is the transition function, s Q is the start state, A Q is the set of accepting/final states. Common alternate notation: q for start state, F for final states. Chan, Har-Peled, Hassanieh (UIUC) CS374 Spring 29 / 36
Formal Tuple Notation Definition A deterministic finite automata (DFA) M = (Q, Σ, δ, s, A) is a five tuple where Q is a finite set whose elements are called states, Σ is a finite set called the input alphabet, δ : Q Σ Q is the transition function, s Q is the start state, A Q is the set of accepting/final states. Common alternate notation: q for start state, F for final states. Chan, Har-Peled, Hassanieh (UIUC) CS374 Spring 29 / 36
Formal Tuple Notation Definition A deterministic finite automata (DFA) M = (Q, Σ, δ, s, A) is a five tuple where Q is a finite set whose elements are called states, Σ is a finite set called the input alphabet, δ : Q Σ Q is the transition function, s Q is the start state, A Q is the set of accepting/final states. Common alternate notation: q for start state, F for final states. Chan, Har-Peled, Hassanieh (UIUC) CS374 Spring 29 / 36
Formal Tuple Notation Definition A deterministic finite automata (DFA) M = (Q, Σ, δ, s, A) is a five tuple where Q is a finite set whose elements are called states, Σ is a finite set called the input alphabet, δ : Q Σ Q is the transition function, s Q is the start state, A Q is the set of accepting/final states. Common alternate notation: q for start state, F for final states. Chan, Har-Peled, Hassanieh (UIUC) CS374 Spring 29 / 36
Formal Tuple Notation Definition A deterministic finite automata (DFA) M = (Q, Σ, δ, s, A) is a five tuple where Q is a finite set whose elements are called states, Σ is a finite set called the input alphabet, δ : Q Σ Q is the transition function, s Q is the start state, A Q is the set of accepting/final states. Common alternate notation: q for start state, F for final states. Chan, Har-Peled, Hassanieh (UIUC) CS374 Spring 29 / 36
Formal Tuple Notation Definition A deterministic finite automata (DFA) M = (Q, Σ, δ, s, A) is a five tuple where Q is a finite set whose elements are called states, Σ is a finite set called the input alphabet, δ : Q Σ Q is the transition function, s Q is the start state, A Q is the set of accepting/final states. Common alternate notation: q for start state, F for final states. Chan, Har-Peled, Hassanieh (UIUC) CS374 Spring 29 / 36
Formal Tuple Notation Definition A deterministic finite automata (DFA) M = (Q, Σ, δ, s, A) is a five tuple where Q is a finite set whose elements are called states, Σ is a finite set called the input alphabet, δ : Q Σ Q is the transition function, s Q is the start state, A Q is the set of accepting/final states. Common alternate notation: q for start state, F for final states. Chan, Har-Peled, Hassanieh (UIUC) CS374 Spring 29 / 36
DFA Notation M = set of all states transition func ( {}}{{}}{ Q, }{{} Σ, alphabet δ, s }{{} start state, set of all accept states {}}{ A ) Chan, Har-Peled, Hassanieh (UIUC) CS374 Spring 29 / 36
Example q q 3 q q 2, Q = {q, q, q, q 3 } Σ = {, } Figure : DFA M for problem 5 δ s = q ange the initial state to B? A = {q } ange the set of final states to be {B} (with initial state A)? Chan, Har-Peled, Hassanieh (UIUC) CS374 2 Spring 29 2 / 36
Example q q 3 q q 2, Q = {q, q, q, q 3 } Σ = {, } Figure : DFA M for problem 5 δ s = q ange the initial state to B? A = {q } ange the set of final states to be {B} (with initial state A)? Chan, Har-Peled, Hassanieh (UIUC) CS374 2 Spring 29 2 / 36
Example q q 3 q q 2, Q = {q, q, q, q 3 } Σ = {, } Figure : DFA M for problem 5 δ s = q ange the initial state to B? A = {q } ange the set of final states to be {B} (with initial state A)? Chan, Har-Peled, Hassanieh (UIUC) CS374 2 Spring 29 2 / 36
Example q q 3 q q 2, Q = {q, q, q, q 3 } Σ = {, } Figure : DFA M for problem 5 δ s = q ange the initial state to B? A = {q } ange the set of final states to be {B} (with initial state A)? Chan, Har-Peled, Hassanieh (UIUC) CS374 2 Spring 29 2 / 36
Example q q 3 q q 2, Q = {q, q, q, q 3 } Σ = {, } Figure : DFA M for problem 5 δ s = q ange the initial state to B? A = {q } ange the set of final states to be {B} (with initial state A)? Chan, Har-Peled, Hassanieh (UIUC) CS374 2 Spring 29 2 / 36
Example q q 3 q q 2, Q = {q, q, q, q 3 } Σ = {, } Figure : DFA M for problem 5 δ s = q ange the initial state to B? A = {q } ange the set of final states to be {B} (with initial state A)? Chan, Har-Peled, Hassanieh (UIUC) CS374 2 Spring 29 2 / 36
Example q q 3 q q 2, Q = {q, q, q, q 3 } Σ = {, } Figure : DFA M for problem 5 δ s = q ange the initial state to B? A = {q } ange the set of final states to be {B} (with initial state A)? Chan, Har-Peled, Hassanieh (UIUC) CS374 2 Spring 29 2 / 36
Example q q 3 q q 2, Q = {q, q, q, q 3 } Σ = {, } Figure : DFA M for problem 5 δ s = q ange the initial state to B? A = {q } ange the set of final states to be {B} (with initial state A)? Chan, Har-Peled, Hassanieh (UIUC) CS374 2 Spring 29 2 / 36
Example q q 3 q q 2, Q = {q, q, q, q 3 } Σ = {, } Figure : DFA M for problem 5 δ s = q ange the initial state to B? A = {q } ange the set of final states to be {B} (with initial state A)? Chan, Har-Peled, Hassanieh (UIUC) CS374 2 Spring 29 2 / 36
Extending the transition function to strings Given DFA M = (Q, Σ, δ, s, A), δ(q, a) is the state that M goes to from q on reading letter a Useful to have notation to specify the unique state that M will reach from q on reading string w Transition function δ : Q Σ Q defined inductively as follows: δ (q, w) = q if w = ɛ δ (q, w) = δ (δ(q, a), x) if w = ax. Chan, Har-Peled, Hassanieh (UIUC) CS374 3 Spring 29 3 / 36
Extending the transition function to strings Given DFA M = (Q, Σ, δ, s, A), δ(q, a) is the state that M goes to from q on reading letter a Useful to have notation to specify the unique state that M will reach from q on reading string w Transition function δ : Q Σ Q defined inductively as follows: δ (q, w) = q if w = ɛ δ (q, w) = δ (δ(q, a), x) if w = ax. Chan, Har-Peled, Hassanieh (UIUC) CS374 3 Spring 29 3 / 36
Formal definition of language accepted by M Definition The language L(M) accepted by a DFA M = (Q, Σ, δ, s, A) is {w Σ δ (s, w) A}. Chan, Har-Peled, Hassanieh (UIUC) CS374 4 Spring 29 4 / 36
Example q q 3 q q 2, What is: δ (q, ɛ) Figure : DFA M for problem 5 δ (q, ) δ (q, ) ange the δ initial (q 4, ) state to B? ange the set of final states to be {B} (with initial state A)? Chan, Har-Peled, Hassanieh (UIUC) CS374 5 Spring 29 5 / 36
Example continued q q 3 q q 2, What is L(M) if start state is changed to q? What is L(M) Figure if final/accept : DFA Mstates for problem are set5 to {q 2, q 3 } instead of {q }? ange the initial state to B? ange the set of final states to be {B} (with initial state A)? Chan, Har-Peled, Hassanieh (UIUC) CS374 6 Spring 29 6 / 36
Advantages of formal specification Necessary for proofs Necessary to specify abstractly for class of languages Exercise: Prove by induction that for any two strings u, v, any state q, δ (q, uv) = δ (δ (q, u), v). Chan, Har-Peled, Hassanieh (UIUC) CS374 7 Spring 29 7 / 36
Part II Constructing DFAs Chan, Har-Peled, Hassanieh (UIUC) CS374 8 Spring 29 8 / 36
DFAs: State = Memory How do we design a DFA M for a given language L? That is L(M) = L. DFA is a like a program that has fixed amount of memory independent of input size. The memory of a DFA is encoded in its states The state/memory must capture enough information from the input seen so far that it is sufficient for the suffix that is yet to be seen (note that DFA cannot go back) Chan, Har-Peled, Hassanieh (UIUC) CS374 9 Spring 29 9 / 36
DFA Construction: Example Assume Σ = {, } L =, L = Σ, L = {ɛ}, L = {}. L = {w {, } w is divisible by 5} L = {w {, } w ends with } L = {w {, } w contains as substring} L = {w {, } w contains or as substring} L = {w w has a k positions from the end} Chan, Har-Peled, Hassanieh (UIUC) CS374 2 Spring 29 2 / 36
DFA Construction: Example Assume Σ = {, } L =, L = Σ, L = {ɛ}, L = {}. L = {w {, } w is divisible by 5} L = {w {, } w ends with } L = {w {, } w contains as substring} L = {w {, } w contains or as substring} L = {w w has a k positions from the end} Chan, Har-Peled, Hassanieh (UIUC) CS374 2 Spring 29 2 / 36
DFA Construction: Example Assume Σ = {, } L =, L = Σ, L = {ɛ}, L = {}. L = {w {, } w is divisible by 5} L = {w {, } w ends with } L = {w {, } w contains as substring} L = {w {, } w contains or as substring} L = {w w has a k positions from the end} Chan, Har-Peled, Hassanieh (UIUC) CS374 2 Spring 29 2 / 36
DFA Construction: Example Assume Σ = {, } L =, L = Σ, L = {ɛ}, L = {}. L = {w {, } w is divisible by 5} L = {w {, } w ends with } L = {w {, } w contains as substring} L = {w {, } w contains or as substring} L = {w w has a k positions from the end} Chan, Har-Peled, Hassanieh (UIUC) CS374 2 Spring 29 2 / 36
DFA Construction: Example Assume Σ = {, } L =, L = Σ, L = {ɛ}, L = {}. L = {w {, } w is divisible by 5} L = {w {, } w ends with } L = {w {, } w contains as substring} L = {w {, } w contains or as substring} L = {w w has a k positions from the end} Chan, Har-Peled, Hassanieh (UIUC) CS374 2 Spring 29 2 / 36
DFA Construction: Example Assume Σ = {, } L =, L = Σ, L = {ɛ}, L = {}. L = {w {, } w is divisible by 5} L = {w {, } w ends with } L = {w {, } w contains as substring} L = {w {, } w contains or as substring} L = {w w has a k positions from the end} Chan, Har-Peled, Hassanieh (UIUC) CS374 2 Spring 29 2 / 36
DFA Construction: Example L = {Binary numbers congruent to mod 5} Example: = 7 = 2 mod 5, = = mod 5 Key observation: w mod 5 = a implies w mod 5 = 2a mod 5 and w mod 5 = (2a + ) mod 5 Chan, Har-Peled, Hassanieh (UIUC) CS374 2 Spring 29 2 / 36
DFA Construction: Example L = {Binary numbers congruent to mod 5} Example: = 7 = 2 mod 5, = = mod 5 Key observation: w mod 5 = a implies w mod 5 = 2a mod 5 and w mod 5 = (2a + ) mod 5 Chan, Har-Peled, Hassanieh (UIUC) CS374 2 Spring 29 2 / 36
Part III Product Construction and Closure Properties Chan, Har-Peled, Hassanieh (UIUC) CS374 22 Spring 29 22 / 36
Part IV Complement Chan, Har-Peled, Hassanieh (UIUC) CS374 23 Spring 29 23 / 36
Complement Question: If M is a DFA, is there a DFA M such that L(M ) = Σ \ L(M)? That is, are languages recognized by DFAs closed under complement? q3 q2, q q Chan, Har-Peled, Hassanieh (UIUC) CS374 24 Spring 29 24 / 36
Complement Example... Just flip the state of the states! q3 q2, q3 q2, q q q q Chan, Har-Peled, Hassanieh (UIUC) CS374 25 Spring 29 25 / 36
Complement Theorem Languages accepted by DFAs are closed under complement. Proof. Let M = (Q, Σ, δ, s, A) such that L = L(M). Let M = (Q, Σ, δ, s, Q \ A). Claim: L(M ) = L. Why? δ M = δ M. Thus, for every string w, δ M (s, w) = δ M (s, w). δ M (s, w) A δ M (s, w) Q \ A. δ M (s, w) A δ M (s, w) Q \ A. Chan, Har-Peled, Hassanieh (UIUC) CS374 26 Spring 29 26 / 36
Complement Theorem Languages accepted by DFAs are closed under complement. Proof. Let M = (Q, Σ, δ, s, A) such that L = L(M). Let M = (Q, Σ, δ, s, Q \ A). Claim: L(M ) = L. Why? δ M = δ M. Thus, for every string w, δ M (s, w) = δ M (s, w). δ M (s, w) A δ M (s, w) Q \ A. δ M (s, w) A δ M (s, w) Q \ A. Chan, Har-Peled, Hassanieh (UIUC) CS374 26 Spring 29 26 / 36
Complement Theorem Languages accepted by DFAs are closed under complement. Proof. Let M = (Q, Σ, δ, s, A) such that L = L(M). Let M = (Q, Σ, δ, s, Q \ A). Claim: L(M ) = L. Why? δ M = δ M. Thus, for every string w, δ M (s, w) = δ M (s, w). δ M (s, w) A δ M (s, w) Q \ A. δ M (s, w) A δ M (s, w) Q \ A. Chan, Har-Peled, Hassanieh (UIUC) CS374 26 Spring 29 26 / 36
Part V Product Construction Chan, Har-Peled, Hassanieh (UIUC) CS374 27 Spring 29 27 / 36
Union and Intersection Question: Are languages accepted by DFAs closed under union? That is, given DFAs M and M 2 is there a DFA that accepts L(M ) L(M 2 )? How about intersection L(M ) L(M 2 )? Idea from programming: on input string w Simulate M on w Simulate M 2 on w If both accept than w L(M ) L(M 2 ). If at least one accepts then w L(M ) L(M 2 ). Catch: We want a single DFA M that can only read w once. Solution: Simulate M and M 2 in parallel by keeping track of states of both machines Chan, Har-Peled, Hassanieh (UIUC) CS374 28 Spring 29 28 / 36
Union and Intersection Question: Are languages accepted by DFAs closed under union? That is, given DFAs M and M 2 is there a DFA that accepts L(M ) L(M 2 )? How about intersection L(M ) L(M 2 )? Idea from programming: on input string w Simulate M on w Simulate M 2 on w If both accept than w L(M ) L(M 2 ). If at least one accepts then w L(M ) L(M 2 ). Catch: We want a single DFA M that can only read w once. Solution: Simulate M and M 2 in parallel by keeping track of states of both machines Chan, Har-Peled, Hassanieh (UIUC) CS374 28 Spring 29 28 / 36
Union and Intersection Question: Are languages accepted by DFAs closed under union? That is, given DFAs M and M 2 is there a DFA that accepts L(M ) L(M 2 )? How about intersection L(M ) L(M 2 )? Idea from programming: on input string w Simulate M on w Simulate M 2 on w If both accept than w L(M ) L(M 2 ). If at least one accepts then w L(M ) L(M 2 ). Catch: We want a single DFA M that can only read w once. Solution: Simulate M and M 2 in parallel by keeping track of states of both machines Chan, Har-Peled, Hassanieh (UIUC) CS374 28 Spring 29 28 / 36
Union and Intersection Question: Are languages accepted by DFAs closed under union? That is, given DFAs M and M 2 is there a DFA that accepts L(M ) L(M 2 )? How about intersection L(M ) L(M 2 )? Idea from programming: on input string w Simulate M on w Simulate M 2 on w If both accept than w L(M ) L(M 2 ). If at least one accepts then w L(M ) L(M 2 ). Catch: We want a single DFA M that can only read w once. Solution: Simulate M and M 2 in parallel by keeping track of states of both machines Chan, Har-Peled, Hassanieh (UIUC) CS374 28 Spring 29 28 / 36
Example M accepts # = odd M 2 accepts # = odd Chan, Har-Peled, Hassanieh (UIUC) CS374 29 Spring 29 29 / 36
Example M accepts # = odd M 2 accepts # = odd Cross-product machine Chan, Har-Peled, Hassanieh (UIUC) CS374 3 Spring 29 3 / 36
Example II Accept all binary strings of length divisible by 3 and 5 2 3 4,, 2, 3, 4,,, 2, 3, 4, 2, 2, 2 2, 2 3, 2 4, 2 Assume all edges are labeled by,. Chan, Har-Peled, Hassanieh (UIUC) CS374 3 Spring 29 3 / 36
Product construction for intersection M = (Q, Σ, δ, s, A ) and M 2 = (Q, Σ, δ 2, s 2, A 2 ) Create M = (Q, Σ, δ, s, A) where Q = Q Q 2 = {(q, q 2 ) q Q, q 2 Q 2 } s = (s, s 2 ) δ : Q Σ Q where δ((q, q 2 ), a) = (δ (q, a), δ 2 (q 2, a)) A = A A 2 = {(q, q 2 ) q A, q 2 A 2 } Theorem L(M) = L(M ) L(M 2 ). Chan, Har-Peled, Hassanieh (UIUC) CS374 32 Spring 29 32 / 36
Product construction for intersection M = (Q, Σ, δ, s, A ) and M 2 = (Q, Σ, δ 2, s 2, A 2 ) Create M = (Q, Σ, δ, s, A) where Q = Q Q 2 = {(q, q 2 ) q Q, q 2 Q 2 } s = (s, s 2 ) δ : Q Σ Q where δ((q, q 2 ), a) = (δ (q, a), δ 2 (q 2, a)) A = A A 2 = {(q, q 2 ) q A, q 2 A 2 } Theorem L(M) = L(M ) L(M 2 ). Chan, Har-Peled, Hassanieh (UIUC) CS374 32 Spring 29 32 / 36
Product construction for intersection M = (Q, Σ, δ, s, A ) and M 2 = (Q, Σ, δ 2, s 2, A 2 ) Create M = (Q, Σ, δ, s, A) where Q = Q Q 2 = {(q, q 2 ) q Q, q 2 Q 2 } s = (s, s 2 ) δ : Q Σ Q where δ((q, q 2 ), a) = (δ (q, a), δ 2 (q 2, a)) A = A A 2 = {(q, q 2 ) q A, q 2 A 2 } Theorem L(M) = L(M ) L(M 2 ). Chan, Har-Peled, Hassanieh (UIUC) CS374 32 Spring 29 32 / 36
Product construction for intersection M = (Q, Σ, δ, s, A ) and M 2 = (Q, Σ, δ 2, s 2, A 2 ) Create M = (Q, Σ, δ, s, A) where Q = Q Q 2 = {(q, q 2 ) q Q, q 2 Q 2 } s = (s, s 2 ) δ : Q Σ Q where δ((q, q 2 ), a) = (δ (q, a), δ 2 (q 2, a)) A = A A 2 = {(q, q 2 ) q A, q 2 A 2 } Theorem L(M) = L(M ) L(M 2 ). Chan, Har-Peled, Hassanieh (UIUC) CS374 32 Spring 29 32 / 36
Product construction for intersection M = (Q, Σ, δ, s, A ) and M 2 = (Q, Σ, δ 2, s 2, A 2 ) Create M = (Q, Σ, δ, s, A) where Q = Q Q 2 = {(q, q 2 ) q Q, q 2 Q 2 } s = (s, s 2 ) δ : Q Σ Q where δ((q, q 2 ), a) = (δ (q, a), δ 2 (q 2, a)) A = A A 2 = {(q, q 2 ) q A, q 2 A 2 } Theorem L(M) = L(M ) L(M 2 ). Chan, Har-Peled, Hassanieh (UIUC) CS374 32 Spring 29 32 / 36
Product construction for intersection M = (Q, Σ, δ, s, A ) and M 2 = (Q, Σ, δ 2, s 2, A 2 ) Create M = (Q, Σ, δ, s, A) where Q = Q Q 2 = {(q, q 2 ) q Q, q 2 Q 2 } s = (s, s 2 ) δ : Q Σ Q where δ((q, q 2 ), a) = (δ (q, a), δ 2 (q 2, a)) A = A A 2 = {(q, q 2 ) q A, q 2 A 2 } Theorem L(M) = L(M ) L(M 2 ). Chan, Har-Peled, Hassanieh (UIUC) CS374 32 Spring 29 32 / 36
Product construction for intersection M = (Q, Σ, δ, s, A ) and M 2 = (Q, Σ, δ 2, s 2, A 2 ) Create M = (Q, Σ, δ, s, A) where Q = Q Q 2 = {(q, q 2 ) q Q, q 2 Q 2 } s = (s, s 2 ) δ : Q Σ Q where δ((q, q 2 ), a) = (δ (q, a), δ 2 (q 2, a)) A = A A 2 = {(q, q 2 ) q A, q 2 A 2 } Theorem L(M) = L(M ) L(M 2 ). Chan, Har-Peled, Hassanieh (UIUC) CS374 32 Spring 29 32 / 36
Product construction for intersection M = (Q, Σ, δ, s, A ) and M 2 = (Q, Σ, δ 2, s 2, A 2 ) Create M = (Q, Σ, δ, s, A) where Q = Q Q 2 = {(q, q 2 ) q Q, q 2 Q 2 } s = (s, s 2 ) δ : Q Σ Q where δ((q, q 2 ), a) = (δ (q, a), δ 2 (q 2, a)) A = A A 2 = {(q, q 2 ) q A, q 2 A 2 } Theorem L(M) = L(M ) L(M 2 ). Chan, Har-Peled, Hassanieh (UIUC) CS374 32 Spring 29 32 / 36
Product construction for intersection M = (Q, Σ, δ, s, A ) and M 2 = (Q, Σ, δ 2, s 2, A 2 ) Create M = (Q, Σ, δ, s, A) where Q = Q Q 2 = {(q, q 2 ) q Q, q 2 Q 2 } s = (s, s 2 ) δ : Q Σ Q where δ((q, q 2 ), a) = (δ (q, a), δ 2 (q 2, a)) A = A A 2 = {(q, q 2 ) q A, q 2 A 2 } Theorem L(M) = L(M ) L(M 2 ). Chan, Har-Peled, Hassanieh (UIUC) CS374 32 Spring 29 32 / 36
Product construction for intersection M = (Q, Σ, δ, s, A ) and M 2 = (Q, Σ, δ 2, s 2, A 2 ) Create M = (Q, Σ, δ, s, A) where Q = Q Q 2 = {(q, q 2 ) q Q, q 2 Q 2 } s = (s, s 2 ) δ : Q Σ Q where δ((q, q 2 ), a) = (δ (q, a), δ 2 (q 2, a)) A = A A 2 = {(q, q 2 ) q A, q 2 A 2 } Theorem L(M) = L(M ) L(M 2 ). Chan, Har-Peled, Hassanieh (UIUC) CS374 32 Spring 29 32 / 36
Correctness of construction Lemma For each string w, δ (s, w) = (δ (s, w), δ 2 (s 2, w)). Exercise: Assuming lemma prove the theorem in previous slide. Proof of lemma by induction on w Chan, Har-Peled, Hassanieh (UIUC) CS374 33 Spring 29 33 / 36
Correctness of construction Lemma For each string w, δ (s, w) = (δ (s, w), δ 2 (s 2, w)). Exercise: Assuming lemma prove the theorem in previous slide. Proof of lemma by induction on w Chan, Har-Peled, Hassanieh (UIUC) CS374 33 Spring 29 33 / 36
Correctness of construction Lemma For each string w, δ (s, w) = (δ (s, w), δ 2 (s 2, w)). Exercise: Assuming lemma prove the theorem in previous slide. Proof of lemma by induction on w Chan, Har-Peled, Hassanieh (UIUC) CS374 33 Spring 29 33 / 36
Product construction for union M = (Q, Σ, δ, s, A ) and M 2 = (Q, Σ, δ 2, s 2, A 2 ) Create M = (Q, Σ, δ, s, A) where Q = Q Q 2 = {(q, q 2 ) q Q, q 2 Q 2 } s = (s, s 2 ) δ : Q Σ Q where δ((q, q 2 ), a) = (δ (q, a), δ 2 (q 2, a)) A = {(q, q 2 ) q A or q 2 A 2 } Theorem L(M) = L(M ) L(M 2 ). Chan, Har-Peled, Hassanieh (UIUC) CS374 34 Spring 29 34 / 36
Product construction for union M = (Q, Σ, δ, s, A ) and M 2 = (Q, Σ, δ 2, s 2, A 2 ) Create M = (Q, Σ, δ, s, A) where Q = Q Q 2 = {(q, q 2 ) q Q, q 2 Q 2 } s = (s, s 2 ) δ : Q Σ Q where δ((q, q 2 ), a) = (δ (q, a), δ 2 (q 2, a)) A = {(q, q 2 ) q A or q 2 A 2 } Theorem L(M) = L(M ) L(M 2 ). Chan, Har-Peled, Hassanieh (UIUC) CS374 34 Spring 29 34 / 36
Set Difference Theorem M, M 2 DFAs. There is a DFA M such that L(M) = L(M ) \ L(M 2 ). Exercise: Prove the above using two methods. Using a direct product construction Using closure under complement and intersection and union Chan, Har-Peled, Hassanieh (UIUC) CS374 35 Spring 29 35 / 36
Things to know: 2-way DFA Question: Why are DFAs required to only move right? Can we allow DFA to scan back and forth? Caveat: Tape is read-only so only memory is in machine s state. Can define a formal notion of a 2-way DFA Can show that any language recognized by a 2-way DFA can be recognized by a regular (-way) DFA Proof is tricky simulation via NFAs Chan, Har-Peled, Hassanieh (UIUC) CS374 36 Spring 29 36 / 36
Things to know: 2-way DFA Question: Why are DFAs required to only move right? Can we allow DFA to scan back and forth? Caveat: Tape is read-only so only memory is in machine s state. Can define a formal notion of a 2-way DFA Can show that any language recognized by a 2-way DFA can be recognized by a regular (-way) DFA Proof is tricky simulation via NFAs Chan, Har-Peled, Hassanieh (UIUC) CS374 36 Spring 29 36 / 36