Download presentation
Presentation is loading. Please wait.
Published byDrusilla Carroll Modified over 9 years ago
1
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011
2
Q = {q 0, q 1, q 2, q 3 } Σ = {0,1} : Q Σ → Q transition function * q 0 Q is start state F = {q 1, q 2 } Q accept states M = (Q, Σ, , q 0, F) where 01 q0q0 q0q0 q1q1 q1q1 q2q2 q2q2 q2q2 q3q3 q2q2 q3q3 q0q0 q2q2 * q2q2 0 0,1 0 0 1 1 1 q0q0 q1q1 q3q3 M
3
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 }
4
REGULAR EXPRESSIONS
5
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 *
6
REGULAR EXPRESSIONS (+ [ - [ ) {0…9}* (. [ ) {0…9} + * NICK STINKS * * NICK RULES * CSCI {1...4}{0...9}{0...9}{0…9}
7
PRECEDENCE * EXAMPLE R 1 R 2 * R 3 = (R 1 (R 2 *)) ∪ R 3
8
{ w | w has exactly a single 1 } 0*10* { w | | w | ≥ 3 and its 3rd symbol is 0 } { w | every odd position of w is a 1 } ΣΣ0Σ*ΣΣ0Σ* (1Σ)*(1 ∪ ε)
9
EQUIVALENCE L can be represented by a regexp L is a regular language
10
L can be represented by a regexp L is a regular language EQUIVALENCE Given regular expression R, we show there exists NFA N such that R represents L(N) Induction on the length of R:
11
Given regular expression R, we show there exists NFA N such that R represents L(N) Induction on the length of R: L can be represented by a regexp L is a regular language Base Cases (R has length 1): R = R = ε R =
12
Inductive Step: Assume R has length k > 1 and that any regular expression of length < k represents a language that can be recognized by an NFA Three possibilities for R: R = R 1 R 2 R = R 1 R 2 R = (R 1 )*
13
L can be represented by a regexp L is a regular language
14
Transform (1(0 1))* to an NFA 1ε1,0 ε
15
a*(b ∪ ε)a* (1 )* ∪ 1( 1)* (lol ∪ zomg)* CONVERT TO NFAs
16
L can be represented by a regexp L is a regular language Proof idea: Transform an NFA for L into a regular expression by removing states and re- labeling the arrows with regular expressions 0 1 0 01*0
17
GENERALIZED NFAs q2q2 a∪ba∪b a a*b qsqs qaqa R(q s,q 2 ) = a*b R(q a,q) = Ø R(q,q s ) = Ø G accepts w if it finds q 0 q 1 …q k, w 1 …w k : w i ∈ R(q i,q i+1 ) w = w 1 w 2 …w k q 0 =q s, q k =q a
18
NFA ε ε ε ε ε Add unique and distinct start and accept states NFA TO GNFA
19
NFA ε ε ε ε ε While machine has more than 2 states: Pick an internal state, rip it out and re- label the arrows with regular expressions to account for the missing state GNFA TO REGEXP
20
q1q1 b a ε q2q2 a,b ε a*b (a*b)(a b)* q0q0 q3q3 R(q 0,q 3 ) = (a*b)(a b)*
21
q3q3 q2q2 b a b q1q1 b a a ε ε ε bb
22
q2q2 b a b q1q1 a a ε ε ε a ba b
23
bb (a ba)b*a a ba q2q2 b q1q1 a ε ε bb b b (a ba)b* = R(q 1,q 1 )
24
Convert the NFA to a regular expression q3q3 q2q2 b b q1q1 a a, b ε ε ε b (a b)b*b bb*b (a b)b*b(bb*b)* (a b)b*b(bb*b)*a
25
((a b)b*b(bb*b)*a)* ((a b)b*b(bb*b)*a)*(a b)b*b(bb*b)*
26
Formally: Run CONVERT(G): If #states = 2 return the expression on the arrow going from q start to q accept Add q start and q accept to create G If #states > 2
27
Formally: Run CONVERT(G): Add q start and q accept to create G If #states > 2 select q rip Q different from q start and q accept define Q = Q – {q rip } define R as: R(q i,q j ) = R(q i,q rip )R(q rip,q rip )*R(q rip,q j ) R(q i,q j ) return CONVERT(G)
28
DFA NFA Regular Language Regular Expression DEF
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.