Title: INHERENT LIMITATIONS OF COMPUTER PROGAMS
1CSci 4011
INHERENT LIMITATIONS OF COMPUTER PROGAMS
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 Language of M, L(M), is the set of strings
that M accepts
A language is regular if it is recognized by a
deterministic finite automaton
L w w contains 001 is regular
L w w has an even number of 1s is regular
4Many interesting programs accept regular languages
- NETWORK PROTOCOLS
- COMPILERS
- SUBSTRING GENETIC TESTING
- BACKWARDS ARITHMETIC
5THE 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
6- THEOREM The Regular Languages are closed under
the regular operations.
If A and B are regular, applying any regular
operation yields a regular language.
7THE 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
8UNION THEOREM
Given two languages, L1 and L2, define the union
of L1 and L2 as L1 ? L2 w w ? L1 or w ? L2
Theorem The union of two regular languages is
also a regular language
9Theorem The union of two regular languages is
also a regular language
Proof Let M1 (Q1, S, ?1, q0, F1) be finite
automaton for L1 and M2 (Q2, S, ?2, q0, F2)
be finite automaton for L2
1
2
We want to construct a finite automaton M (Q,
S, ?, q0, F) that recognizes L L1 ? L2
10Theorem The union of two regular languages is
also a regular language
M1
M2
M ?
11Idea Run both M1 and M2 at the same time!
F (q1, q2) q1 ? F1 or q2 ? F2
?( (q1,q2), ?) (?1(q1, ?), ?2(q2, ?))
12Theorem The union of two regular languages is
also a regular language
131
q0,p0
q1,p0
1
0
0
0
0
1
q0,p1
q1,p1
1
14THE 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
15REVERSE CLOSURE
Regular languages are closed under reverse
Assume L is a regular language and M recognizes L
We build MR that accepts LR
If M accepts w then w describes a directed path
in M from start to an accept state
Define MR as M with the arrows reversed
16MR IS NOT ALWAYS A DFA!
It may have many start states
Some states may have too many outgoing edges, or
none
170,1
1
0
0
0
1
1
18NON-DETERMINISM
0,1
1
0
0
0
1
1
What happens with 100?
We will say that the machine accepts if there is
a way to make it reach an accept state
19Deterministic Computation
Non-Deterministic Computation
reject
accept or reject
accept
200,1
0,1
0,e
0
211
1
0,1
e
0
0
221
0
0
L(M)1,00
23A non-deterministic finite automaton is a 5-tuple
N (Q, S, ?, Q0, F)
Q is the set of states
S is the alphabet
? Q ? Se ? P(Q) is the transition function
Q0 ? Q is the set of start states
F ? Q is the set of accept states
P(Q) is the set of subsets of Q and Se S ? e
241
q4
q2
0
N (Q, S, ?, Q0, F)
q3
Q q1, q2, q3, q4
0
S 0,1
q1
Q0 q1, q2
F q4 ? Q
?(q2,1)
q4
?(q3,1)
?
250,1
0,1
0,e
0
q1
q3
q2
N (Q, S, ?, Q0, F)
Q q1, q2, q3
?(q1,0)
q1, q2
S 0,1
?(q1,e)
q2
Q0 q1
F q3 ? Q
?(q2,1)
?
26MULTIPLE START STATES
We allow multiple start states for NFAs, and
Sipser allows only one
Can easily convert NFA with many start states
into one with a single start state
e
e
e
27UNION THEOREM FOR NFAs
0
0
1
0
1
28NFAs ARE SIMPLER THAN DFAs
An NFA that recognizes the language 1
1
A DFA that recognizes the language 1
0,1
0
1
0,1
29Theorem Every NFA has an equivalent DFA
Corollary A language is regular iff it is
recognized by an NFA
Corollary L is regular iff LR is regular
30THE 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