Professional Documents
Culture Documents
Formal Languages
NFA − Λ
S. Pramanik
1
NFA − Λ
q q
q0 1 2
1
1 1
0
0,1
O 0,1 O
*
(01)
0* FA
FA
0
0 0
0 0
Λ
q 0 q q q q q
0 1 2 0 1 2
1 1
0* (01)* 0* (01)*
NFA NFA-
Figure 1:
2
• Definition: A nondeterministic finite automata with
Λ−transitions (abbreviated N F A−Λ) is a 5-tuple
(Q, Σ, q0, A, δ), where Q and Σ are finite sets, q0Q,
A ⊆ Q, and
δ : Q × (Σ ∪ {Λ}) → 2Q
• Note: Λ is not part of the alphabet. It is defined for
any N F A − Λ.
0
0
Λ
q q q
0 1 2
1
0* (01)*
NFA-
Figure 2:
q 0 1 Lambda
q0 {q0} {q1}
q1 {q2}
q2 {q1}
• Example:
δ(q0, Λ) = {q1}
δ(q0, 0) = {q0}
δ(q1, 0) = {q2}
δ(q2, 1) = {q1}
• δ ∗ for an NFA−Λ
3
For xΣ and pQ, p is the set of all states qQ such
that there is a sequence of transitions corresponding
to x by which the N F A − Λ moves from p to q.
• For the above NFA-Λ:
x=0
δ ∗(q0, 0) = {q0, q1}
δ ∗(q0, 00) = {q0, q1, q2}
δ ∗(q0, 10) = not defined
• Nondeterminism due to Λ-transitions (δ ∗(q0, 0) =
{q0, q1}).
• accept x=0?, x=00?, x=10?
0
q
1 1
q 0
0
0 q2 q3
*
(0+1)0
Figure 3:
4
GOAL: Find Equivalent NFA
1. NFA-Λ can make transitions on Λ
2. How can the equivalent NFA simulate these Λ-Transitions.
3. Basic Idea:
Λ-transition is a type of nondeterminism. If the tran-
sitions of NFA-Λ is as follows: p0 → q Λ → r
then from state p, the input symbol 0 allows us to go
to either q or r. Thus, we can eliminate the NFA-Λ
without changing the states, by simply adding the
transitions from p to r on input 0. Thus, we have the
following:
4.
5
Example:
b b
NFA- 1 2 3 4 5 6
a
b b
b
Process state 1: 1 2 3 4 5 6
b
Process state 2
b
b
a
a a
Process state 3
b
Similarly process states 4 and 5 , NFA: Combine the 5 NFA’s
6
Λ-Closure of a Set of States
p 1 r 0 s
q0
w
t 0 u 0 v
1 0
Figure 4:
7
N F A − Λ to NFA
Input N F A − Λ = (Q, Σ, q0, δ, A)
Output N F A = (Q1, Σ1, q1, δ1, A1)
Q1 = Q
Σ1 = Σ
q1 = q 0
What is A1?
Computing δ1(q, a):
δ1(q, a)= the set of states reachable from state q in
the NFA-Λ taking 0 or more Λ-transitions and exactly
one transition on the character a= Λ(δ(Λ(q), a)
Break this down into three steps:
• First compute all states reachable from q using o or
more Λ-transitions
- We call this set of states Λ(q)
• Next, compute all states reachable from any element
of Λ(q) using the character a
We can denote this states as δ(Λ(q), a)
• Finally, compute all states reachable from states in
δ(Λ(q), a) using 0 or more Λ-transitions.
- We denote these states as Λ(δ(Λ(q), a)
- This is the desired answer
8
Example of Computing δ1
δ1(1, b) = {3, 4, 5}
9
Recursive Definition of δ ∗ for an
NFA − Λ
• Definition of δ ∗
1. For any qQ, δ ∗ (q, Λ) = Λ({q})
2. For any qQ, yΣ∗, and aΣ,
δ ∗ (q, ya) = Λ(∪rδ∗(q,y)δ(r, a))
A string x is accepted by M if δ ∗(q0, x) ∩ A 6= ∅.
• Similar to δ ∗ of NFA except
1. Start with Λ infront of the input.
2. After each input symbol do Λ closure.
We will use recursive definition of δ ∗ to calculate
the set δ ∗(q0, abc). This set is defined in terms of
δ ∗(q0, ab), which is defined interms of δ ∗ (q0, a and
which is then defined interms of δ ∗(q0, Λ) which is
Λ(q0) (the base case). We, therefore approach the
calculation from bottom up, calculating δ ∗ (q0, Λ) first.
• δ ∗(q0, abc)
= δ ∗ (p, Λ/abc) where pP = Λ(δ(q0, Λ))
= δ ∗ (r, Λa/bc) where rR = Λ((δ(p, a), pP )
= δ ∗ (s, Λab/c) where sS = Λ((δ(r, b), rR)
= δ ∗ (m, Λabc/) where mM = Λ((δ(s, c), sS)
10
0 1
p 1 r 0 s
q0
w
t 0 u 0 v
1 0
Figure 5:
11
Constructing NFA from N F A − Λ
• Theorem: If L is accepted by an N F A − Λ, there is
an equivalent NFA that also accepts L.
q δ(q, Λ) δ(q, 0) δ(q, 1)
A {B} {A} ∅
• B {D} {C} ∅
C ∅ ∅ {B}
D ∅ {D} ∅
• δ ∗(A, 0) = {A, B, C, D}, δ ∗ (A, 1) = {????}, δ ∗ (B, 0) =
{C, D}
δ ∗(B, 1) = {?????}, δ ∗(C, 0) = {?????}, δ ∗ (C, 1) =
{?}
δ ∗(D, 0) = {????}, δ ∗ (D, 1) = {????}
• Draw NFA using the above transitions. Show δ1∗ for
the same inputs as above for NFA are the same.
• Prove that δ1∗ (q, x) = δ ∗(q, x) for any x except x=
Λ.
• See the difference: δ ∗ (A, Λ={A,B,D} but δ1∗ (A, Λ) =
{A}
• Justify conditions for acceptance states:
12
C
0
1 0
0
Λ Λ
A B D
0 0 1
1 0
0
0 0
A B D
Figure 6:
13
Theorem : For every language L ⊆ Σ∗ ac-
cepted by an NFA-Λ: M = (Q, Σ, q0, A, δ), there
is an NFA (without Λ−transitions): M1 = (Q1, Σ1, q1, A1, δ1)
that also accepts L.
Proof:
We define M1 as
Q1 = Q
Σ = Σ1
q0 = q 1
δ1(q, Λ) = ∅ (there is no Λ-transitions in M1
∀qQ and ∀σΣ
δ1(q, σ) = δ ∗ (q, σ)
and
A1 = A ∪ {q0} if ΛL else A1 = A
Second, assume | x |≥ 1
14
Assume | y |= n ≥ 1, δ1∗(q, y) = δ ∗(q, y) (hypothesis)
Then | yσ |= n + 1 and
δ1∗ (q, ya) = ∪{δ1(p, σ) | pδ1∗(q, y)} by definition of δ1∗
= ∪{δ1(p, σ) | pδ ∗(q, y)} by the induction hypothesis
= ∪{δ ∗(p, σ) | pδ ∗(q, y)} by definition of δ1 .
Now if xL(M ) we want to show xL(M1)
Because xL(M ), δ ∗(q0, x) contains an element of A;
therefore since δ ∗(q0, x) = δ1∗ (q0, x) and A ⊆ A1, xL(M1).
Now if xL(M1) we show xL(M )
If xL(M1) then δ1∗ (q0, x) contains an element of A1 . If
A1 = A then xL(M ). However, if A1 6= A then A1 has
q0 and A does not. If A1 contains q0 then ΛL(M1) i.e.,
δ1∗ (q0, x) contains q0. However, we have shown
δ1∗ (q0, x) = δ ∗ (q0, x) Thus,
δ ∗ (q0, x) contains q0 and therefore, contains Λ({q0)}
Thus, even when A1 6= A xL(M )
15
Theorem 4.3
1. L can be recognized by an FA
2. L can be recognized by an NFA
3. L can be recognized by an N F A − Λ
16
Kleene’s Theorem
• Examples:
q1 1 q2 0
UNION 1 0
q1 q2
0
q1 0 q3 1
q3
1
Figure 7:
Figure 8:
17
a
Figure 9:
f1 CONCATANATION OF M1 and M2
M1
q1
f’ 1 f1
f 2
qu q
qc=q 1 2
f2
f’1
q2 M2 f’ 2
f’ 2
KLEENE STAR OF M1
f 1
qk q
1 M1
f’1
Figure 10:
18
responding to an acceptance state of M1 . It will then
follow the Λ transition from this state to the state of
Mc that corresponds to the start state of M2 . Since x2
is accepted by M2 and Mc has all the states and the
transitions of M2 , Mc will reach the state that corre-
spond to the acceptance state of M2 which is also an
acceptance state of Mc . Thus Mc accepts x1x2.
Show if x is accepted by Mc then x = x1x2, and
x1 is accepted by M1 and x2 is accepted by M2 :
Since x is accepted by Mc , it starts in qc = q1 and ends
in qAc = A2. This can only be done through an inter-
mediate Λ transition as defined above.
Since Q1 ∩ Q2 = ∅, this crossing can happen only once.
All transitions before crossing are due to those of ma-
chine M1 and after crossing are due to those of M2 .
Thus, x = x1x2, x is accepted by Mc and x1 is used
before crossing and is accepted by M1 , x2 is used after
crossing and is accepted by M2 .
Proof for Mk :
Base case is similar to above that there exists N F A−Λ
for empty set, etc. We assume there is a N F A − Λ for
L then there is an N F A − Λ for L∗.
If xL∗ then xL(Mk )
and if xL(Mk ) then xL∗
xL∗ means that x = x1x2...xm, where each xiL
x can be written as (Λx1Λ)(Λx2Λ)...(ΛxmΛ)
Where each one of them (ΛxmΛ) gets accepted by M
and comes back to start state of L(Mk ). Therefore x is
accepted by L(Mk )
19
• Construct an N F A − Λ for the following regular expression
using Kleene’s theorem:
(1 + 0)∗1
0
*
(1+0) 1
1 1
Figure 11:
20