You are on page 1of 20

CSE 460: Computabilty and

Formal Languages

NFA − Λ

S. Pramanik

1
NFA − Λ

• Concatanation of languages 0∗ and (01)∗: 0∗(01)∗


0 0

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:

• N F A − Λ is an NFA but it also allows Λ-transitions.


• Advantage of NFA plus flexibility of Λ-transitions.

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:

For the above NFA-Λ

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:

Language=0∗(1+0)0∗ same as (0+1)0∗ or (0+1)∗(0+


1)(0 + 1)∗

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:

• For each state q of NFA-Λ and each character α


of Σ, figure out which states are reachable from q
taking any number of Λ-transitions and exactly
one transition on that character α.
• In the equivalent NFA, directly connect q to each
of these states using an arc labeled with α.

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

• Lambda Closure, Λ(S), for a set of states S is defined


as:
1. Every element of S is an element of Λ(S).
2. For any qΛ(S), every element of δ(q, Λ) is in
Λ(S).
3. No other elements of Q are in Λ(S).
• All states that can be reached through Λ transitions
only.
0 1

p 1 r 0 s

q0
w

t 0 u 0 v

1 0

Figure 4:

• Λ({s}) = {s, w, q0, p, t}

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}

1. Compute Λ(1), all states reachable from state 1 using


0 or more Λ-transitions
Λ(1) = {1, 2}
2. Compute δ(Λ(1), b), all states reachable from any el-
ement of Λ(1) using the character b
δ(Λ(1), b) = δ({1, 2}, b) = δ(1, b) ∪ δ(2, b) = {} ∪
{3} = {3}
3. Compute Λ(δ(Λ(1), b)), all states reachable from states
in δ(Λ(1), b) using 0 or more Λ-transitions.
Λ(δ(Λ(1), b)) = Λ(3) = {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:

• δ ∗(q0, 01) = δ ∗ (r, Λ/01), r{q0, p, t}

= δ ∗ (s, Λ0/1), sΛ(δ(q0, 0)∪δ(p, 0)∪δ(t, 0)) = Λ({p, u}) =


{p, u, }

= δ ∗(m, Λ01/), mΛ(δ(p, 1) ∪ δ(u, 1)) = Λ({r}) =


{r}

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:

1. Acceptance state of the N F A − Λ becomes the ac-


ceptance states of the NFA.
2. If Λ({q0}) contains an acceptance state then q0 also
becomes an acceptance state of the NFA. Justifica-
tion:

12
C

0
1 0
0

Λ Λ
A B D

0 0 1
1 0
0

0 0
A B D

Figure 6:

3. For the exercise problem:


Λ({A}) = {A, B, D} containing the final state D
Therefore, Both D and A are going to be final states.

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

We want to show L(M1) = L(M ) = L


First, assume | x |= 0

This is the base case for the proof by induction later.


If Λ is accepted by M then Λ({q0}) ⊆ A which includes
q0. By definition of M1, q0 = q1. Therefore, q1 A1 by
definition of M1. Λ is accepted by M1
If the string Λ¬L(M ), than A = A1; therefore, q0¬A1,
and Λ¬L(M1)

Second, assume | x |≥ 1

We prove δ1∗ (q, x) = δ ∗ (q, x) for | x |≥ 1


We prove this by induction:

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 )

NOTE: even if | x |≥ 1, M1 can go to q1 (for example


string x = 0∗, and x is accepted by reaching q1). In M,
the string Λ does not have to be accepted by reaching q0;
it is accepted by reaching any of the states in Λ({q0}).

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:

Does Not work:


q1 0 q2
0 q2
1 UNION?
q1
1
1 q3
q1 q3
0,1

Figure 8:

• Kleene’s Theorem 4.4 (Part 1):


Any regular language can be accepted by a finite automata.
Proof:
– By theorem 4.3 (same L can be recognized by FA, NFA
and Λ-NFA) it is sufficient to show that any regular
language can be accepted by an N F A − Λ.
– Definition 3.1 gives the definition of regular languages
and we construct N F A − Λ based on this definition.
– N F A − Λ for the three basic languages (figure 11):
∅, {Λ}, {a}(aΣ)
Now if L1 and L2 are two regular languages recognized
by two N F A−Λ’s M1:(Q1, Σ, q1, A1, δ1) and M2:(Q2, Σ, q2, A2, δ2)

17
a

Figure 9:

, then we give construction for N F A − Λs union, con-


catanation and kleen *, i.e., Mu , Mc, and Mk , recogniz-
ing languages L1 ∪ L2, L1 .L2 and L∗1 , respectively.
We will give construction for Mc : (Qc, Σ, qc, Ac, δc)
only:
By renaming states we can assume Q1 ∩ Q2 = ∅.
1. Qc = Q1 ∪ Q2
2. qc = q1
3. Ac = A2
4. Include all transitions of M1 and M2 in Mc
5. Add Λ transitions from each of the states in A1 to
q2 . Refer to the following figure:
UNION OF M1 AND M2

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:

Show that if x1 is accepted by M1 and x2 is ac-


cepted by M2 then x1x2 is accepted by Mc
Since x1 is accepted by M1 and Mc has all the states
and the transitions of M1 , Mc will reach the state cor-

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

You might also like