INHERENT LIMITATIONS OF COMPUTER PROGRAMS
description
Transcript of INHERENT LIMITATIONS OF COMPUTER PROGRAMS
INHERENT LIMITATIONS OF COMPUTER PROGRAMS
CSci 4011
Q = {q0, q1, q2, q3}
Σ = {0,1}
: Q Σ → Q transition function*q0 Q is start state
F = {q1, q2} Q accept states
M = (Q, Σ, , q0, F) where
0 1
q0 q0 q1
q1 q2 q2
q2 q3 q2
q3 q0 q2
*
q2
00,1
00
1
1
1
q0
q1
q3
M
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: 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 }
REGULAR EXPRESSIONS
REGULAR EXPRESSIONS
s 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*
REGULAR EXPRESSIONS
(+ - ∪ ∪ ε) {0…9}* (. ∪ ε) {0…9}+
* NICK STINKS *
* NICK RULES *
CSCI {1...4}{0...9}{0...9}{0…9}
PRECEDENCE
* EXAMPLE
R1R2* R3 = (R1 (R2*)) ∪ R3
{ 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Σ*
(1Σ)*(1∪ε)
EQUIVALENCEL can be represented by a regexp
L is a regular language
L can be represented by a regexp
L is a regular language
EQUIVALENCEGiven regular expression R, we show there exists NFA N such that R represents L(N)
Induction on the length of R:
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 =
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 = R1 R2
R = R1R2
R = (R1)*
L can be represented by a regexp
L is a regular language
Transform (1(0 1))* to an NFA
1ε 1,0
ε
a*(b∪ε)a*
(1)*∪1(1)*
(lol ∪ zomg)*
CONVERT TO NFAs
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
001*0
GENERALIZED NFAs
q2
a∪b
aa*bqs qa
R(qs,q2) = a*b
R(qa,q) = Ø
R(q,qs) = Ø
G accepts w if it finds q0q1…qk, w1…wk: wi ∈ R(qi,qi+1)w = w1w2…wk q0=qs, qk=qa
NFAε
ε
ε
ε
ε
Add unique and distinct start and accept states
NFA TO GNFA
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
q1
b
a
εq2
a,b
εa*b(a*b)(ab)*q0 q3
R(q0,q3) = (a*b)(ab)*
q3
q2
b
a
b
q1
b
a
a
ε
ε
ε
bb
q2
b
a
b
q1
a
a
ε
ε
ε
bb
a ba
b
bb (a ba)b*a
a baq2
b
q1
a
ε
ε
bb
bb (a ba)b*
= R(q1,q1)
Convert the NFA to a regular expression
q3
q2
b
bq1
a
a, b
ε
ε
εb
(a b)b*b
bb*b
(a b)b*b(bb*b)*
(a b)b*b(bb*b)*a
((a b)b*b(bb*b)*a)* ((a b)b*b(bb*b)*a)*(a b)b*b(bb*b)*
Formally:
Run CONVERT(G):
If #states = 2
return the expression on the arrow going from qstart to qaccept
Add qstart and qaccept to create G
If #states > 2
Formally:
Run CONVERT(G):
Add qstart and qaccept to create G
If #states > 2
select qripQ different from qstart and qaccept
define Q = Q – {qrip}
define R as:
R(qi,qj) = R(qi,qrip)R(qrip,qrip)*R(qrip,qj) R(qi,qj)
return CONVERT(G)
DFA NFA
RegularLanguage
RegularExpression
DEF