Non-deterministic Finite Automata with λ moves (λ-NFA)

Non-deterministic Finite Automata
with λ moves (λ-NFA)
• λ-NFA is an extension of NFA to include transitions on the empty input string λ
• A λ-NFA M is formally defined by the 5-tuple
M=(Q, Σ, δ, q0 , F )
with:
1. Q is a finite set of states
2. Σ is a finite set of input symbols (alphabet)
3. δ is a transition function
δ : Q × (Σ ∪ {λ}) −→ 2Q
4. q0 ∈ Q is a start state
5. F ⊆ Q is a final set of states
• As in DFA and NFA, λ-NFA transitions will
be represented in a form of digraph or a table
• Example
0
q0
1
λ
q1
2
λ
q2
• We can draw a λ-NFA as a finite control, which
is in some state from Q, reading a sequence of
symbols from Σ written on a tape, as in DFA
and NFA.
• Extension of transition δ
First we give the following definition of
λ-closure:
λ-closure(q)=
{p: there is a path from q to p labeled λ}
λ-closure(P)=∪q∈P λ-closure(q)
Now we extend δ. We have δ defined as
δ : Q × (Σ ∪ {λ}) −→ 2Q
on symbols and single states. This definition
can be extended in two ways:
1. extension to strings: δb : Q × Σ∗ −→ 2Q such
that:
b λ) =λ-closure(q)
(a) δ(q,
b wa)= λ-closure(P)
(b) δ(q,
b w)},
where P= {p : p ∈ δ(r, a), r ∈ δ(q,
a ∈ Σ and w ∈ Σ∗ .
2. extension to sets of states: δb : 2Q ×Σ∗ −→ 2Q
where:
b a)=∪q∈R δ(q, a)
(a) δ(R,
b w)=∪q∈R δ(q,
b w) here we have R ⊆ Q
(b) δ(R,
• Note that: unlike DFA an NFA, for λ-NFA we
b a) 6= δ(q, a) in general, so for λ-NFA
have δ(q,
b
we can not use δ instead of δ.
2
• Accepted strings: For a λ-NFA M=(Q, Σ, δ, q0 , F ),
a string w ∈ Σ∗ is accepted by M if
b 0 , w) ∩ F 6= ∅
δ(q
• Accepted Language: For a λ-NFA M=(Q, Σ, δ, q0 , F )
the language accepted by M is defined by:
b 0 , w) ∩ F 6= ∅}
L(M ) = {w : δ(q
• Example: Consider the following λ-NFA
0
q0
1
λ
q1
2
λ
q2
L(M )={w: w starts with any number of 0’s
followed by any number of 1’s followed by
any number of 2’s}.
Ex. Show that the string w=01 is accepted by
this λ-NFA?
(More explanation about this example will be
given in the lecture).
3
Equivalence of NFA’s and λ-NFA’s
We have NFA ⇐⇒ λ-NFA
1. for NFA =⇒ λ-NFA the proof is obvious
2. for NFA ⇐= λ-NFA the proof is shown by the
following theorem
Theorem 2
Let L be a language accepted by an λ-NFA M ,
then there exists an NFA M 0 that accepts L.
Proof: the complete proof will be described in
the lecture
• Example:
Given the NFA M=(Q, Σ, δ, q0 , F ), where Q =
{q0 , q1 , q2 }, Σ = {0, 1, 2}, F = {q2 }, and δ is defined by
0
q0
1
λ
q1
Construct its equivalent NFA.
4
2
λ
q2
Finite Automata with output (Transducer)
•
Moore machine
A Moore machine M is formally defined by
the 6-tuple
M=(Q, Σ, ∆, δ, τ, q0 )
with:
1. Q is a finite set of states
2. Σ is a finite set of input symbols
3. ∆ is a finite set of output symbols
4. δ is a transition function
δ : Q × Σ −→ Q
i.e. for q ∈ Q, a ∈ Σ, δ(q, a) = p for some
p∈Q
5. τ is the output function
τ : Q −→ ∆
giving the output associated with each state,
that is:
if for all 1 ≤ i ≤ n δ(qi−1 , ai ) = qi ,
then the output τ (q0 )τ (q1 ) · · · τ (qn ) is the
response of M on the input string a1 a2 · · · an
Note that any Moore Machine gives output τ (q0 ) in response to input λ (the empty
string)
6. q0 ∈ Q is a start state
5
• As in DFA, NFA, and λ-NFA transitions of
Moore machines will be represented in a form
of digraph or a table
• Example:
consider the following Moore machine with
input alphabet Σ = {0, 1}, output alphabet
∆ = {a, b, c}, τ (q0 ) = a, τ (q1 ) = b, τ (q2 ) = c, and δ
is defined by the digraph
0
1
0
q0
q1
q2
1
0
a
c
b
1
The output of this Moore machine in response
to the input string w = 0110 ∈ Σ∗ is aabaa ∈ ∆∗
• We can draw a Moore machine as a finite control, which is in some state from Q, reading
a sequence of symbols from Σ written on an
input tape, and write a sequence of symbols
from ∆ on an output tape:
input string a1 a2 · · · an
a1
q0
a2
q1
..........
an
qn
τ (qn )
:
:
Control
:
τ (q1 )
output string τ (q0 )τ (q1 ) · · · τ (qn )
τ (q0 )
•
Mealy machine
A Mealy machine M is formally defined by
the 6-tuple
M=(Q, Σ, ∆, δ, τ, q0 ), where:
Q is a finite set of states
Σ is a finite set of input symbols
∆ is a finite set of output symbols
δ is a transition function
δ : Q × Σ −→ Q
i.e. for q ∈ Q, a ∈ Σ, δ(q, a) = p for some
p∈Q
5. τ is the output function
τ : Q × Σ −→ ∆
such that:
if for all 1 ≤ i ≤ n δ(qi−1 , ai ) = qi ,
then the output τ (q0 , a1 )τ (q1 , a2 ) · · · τ (qn−1 , an )
is the response of M on the input string
a1 a2 · · · an
6. q0 ∈ Q is a start state
1.
2.
3.
4.
• As in DFA, NFA, λ-NFA, and Moore machines,
transitions of Mealy machines will be represented in a form of digraph or a table.
• As in Moore machines, we can draw a Mealy
machine as a finite control, which is in some
state from Q, reading a sequence of symbols
from Σ written on an input tape, and write
a sequence of symbols from ∆ on an output
tape.
7
• Example:
consider the following Mealy machine with
input alphabet Σ = {0, 1}, output alphabet
∆ = {y, n}, τ defined by:
τ (q0 , 0) = n, τ (q0 , 1) = n,
τ (q1 , 0) = y, τ (q1 , 1) = n,
τ (q2 , 0) = n, τ (q2 , 1) = y,
and δ is defined by the digraph
0/y
q1
0/n
q0
1/n
0/n
1/n
q2
1/y
The output of this Mealy machine in response
to the input string w = 0110 ∈ Σ∗ is nnyn ∈ ∆∗
8
Equivalence of Moore and Mealy
machines
We have Moore machine ⇐⇒ Mealy machine
1. for Moore machine =⇒ Mealy machine. See
theorem A below
2. for Moore machine ⇐= Mealy machine. See
theorem B below
Theorem A
For every Moore machine M1 there exists an equivalent Mealy machine M2
Theorem B
For every Mealy machine M1 there exists an equivalent Moore machine M2
9