230 likes | 346 Views
CSci 4011. INHERENT LIMITATIONS OF COMPUTER PROGRAMS. THE REGULAR OPERATIONS. Negation: A = { w | w A }. Union: A B = { w | w A or w B }. Intersection: A B = { w | w A and w B }. Reverse: A R = { w 1 …w k | w k …w 1 A }.
E N D
CSci 4011 INHERENT LIMITATIONS OF COMPUTER PROGRAMS
THE REGULAR OPERATIONS Negation: A = { w | w A } Union: A B = { w | w A or w B } Intersection: A B = { w | w A and w B } Reverse: AR = { w1 …wk | wk …w1 A } Concatenation: A B = { vw | v A and w B } Star: A* = { w1 …wk | k ≥ 0 and each wi A }
0,1 1 0 0 0 1 1
NON-DETERMINISM 0,1 1 0 0 0 1 1 An NFA accepts if there is a series of choices that take it to an accept state
Deterministic Computation Non-Deterministic Computation reject accept or reject accept
Theorem: Every NFA has an equivalent DFA Corollary: A language is regular iff it is recognized by an NFA
FROM NFA TO DFA Input: N = (Q, Σ, , Q0, F) Output: M = (Q, Σ, , q0, F) To learn if NFA accepts, we could do the computation in parallel, maintaining the set of states where all threads are reject Idea: Q = 𝒫(Q) accept
FROM NFA TO DFA Input: N = (Q, Σ, , Q0, F) Output: M = (Q, Σ, , q0, F) Q = 𝒫(Q) : Q Σ→ Q (R,) = ε( (r,) ) (R,) = ε( (r,) ) (R,) = ε( (r,) ) rR q0 = ε(Q0) F = { R Q | f R for some f F }
EXAMPLES: NFA TO DFA 1 a b 0,1 ε 0 3 1 2 1
REGULAR LANGUAGES CLOSED UNDER CONCATENATION Given DFAs M1 and M2, construct NFA by connecting all accept states in M1 to start states in M2 ε L(M1)=A L(M2)=B ε
REGULAR LANGUAGES ARE CLOSED UNDER REGULAR OPERATIONS Union: A B = { w | w A or w B } Intersection: A B = { w | w A and w B } Reverse: AR = { w1 …wk | wk …w1 A } Negation: A = { w | w A } Concatenation: A B = { vw | v A and w B } Star: A* = { w1 …wk | k ≥ 0 and each wi A }
1 0 0,1 1 0 0 1 REGULAR LANGUAGES CLOSED UNDER STAR Let L be a regular language and M be a DFA for L We construct an NFA N that recognizes L* ε ε ε
Formally: Input: M = (Q, Σ, , q1, F) Output: N = (Q, Σ, , {q0}, F) Q = Q {q0} F = F {q0} {(q,a)} if q Q and a ≠ ε if q F and a = ε {q1} if q = q0 and a = ε {q1} (q,a) = if q = q0 and a ≠ ε else
L(N) = L* Assume w = w1…wk is in L*, where w1,…,wk L We show N accepts w by induction on k Base Cases: k = 0 k = 1 Inductive Step: Assume N accepts all strings v = v1…vk L*, and let u = u1…ukuk+1 L* Since N accepts u1…uk and M accepts uk+1, N must accept u
Assume w is accepted by N, we show w L* If w = ε, then w L* If w ≠ε ε ε accept
REGULAR LANGUAGES ARE CLOSED UNDER REGULAR OPERATIONS Union: A B = { w | w A or w B } Intersection: A B = { w | w A and w B } Reverse: AR = { w1 …wk | wk …w1 A } Negation: A = { w | w A } Concatenation: A B = { vw | v A and w B } Star: A* = { w1 …wk | k ≥ 0 and each wi A }
REGULAR EXPRESSIONS • is a regular expression representing {} ε is a regular expression representing {ε} is a regular expression representing If R1 and R2 are regular expressions representing L1 and L2 then: (R1R2) represents L1L2 (R1 R2) represents L1 L2 (R1)* represents L1*
PRECEDENCE *
EXAMPLE ( ( R1* ) R2 ) R3 R1*R2 R3 =
{ w | w has length ≥ 3 and its 3rd symbol is 0 } 000(01)* 010(01)* 100(01)* 110(01)*