Automata Unit2
Automata Unit2
q3/0
1 1 0
Moore and Mealy Machines: Finite automata 0
with output: The finite automata which we were q0/0 q2/0
considered in the earlier have binary output i.e. 1 1
either they accept the string or they do not accept q1/1
the string. This acceptability was decided on the 0
basis of the reachability of final state by the Transition graph
initial state. Now, we remove this restriction and input string ⟶ 0111
consider the model where the outputs can be
chosen from some other alphabets. q0 0 q3 1 q0 1 q1 1 q2
The value of the output function Z(t) in the most output ⟶ 00010
general case is a function of the present state q(t)
and present input x(t), i.e. Definition: A Mealy machine has 6-tuple
Z(t) = λ(q(t), x(t) ) (Q, Σ, Δ,δ, λ,q0), where
Where λ is called the output function. This I. Q is a finite set of states.
generalized model is usually called the mealy II. Δ is the output alphabet,
machine. III. Σ is the input alphabet,
if the output function Z(t) depends only on the IV. δ is the transition function Σ × Q into Q.
present state and is independent of the current V. λ is the output function mapping Σ × Q into Δ.
input, the output function may be written as VI. q0 is initial state.
Z(T) = λ(q(t))
this restricted model is called the Moore machine. Example: Mealy Machine
q1 0 q3 0 q2 1 q4 1 q3
Output String = 0100
Note: for a Moore machine, if the input string is Present a=0 a=1
of length n, the output string is of length n+1. The State Next O/p Next O/p
first output is λ(q0) for all output strings. In the ⟶q1 q3 0 q20 0
case of a Mealy machine if the input string is of q20 q1 1 q40 0
q21 q1 1 q41 1
length n, the output string is also same length. q3 q21 1 q1 1
q40 q41 1 q3 0
Convert the Following Moore Machine to Mealy
q41 q41 1 q3 0
Machine.
Convert the Following Mealy Machine to Moore Present Next State Output
Machine. State a=0 a=1 (λ)
⟶q1 q21 q31 ∧
Present a=0 a=1 q21 q22 q31 z1
State Next O/p Next O/p q22 q22 q31 z2
⟶q1 q3 0 q2 0 q3 q21 q32 z1
q2 q1 1 q4 0 q3 q21 q32 z2
q3 q2 1 q1 1
q4 q4 1 q3 0
Question: Design a Moore machine which counts By the analyzing mealy machine transition
the occurrence of substring aab in input string. diagram, we can easily notice that it is also finite
Solution: Let the Moore machine be automata without any final state and output is
M0 = (Q, Σ, Δ, δ, λ,q0) there for input-symbol on corresponding
Q = { q0, q1, q2, q3 } transition. Output for every input symbol is
Σ = { a, b} represented as level on each transition
We will design this machine in such a way that corresponding output. For e.q. in between q1 and
machine prints out the character 0 except for q3, q2 is labeled by 0/1, 0 is input symbol and 1 is the
which prints a 1. To get q3, we must come from output symbol.
state q2 and have 1st read b. To get state q2, we
Question: Design a mealy machine, which prints
must read atleast two a’s in a row, having started
1’s complement of input bit string over alphabet
in any state.
Σ = { 0, 1}.
Δ={0,1}
Solution: If input string is 101110 then 1’s
λ’(q0) = 0, λ’(q1) = 0, λ’(q2) = 0, λ’(q3) = 1 complements of 101110 will be 010001, so we
The following machine will counts aab have to design a mealy machine which will print
occurrence for us. output 010001 for the input string 10110.
a
M0 = (Q, Σ, Δ, δ, λ,q0)
a
Q = { q0 }
a
q0/0 q0/1 q0/0 b q0/1 Σ = { 0, 1}
b Δ={0,1}
a
b b q0 is the initial state.
0/0 1/0 q2
1/0 0/1
Arden’s Theorem: let P and Q be two regular Conversion of FA to Regular Expression.
expressions over Σ. If P does not contain ∧, then
Example: The transition system is given in figure.
the following equation in R, is
R = Q + RP ---(i) a a b a
d0,1
Fo
Proof: let S1 and S2 be te two regular sets. C1 belongs to the language set L and those in the
since S2 is a regular set, s 2 is also a regular class C2 do not belongs to L.
set, (S1 ∩ s 2) is also a regular set. The language L can be implemented on the finite
state machine (FSM) such that each state in the
S1 ∩ s 2 = S1 – S2 is also a regular set.
FSM corresponds to a particular class.
Therefore, regular sets are closed over the
intersection operation. FA contains minimum two states.
7. Regular sets are closed over the Kleene’s
1. where the strings belonging to the class
star. C1 reach the final state and
proof: The closure over Kleene’s star(∗) is 2. Other where the strings belonging to the
also known as Kleene’s closure. closure of a class C2 reach the non-final state. Thus,
regular set over Kleene’s star means that if R the language L can be implemented using
is a regular expression, then R* is also a a FA.
regular expression. 0 0
1
Let R be a regular expression and M be its
F
corresponding finite automaton, as shown in S
figure, 1
Since L1 is regular.
q0 qi qk qf
Similarly consider a language L2 over {0, 1} such
that all strings belonging to L2 wnd with 00.
Now wrap around the finite automaton M and
all the string classified into 5-classes.
superimpose the final state qf with the initial state
q0 to make the initial state as the final state and to Class C1: string length less than 2 I.e. ∧, 0, 1.
create a new finite automaton, say M’ as shown Class C2: those ending with 00.
in figure. Class C3: those ending with 01.
Class C4: those ending with 10.
q0 qi qk Class C5: those ending with 11.
1 0
Now if a string ω is accepted by the finite 0
0 qf
automaton M, then M’ accepts all the strings that q0 q1
involve the repetition of ω. such as ∧, ω, ωω,
1
ωωω and so on. Thus, M’ is a finite automaton
for R*. since there exists a finite automaton for since L2 is regular
R*, it is a regular set corresponding to R*. Hence, “If the number of equivalent classes over a
regular sets are closed over Kleene’s closure. language L is finite then the language L is
regular”. This statement is refered to as Myhill-
Myhill-Nerode Theorem [ Equivalent classes
Nerode theorem.
and Regular Languages]: Consider a language
L with Σ = {0, 1} such that a string ω belong to L L3 = {0n1n|n>0} to recognize this machine should
if and only if it ends with 0. we can categorized, be able to remember how many 0’s it has seen
all the strings into two categories ( classes), those and if the no. of 1’s is exactly the same as that of
ending with 0(say class C1) and those ending number of 0’s. However, the FSM is devoid of
with 1(say class C2). All the strings in the class any kind of memory the 0 count and match it
with the 1 count. the no. of equivalent classes belongs to L6, otherwise it does not since the
generated by the language L3 over {0,1}* is number of equivalent classes. for L6 is finite(9),
infinite, with each class corresponding to number the language L6 can be implemented on the FSM
of 0’s on any string. Since the number equivalent and therefore L6 is regular.
classes are not finite, according to Myhill-Nerode Current Input Symbol
theorem, the language L3 is not regular. state 0 1 2 3 4 5 6 7 8 9
⟶ q0 q0 q1 q2 q3 q4 q5 q6 q7 q8 q0
Consider a language L4 = {w|w is palindrome q1 q1 q2 q3 q4 q5 q6 q7 q8 q0 q1
over {a,b}}. q2 q2 q3 q4 q5 q6 q7 q8 q0 q1 q2
q3 q3 q4 q5 q6 q7 q8 q0 q1 q2 q3
Now, the recursive definition of a palindrome q4 q4 q5 q6 q7 q8 q0 q1 q2 q3 q4
over {a, b} is as follows: q5 q5 q6 q7 q8 q0 q1 q2 q3 q4 q5
∧ - is a palindrome q6 q6 q7 q8 q0 q1 q2 q3 q4 q5 q6
q7 q7 q8 q0 q1 q2 q3 q4 q5 q6 q7
a – is a palindrome
q8 q8 q0 q1 q2 q3 q4 q5 q6 q7 q8
b – is a palindrome
if a string x is a palindrome then axa, bxb are Minimization of Finite Automata:
palindromes.
Definition: Two state q1 and q2 are equivalent (
To recognize L4, a machine should be able to denoted by q1≡q2). if both δ(q1, x) and δ(q2, x) are
mark the middle of the string and match the final states or both of them are non final state for
symbols on the both sides of the middle. FSM all x∈Σ*.
has no memory, so counting is n’t possible.
As it is difficult to construct δ(q1, x) and δ(q2, x)
another possible mechanism is to create a class
for all x∈Σ* because there are an infinite number
corresponding to the string before the middle of
of strings in Σ*.
the input string and to match this class with the
class of the reverse string after the middle. if they Definition: Two states q1 and q2 are k-equivalent(
are same then the string is a palindrome. k≥ 0 ) if both δ(q1, x) and δ(q2, x) are final states
Otherwise, it is not. However the number of or both non final states for all strings x of length
possible classes for the string before the middle is k or less.
infinite; hence the language L4 can not be Example:
implemented on a finite automaton and hence, is Current State Input State
not regular. a b
⟶q0 q1(N) q4(N)
L5 = {ww | w is a string over {0.1} is not regular} q1 q5(N) qf(F)
because the language L5 belongs to the same q2 qf(F) q5(N)
group as the language L4. q3 q6(N) q4(N)
q4 qf(F) q5(N)
L6 over Σ = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; a string w
q5 q5(N) q3(N)
over Σ* belongs to L6 if the number formed by w q6 q5(N) qf(F)
is divisible by 9. q0(N) qf(F)
qf
For example: 9, 18, 27, . . . are belongs to L6 1,
2, 3, . . . rest does not belongs to L6. a) 0-level equivalence: The only string with
Here string can be divided into 9 equivalent length zero i.e. ∧, if ∧ is applied on any state
classes, with each class corresponding to a qi remains on the same state qi.
remainder 0 to 8. if remainder 0, then the string if ∧ is applied in state qf we get final state.
if ∧ is applied in state any other state,
we get non final state. Current Input Symbol
The state of state Q can be partitioned state aaa aab aba abb baa bab bba bbb
into two subsets: {qf} and {q0, q1, q2, q3, q0 q5(N) q3(N) q0(N) qf(N) q0(N) qf(N) q5(N) q3(N)
q3 q5(N) q3(N) q0(N) qf(N) q0(N) qf(N) q5(N) q3(N)
q4, q5, q6}
This partition is denoted by
q1 q5(N) q3(N) q0(N) q4(N) q1(N) q4(N) q0(N) qf(N)
π0 = { {q0, q1, q2, q3, q4, q5, q6}, {qf}} q6 q5(N) q3(N) q3(N) q4(N) q1(N) q4(N) q0(N) qf(N)
b) 1- Level equivalence: The strings with
length one are a and b, equivalence at q2 q1(N) q4(N) q0(N) qf(N) q5(N) q3(N) q6(N) q4(N)
level 1 can exists if and only if, there q4 q1(N) q4(N) q0(N) qf(N) q5(N) q3(N) q6(N) q4(N)
exists equivalence at level 0. Hence, qf
cannot be equivalent to any other state at Algorithm (minimization of Finite
level 1. Automaton):
1) The state q0, q3, & q5 have same
behavior. These state lead to a non-final Step 1: (construction of π0): By definition of 0-
state for both the strings a and b. level equivalence, π0 = {Q10, Q20 } where Q10 is
2) The state q2 and q4 have the same the set of all final states and Q20 = Q – Q10.
behavior a- F, b-NF. Step 2: (Construction of πk+1 and πk ): let Qik be
Hence the set partition for 1-level any subset in πk. if q1 and q2 are in Qik, they are
equivalence is as follows: (k+1)-equivalent provided δ(q1, a ) and δ(q2, a )
π1 = { {q0, q3, q5}, {q1,q6}, {q2 q4}}, {qf}} are in the same equivalent class in πk for every
a∈Σ.
Current Input String
state aa ab ba bb if so, q1 and q2 are (k+1)- equivalent. in this way,
q0 q5(N) qf(F) qf(F) q5(N) Qik is further divided into (k+1)-equivalent
q3 q5(N) qf(F) qf(F) q5(N) classes. repeat this for every Qik in πk to get all
q5 q5(N) q3(N) q6(N) q4(N)
the elements of πk+1.
q1 q5(N) q3(N) q0(N) qf(F) Step 3: Construct πn for n = 1, 2, … until πn =
q6 q5(N) q3(N) q0(N) qf(F) πn+1.