5-453 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
NON-DETERMINISM and REGULAR OPERATIONS THURSDAY JAN 6
UNION THEOREM The union of two regular languages is also a regular language Regular Languages Are Closed Under Union INTERSECTION THEOREM The intersection of two regular languages is also a regular language
Complement THEOREM The complement of a regular language is also a regular language In other words, if L is regular than so is L, where L= { w Σ* w L } Proof?
,, L(M) = { w w begins with }
,, L(M) = { w w begins with } Suppose our machine reads strings from right to left What language would be recognized then?
,, L(M) = { w w begins with } Suppose our machine reads strings from right to left What language would be recognized then? L(M) = { w w ends with } Is L(M) regular?
L(M) = { w w ends with } Is L(M) regular?
THE REVERSE OF A LANGUAGE Reverse: L R = { w w k w k w L, w i Σ} If L is recognized by a normal DFA, Then L R is recognized by a DFA reading from right to left! Can every Right-to-Left DFA be replaced by a normal DFA??
REVERSE THEOREM The reverse of a regular language is also a regular language ``Regular Languages Are Closed Under Reverse If a language can be recognized by a DFA that reads strings from right to left, then there is an normal DFA that accepts the same language
REVERSING DFAs Assume L is a regular language. Let M be a DFA that recognizes L Task: Build a DFA M R that accepts L R If M accepts w, then w describes a directed path in M from start to an accept state.
REVERSING DFAs Assume L is a regular language. Let M be a DFA that recognizes L Task: Build a DFA M R that accepts L R If M accepts w, then w describes a directed path in M from start to an accept state. First Attempt: Try to define M R as M with the arrows reversed. Turn start state into a final state. Turn final states into start states.
M R IS NOT ALWAYS A DFA! It could have many start states Some states may have too many outgoing edges, or none at all!
,
REVERSE, What happens with?
REVERSE, What happens with? We will say that this machine accepts a string if there is some path that reaches an accept state from a start state.
NONDETERMINISM is BORN!, What happens with? We will say that this machine accepts a string if there is some path that reaches an accept state from a start state.
IBM JOURNAL APRIL 959 Turing Award winning paper
NFA EXAMPLES,,, ε At each state, we can have any number of out arrows for each letter σ Σ ε = Σ {ε}
NFA EXAMPLES, ε L(M) = { i j i {,}, j } Possibly many start states
NFA EXAMPLES L(M)={,}
A non-deterministic finite automaton (NFA) is a 5-tuple N = (Q, Σ, δ, Q, F) Q is the set of states Σ is the alphabet δ : Q Σ ε 2 Q is the transition function Q Q is the set of start states F Q is the set of accept states 2 Q is the set of all possible subsets of Q Σ ε = Σ {ε}
Let w Σ* and suppose w can be written as w... w n where w i Σ ε (ε = empty string) Then N accepts w if there are r, r,..., r n Q such that. r Q 2. r i+ δ(r i, w i+ ) for i =,..., n-, and 3. r n F L(N) = the language recognized by N = set of all strings machine N accepts A language L is recognized by an NFA N if L = L(N).
Deterministic Computation Non-Deterministic Computation reject accept or reject accept
Deterministic Computation Non-Deterministic Computation reject accept or reject accept
q 2 q 4 N = (Q, Σ, δ, Q, F) Q = {q, q 2, q 3, q 4 } Σ = {,} q ε L(N)? L(N)? q 3 Q = {q, q 2 } F = {q 4 } Q δ(q 2,) = {q 4 } δ(q 3,) = δ(q 3, ε) = { q 2 } δ(q,) = { q 3 }
q 2 q 4 N = (Q, Σ, δ, Q, F) Q = {q, q 2, q 3, q 4 } Σ = {,} ε q 3 Q = {q, q 2 } F = {q 4 } Q δ ε q q {q 3 } q 2 {q 4 } q 3 {q 4 } {q 2 } q 4
q 2 q 4 N = (Q, Σ, δ, Q, F) Q = {q, q 2, q 3, q 4 } Σ = {,} Q = {q, q 2 } q 3 F = {q 4 } Q δ ε q q {q 2,q 3 } q 2 {q 4 } q 3 {q 4 } q 4
q 2 q 4 N = (Q, Σ, δ, Q, F) Q = {q, q 2, q 3, q 4 } Σ = {,} Q = {q, q 2 } q 3 F = {q 4 } Q δ ε q q {q 2,q 3 } q 2 {q 4 } q 3 {q 4 } q 4
MULTIPLE START STATES We allow multiple start states for NFAs, and Sipser allows only one Can easily convert NFA with many start states into one with a single start state: ε ε ε
UNION THEOREM FOR NFAs?
UNION THEOREM FOR NFAs?
NFAs ARE SIMPLER THAN DFAs A DFA that recognizes the language {}:,,
NFAs ARE SIMPLER THAN DFAs An NFA that recognizes the language {}: A DFA that recognizes the language {}:,,
BUT DFAs CAN SIMULATE NFAs! Theorem: Every NFA has an equivalent* DFA Corollary: A language is regular iff it is recognized by an NFA Corollary: L is regular iff L R is regular * N is equivalent to M if L(N) = L (M)
FROM NFA TO DFA Input: NFA N = (Q, Σ, δ, Q, F) Output: DFA M = (Q, Σ, δ, q, F ) accept reject To learn if NFA accepts, we could do the computation in parallel, maintaining the set of all possible states that can be reached Idea: Q = 2 Q
For R Q, the ε-closure of R, ε(r) = {q that can be reached from some r R by traveling along zero or more ε arrows} FROM NFA TO DFA Input: NFA N = (Q, Σ, δ, Q, F) Output: DFA M = (Q, Σ, δ, q, F ) Q = 2 Q δ : Q Σ Q δ (R,σ) = ε( δ(r,σ) ) r R q = ε(q ) * * F = { R Q f R for some f F }
EXAMPLE OF ε-closure,,,ε,ε q q q 2 ε({q }) = ε({q }) = ε({q 2 }) =
EXAMPLE OF ε-closure,,,ε,ε q q q 2 ε({q }) = {q, q, q 2 } ε({q }) = {q, q 2 } ε({q 2 }) = {q 2 }
Given: NFA N = ( {,2,3}, {a,b}, δ, {}, {} ) Construct: Equivalent DFA M N M = (2 {,2,3}, {a,b}, δ, {,3}, ) a b ε a a, b 2 3 ε({}) = {,3}
Given: NFA N = ( {,2,3}, {a,b}, δ, {}, {} ) Construct: Equivalent DFA M M = (2 {,2,3}, {a,b}, δ, {,3}, ) N a b a ε a {,3} {3} b b a, b 2 3 {2} a {2,3} ε({}) = {,3}
Given: NFA N = ( {,2,3}, {a,b}, δ, {}, {} ) Construct: Equivalent DFA M M = (2 {,2,3}, {a,b}, δ, {,3}, ) N a b a ε a {,3} a b {3} b b b a,b a, b 2 3 ε({}) = {,3} {2} a {2,3} b a a {}, {,2}? {,2,3}
N = ( Q, Σ, δ, Q, F ) Given: NFA N = ( {,2,3}, {a,b}, δ, {}, {} ) Construct: equivalent DFA M = (Q, Σ, δ, q, F ) a N a b ε 2 a, b 3 q = ε({}) = {,3} δ a b {} {2} {3} {,2} {,3} {2,3} {,2,3}
N = ( Q, Σ, δ, Q, F ) Given: NFA N = ( {,2,3}, {a,b}, δ, {}, {} ) Construct: equivalent DFA M = (Q, Σ, δ, q, F ) a N a b ε 2 a, b 3 q = ε({}) = {,3} δ a b {} {2} {3} {,2} {,3} {2,3} {,2,3}
N = ( Q, Σ, δ, Q, F ) Given: NFA N = ( {,2,3}, {a,b}, δ, {}, {} ) Construct: equivalent DFA M = (Q, Σ, δ, q, F ) a N a b ε 2 a, b 3 q = ε({}) = {,3} δ a b {} {2} {2} {2,3} {3} {3} {,3} {,2} {2,3} {2,3} {,3} {,3} {2} {2,3} {,2,3} {3} {,2,3} {,2,3} {2,3}
N = ( Q, Σ, δ, Q, F ) Given: NFA N = ( {,2,3}, {a,b}, δ, {}, {} ) Construct: equivalent DFA M = (Q, Σ, δ, q, F ) a N a b ε 2 a, b 3 q = ε({}) = {,3} δ a b {} {2} {2} {2,3} {3} {3} {,3} {,2} {2,3} {2,3} {,3} {,3} {2} {2,3} {,2,3} {3} {,2,3} {,2,3} {2,3}
NFAs CAN MAKE PROOFS MUCH EASIER! Remember this on your Homework!
REGULAR LANGUAGES CLOSED UNDER CONCATENATION Concatenation: A B = { vw v A and w B } Given DFAs M and M 2, connect accept states in M to start states in M 2,, L(N) = L(M ) L(M 2 )
REGULAR LANGUAGES CLOSED UNDER CONCATENATION Concatenation: A B = { vw v A and w B } Given DFAs M and M 2, connect accept states in M to start states in M 2, ε, ε L(N) = L(M ) L(M 2 )
REGULAR LANGUAGES CLOSED UNDER CONCATENATION Concatenation: A B = { vw v A and w B } Given DFAs M and M 2, connect accept states in M to start states in M 2, ε, ε L(N) = L(M ) L(M 2 )
RLs ARE CLOSED UNDER STAR Star: A* = { s s k k and each s i A } Let M be a DFA, and let L = L(M) Can construct an NFA N that recognizes L*,
RLs ARE CLOSED UNDER STAR Star: A* = { s s k k and each s i A } Let M be a DFA, and let L = L(M) Can construct an NFA N that recognizes L* ε, ε
RLs ARE CLOSED UNDER STAR Star: A* = { s s k k and each s i A } Let M be a DFA, and let L = L(M) Can construct an NFA N that recognizes L* ε, ε ε
Formally: Input: M = (Q, Σ, δ, q, F) Output: N = (Q, Σ, δ, {q }, F ) Q = Q {q } F = F {q } δ (q,a) = {δ(q,a)} {q } {q } if q Q and a ε if q F and a = ε if q = q and a = ε if q = q and a ε else
Show: L(N) = L* where L = L(M). L(N) L* 2. L(N) L*
. L(N) L* ( where L = L(M)) Assume w = w w k is in L*, where w,,w k L We show N accepts w by induction on k Base Cases: k = k = (w = ε) (w L)
. L(N) L* ( where L = L(M)) Assume w = w w k is in L*, where w,,w k L We show N accepts w by induction on k Base Cases: k = k = Inductive Step: (w = ε) (w L) Assume N accepts all strings v = v v k L*, v i L and let v = v v k v k+ L*, u j L Since N accepts v v k (by induction) and M accepts v k+, N must accept v
2. L(N) L* (where L = L(M)) Assume w is accepted by N, we show w L* If w = ε or w L, then w L*
2. L(N) L* (where L = L(M)) Assume w is accepted by N, we show w L* If w = ε or w L, then w L* If w ε or w L write w as w=uv, where v is the substring read after the last ε-transition
2. L(N) L* (where L = L(M)) Assume w is accepted by N, we show w L* If w = ε or w L, then w L* If w ε or w L write w as w=uv, where v is the substring read after the last ε-transition ε accept
2. L(N) L* (where L = L(M)) Assume w is accepted by N, we show w L* If w = ε or w L, then w L* If w ε or w L write w as w=uv, where v is the substring read after the last ε-transition ε ε accept
2. L(N) L* (where L = L(M)) Assume w is accepted by N, we show w L* If w = ε or w L, then w L* If w ε or w L write w as w=uv, where v is the substring read after the last ε-transition u ε ε v accept
2. L(N) L* (where L = L(M)) Assume w is accepted by N, we show w L* If w = ε or w L, then w L* If w ε or w L write w as w=uv, where v is the substring read after the last ε-transition u ε ε u L* By induction v v L accept
2. L(N) L* (where L = L(M)) Assume w is accepted by N, we show w L* If w = ε or w L, then w L* If w ε or w L write w as w=uv, where v is the substring read after the last ε-transition u ε ε u L* By induction v v L accept So, w=uv L*
REGULAR LANGUAGES ARE CLOSED UNDER THE REGULAR OPERATIONS Union: A B = { w w A or w B } Intersection: A B = { w w A and w B } Negation: A = { w Σ* w A } Reverse: A R = { w w k w k w A } Concatenation: A B = { vw v A and w B } Star: A* = { w w k k and each w i A }
WWW.FLAC.WS Read Chapters.3 and.4 of the book for next time