Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 18

Finite Automata with

Epsilon-Transitions and with


Outputs

Finite Automata Theory


& Formal Languages

Khawaja 2023 Automata Theory & Languages 1


NFA with Epsilon Transitions

Khawaja 2023 Automata Theory & Languages 2


ε-NFA and ε-Transitions
• Finite Automata With Epsilon Transitions allows a transition on ε, the
empty string.
• In other words, it is allowed to make a transition spontaneously,
without receiving an input symbol.
• The class of languages accepted by this type of NFA is still regular.
• However, it gives us some added “programming convenience”.

Khawaja 2023 Automata Theory & Languages 3


First Example of ε-NFA
• Below is an ε-NFA that accepts decimal numbers consisting of:
1. An optional + or – sign,
2. A string of digits,
3. A decimal point and
4. Another string of digits. Either this string of digits, or the string in (2) can be
empty, but at least one of the two strings of digits must be nonempty.

Khawaja 2023 Automata Theory & Languages 4


Second Example of ε-NFA
• The NFA recognizing the keywords web and ebay can also be implemented with ε-
transitions.
• In general, we construct a complete sequence of states for each keyword, as if it
were the only word the automaton needed to recognize.
• Then, we add a new start state with ε-transitions to the start states of the automata
for each of the keywords.

Khawaja 2023 Automata Theory & Languages 5


Formal Notation for ε-NFA
ε-NFA is represented exactly as an NFA, with one exception, the transition
function must include information about transitions on ε.
Formally:
A = (Q, Σ, δ, q0, F)
Where:
All components have same interpretation as for NFA, except δ.
δ is now a function that takes as arguments:
1. A state in Q, and
2. A member of Σ U {ε}, that is, either an input symbol, or the symbol ε.
Note: We require that ε, the symbol for the empty string, cannot be a member of the alphabet
Σ, so no confusion results.

Khawaja 2023 Automata Theory & Languages 6


Transition Table for ε-NFA
The ε-NFA of first example is represented formally as:

Where δ is defined by the transition table below:

Khawaja 2023 Automata Theory & Languages 7


Epsilon Closures
• Informally, we ε-close a state q by following all transitions out of q that are labeled
ε.
Note: ECLOSE(q) includes q also.
• When we get to other states by following ε we follow the ε-transitions out of those
states also, and so on, eventually finding every state that can be reached from q
along any path whose arcs are all labeled ε.
• For example, in figure below,
ECLOSE(2) = { 2, 3, 6 } and
ECLOSE(1) = { 1, 2, 3, 4, 6 }

Khawaja 2023 Automata Theory & Languages 8


Converting ε-NFA To DFA

Khawaja 2023 Automata Theory & Languages 9


Converting an ε-NFA to DFA
1. Find the e-closure of the start state from the ε-NFA.
2. Use the e-closure found in step (1) as the starting state for the
transition table for resulting DFA
3. Complete the DFA table by taking the resulting states as the next
state in each step.

Note: For each symbol the resulting set of states will also include the
states for any ε-transitions immediately after that symbol.

Khawaja 2023 Automata Theory & Languages 10


Converting ε-NFA to DFA – Example 1
Strings of symbols 0 and 1, having zero or more occurrences of 10 only
ε
Start ε 1 ε 0 ε
1 2 3 4 5 6
ε

ECLOSE(1) = {1, 2, 6} 0 1
ECLOSE(2) = {2}
ECLOSE(3) = {3, 4} *{1, 2, 6} Ф [3, 4} 0, 1
ECLOSE(4) = {4} [3, 4} {2, 5, 6} Ф 0
ECLOSE(5) = {2, 5, 6} Ф {2, 5, 6}
ECLOSE(6) = {6} *{2, 5, 6} Ф [3, 4}
Ф Ф Ф 0 0 1
1
Start
{1, 2, 6} {3, 4}
1
Khawaja 2023 Automata Theory & Languages 11
Converting ε-NFA to DFA – Example 2
ε-NFA that accepts decimal numbers
ECLOSE(q0) = {q0, q1}
ECLOSE(q1) = {q1}
ECLOSE(q2) = {q2}
ECLOSE(q3) = {q3, q5}
ECLOSE(q4) = {q4}
ECLOSE(q5) = {q5}
+, - . 0,1,…,9
{q0, q1} {q1} {q2} {q1, q4}
[q1} Ф {q2} {q1, q4}
{q2} Ф Ф {q3, q5}
{q1, q4} Ф {q2, q3, q5} {q1, q4}
*{q3, q5} Ф Ф {q3, q5}
*{q2, q3, q5} Ф Ф {q3, q5}
Khawaja 2023 Automata Theory & Languages 12
DFA with Output
(Moore and Mealy Machines)

Khawaja 2023 Automata Theory & Languages 13


Moore and Mealy Machines
Formally, a Moore or a Mealy Machine is represented as:
A = (Q, Σ, δ, q0, O, λ)
Where:
A - Name of Moore/Mealy machine
Q - Finite Set of States
Σ - Input Alphabet
δ - Transition Function δ(q, a) = p
q0 - Start State
O - Output Alphabet
λ - Output Function (different for Moore and Mealy machines)

Khawaja 2023 Automata Theory & Languages 14


Moore Machine
Σ = {a, b}
O = {0, 1}
a b
b
Start
q0, 1 q1, 0
a
Output is determined by the state:
λ:QO
q0  1
q1  0

Ex: If input is ab, then output is 110


a b
q0 q0 q1

1 1 0

for n inputs, there are n+1 outputs


Khawaja 2023 Automata Theory & Languages 15
Example of Moore Machine
Construct a Moore machine that prints a 1 as output for every occurrence of
ab as substring over alphabet {a, b}.
(In other words, that counts the occurrences of ab in a string)
Σ = {a, b} b a
O = {0, 1} Start a b
q0, 0 q1, 0 q2, 1

(A DFA with string ending with ab, a


b
since starting with ab or containing
ab DFA’s will not be able to print 1 for all remaining ab after printing 1 for first ab.)

a b a b
For example, for input abab: q0 q1 q2 q1 q2

0 0 1 0 1
Khawaja 2023 Automata Theory & Languages 16
Mealy Machine
Σ = {a, b} a/1 b/0
O = {0, 1}
b/0
Start
q0 q1
a/1
Output is determined by the state and the input:
λ:QxΣO
(q0 , a)  1
(q0 , b)  0
(q1 , a)  1
(q1 , b)  0

Ex: If input is ab, then output


a is 10 b
q0 q0 q1
1 0
for n inputs, there are n outputs
Khawaja 2023 Automata Theory & Languages 17
Example of Mealy Machine
Construct a Mealy machine that prints a 1 as output for every occurrence of ab as
substring over alphabet {a, b}.
(In other words, that counts the occurrences of ab in a string)
Σ = {a, b} b/0 a/0
O = {0, 1} Start a/0 b/1
q0 q1 q2
a/0
(A DFA with string ending with ab, b/0
since starting with ab or containing
ab DFA’s will not be able to print 1 for all remaining ab after printing 1 for first ab.)

For example, for input abab: a b a b


q0 q1 q2 q1 q2
0 1 0 1

Khawaja 2023 Automata Theory & Languages 18

You might also like