Title: INHERENT LIMITATIONS OF COMPUTER PROGRAMS
1CSci 4011
INHERENT LIMITATIONS OF COMPUTER PROGRAMS
2M (Q, S, ?, q0, F) where
Q q0, q1, q2, q3
S 0,1
? Q ? S ? Q transition function
q0 ? Q is start state
F q1, q2 ? Q accept states
3THE 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
4REGULAR EXPRESSIONS
5REGULAR EXPRESSIONS
- is a regular expression representing ?
e is a regular expression representing e
? is a regular expression representing ?
If R1 and R2 are regular expressions representing
L1 and L2 then
(R1R2) represents L1?L2
(R1 ? R2) represents L1 ? L2
(R1) represents L1
6REGULAR EXPRESSIONS
( - ?) 09 (. ?) 09
? NICK STINKS ?
CSCI 1...40...90...909
? NICK RULES ?
7PRECEDENCE
? ?
EXAMPLE
R1R2 ? R3
(R1 (R2)) R3
8 w w has exactly a single 1
010
w w 3 and its 3rd symbol is 0
SS0S
w every odd position of w is a 1
(1S)(1e)
9EQUIVALENCE
L can be represented by a regexp ? L is a regular
language
10EQUIVALENCE
Given regular expression R, we show there exists
NFA N such that R represents L(N)
L can be represented by a regexp ? L is a regular
language
Induction on the length of R
11L can be represented by a regexp ? L is a regular
language
Base Cases (R has length 1)
R ?
R e
R ?
12Inductive Step
Assume R has length k gt 1 and that any regular
expression of length lt k represents a language
that can be recognized by an NFA
Three possibilities for R
R R1 ? R2
R R1R2
R (R1)
13L can be represented by a regexp ? L is a regular
language
14Transform (1(0 ? 1)) to an NFA
1
e
1,0
e
15CONVERT TO NFAs
a(be)a
(1?)1(?1)
(brett favre)
16Proof idea Transform an NFA for L into a regular
expression by removing states and re-labeling the
arrows with regular expressions
L can be represented by a regexp ? L is a regular
language
?
17GENERALIZED NFAs
ab
qs
qa
G accepts w if it finds q0q1qk, w1wk wi 2
R(qi,qi1) w w1w2wk q0qs, qkqa
R(qs,q2) ab
R(qa,q) Ø
R(q,qs) Ø
18NFA TO GNFA
NFA
Add unique and distinct start and accept states
19GNFA TO REGEXP
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
20q3
q0
R(q0,q3) (ab)(a?b)
21b
bb
a
q2
q1
a
e
b
e
b
a
e
q3
22b
bb
a
q2
q1
a ? ba
a
e
b
e
b
a
e
23b
R(q1,q1)
bb ? (a ? ba)ba
bb
a
q2
q1
a ? ba
e
e
b ? (a ? ba)b
b
24Convert the NFA to a regular expression
a, b
(a ? b)bb(bbb)
b
q2
q1
(a ? b)bb
e
b
(a ? b)bb(bbb)a
bbb
a
b
e
q3
e
25((a ? b)bb(bbb)a) ? ((a ? b)bb(bbb)a)(a
? b)bb(bbb)
26Formally
Add qstart and qaccept to create G
Run CONVERT(G)
If states 2
return the expression on the arrow going from
qstart to qaccept
If states gt 2
27Formally
Add qstart and qaccept to create G
Run CONVERT(G)
If states gt 2
select qrip?Q 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?)
28NFA
DFA
DEF
Regular Language
Regular Expression