INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011
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 1 …w k | w k …w 1 A } Concatenation: A B = { vw | v A and w B } Star: A* = { w 1 …w k | k ≥ 0 and each w i A }
,1 0
NON -DETERMINISM ,1 0 An NFA accepts if there is a series of choices that take it to an accept state
Deterministic Computation Non-Deterministic Computation accept or rejectaccept reject
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, Σ, , Q 0, F) Output: M = (Q, Σ, , q 0, F) accept reject To learn if NFA accepts, we could do the computation in parallel, maintaining the set of states where all threads are Q = (Q) Idea:
(R, ) = ε( (r, ) ) Q = (Q) : Q Σ → Q (R, ) = ε( (r, ) ) rRrR q 0 = ε(Q 0 ) F = { R Q | f R for some f F } FROM NFA TO DFA Input: N = (Q, Σ, , Q 0, F) Output: M = (Q, Σ, , q 0, F) (R, ) = ε( (r, ) )
EXAMPLES: NFA TO DFA 1 0,1 ε a b 1
REGULAR LANGUAGES CLOSED UNDER CONCATENATION Given DFAs M 1 and M 2, construct NFA by connecting all accept states in M 1 to start states in M 2 ε ε L(M 1 )=A L(M 2 )=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 } Negation: A = { w | w A } Reverse: A R = { w 1 …w k | w k …w 1 A } Concatenation: A B = { vw | v A and w B } Star: A* = { w 1 …w k | k ≥ 0 and each w i A }
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* 0 0, ε ε ε
Formally: Input: M = (Q, Σ, , q 1, F) Output: N = (Q, Σ, , {q 0 }, F) Q = Q {q 0 } F = F {q 0 } (q,a) = { (q,a)} {q1}{q1} {q1}{q1} if q Q and a ≠ ε if q F and a = ε if q = q 0 and a = ε if q = q 0 and a ≠ ε else
L(N) = L* Assume w = w 1 …w k is in L*, where w 1,…,w k L We show N accepts w by induction on k Base Cases: k = 0 k = 1 Inductive Step: Assume N accepts all strings v = v 1 …v k L*, and let u = u 1 …u k u k+1 L* Since N accepts u 1 …u k and M accepts u k+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 } Negation: A = { w | w A } Reverse: A R = { w 1 …w k | w k …w 1 A } Concatenation: A B = { vw | v A and w B } Star: A* = { w 1 …w k | k ≥ 0 and each w i A }
REGULAR EXPRESSIONS
is a regular expression representing { } ε is a regular expression representing {ε} is a regular expression representing If R 1 and R 2 are regular expressions representing L 1 and L 2 then: (R 1 R 2 ) represents L 1 L 2 (R 1 R 2 ) represents L 1 L 2 (R 1 )* represents L 1 *
PRECEDENCE *
R2R2 R1*R1*( EXAMPLE R 1 *R 2 R 3 = ()) R3R3
{ w | w has exactly a single 1 } 0*10*
{ w | w has length ≥ 3 and its 3rd symbol is 0 } 000(0 1)* 010(0 1)* 100(0 1)* 110(0 1)*
{ w | every odd position of w is a 1 }