x | x in A or x in B

Regular Operations on Languages
A, B languages
A
B = { x | x in A or x in B}
A
B = {xy | x in A and y in B}
A * = {x1 x2 ... xk | k > 0 and each xi in A}
If A1 and A2 are regular, then A1 A2 is regular.
Proof: Regular languages are closed under union
Let M1 = (Q1, ,
Let M2 = (Q2, ,
, q1, F1)
, q2, F2)
2
1
Construct M = (Q, , , q 0, F) to recognize
A1
A2 as follows.
Q = {(r1, r2) | r1 in Q1 and r2 in Q2} = Q1 X Q2
( (r1,r2), a ) = ( 1(r1, a),
2
(r2, a))
q 0 = (q 1 , q2 )
F = { (r1,r2) | r1 in F1 or r2 in F2}
Union FA of FA’s
Q1 = { q0, q1, q2}
= { 0,1}
q1
q0
q2
L(M1) = { w | the sum of w’s digits is a multiple of 3}
Q2 = { s0, s1}
s0
= { 0,1}
s1
L(M2) = { w | the sum of w’s digits is a multiple of 2}
What about other Regular Operations?
A, B languages
A
B
A
B
DFA D1
DFA D2
A*
May not be
DFA!!
Nondeterministic Finite Automata
Nondeterminism allows several possible next
states (no one state is determined)
Deterministic
a
S.D.
Nondeterministic
a
a
a
a
q0
Computation
q0
q1
q1
q2
..
ql
q2
qr
qa
NFA that accepts multiples of 2 or 3
Q = { q0, q1, q2, s0, s1, new}
= { 0,1}
q1
q0
q2
new
s0
s1
L(M) = { w | sum of w’s digits is a multiple of 2 or 3}
NFA vs. DFA
NFA are seemingly more powerful (NOT!)
NFA allow choice of next state
When choice, NFA may be more compact
Handling
q1
q2
If in q1 reading input symbol a, and take
still reading a, but in state q2.
All
edge,
edges must be included in execution tree.
Qu: Is every DFA an NFA?
Example NFA
b
b
a
a,b
b
a,b
Execution on baabb
L(M) =
More Example NFA’s
a
b
b
a
a
a
or
1
1
a
q
b
0
2
b
2
b
Equivalence of NFA and DFA
Def: Two NFA M1, M2 are equivalent if
L(M1) = L(M2).
Th.: For each NFA, there is an equivalent DFA.
Proof: Let N = ( Q, , , q , F)
M = (Q’,
, ’ , q’ , F ’)
Q
2.
1. Q’ =
3. q ’ = {q }
0
0
be an NFA.
’ (R, a) =
(r,a)
4. F’ = { R in Q’ | R
F =
Equivalence of NFA and DFA
Proof: For R a subset of Q, define
E(R) = {q | q can be reached from some state
in R by following only edges}
Change the construction in Case 1 as follows:
2. ’ (R, a) = { q in Q | q in E( (r,a)) for some
r in R}
3. q ’ = {E(q ) }
0
0
M keeps track of exactly the subset of states N
would be in, and accepts when N accepts.
}
Equivalence of NFA and DFA
Cor.: A language is regular iff some NFA
recognizes it.
Example: NFA, construct DFA
1
b
2
a,b
a
3
Get lots of states....can we do better?