Moore Machine and Mealy machine (FA with output)
Both Moore and Mealy machine are special case of DFA.
Both acts like output producers rather than language acceptors
In Moore and Mealy machine no need to define final state.
No concepts of dead states and no concepts of final states.
Both machines are equivalent in power.
Finite automata may have outputs corresponding to each transition.
There are two types of finite state machines that generate output as:
Mealy Machine
Moore machine
Moore Machine
In computation theory, we refer to a Moore Machine as a Finite State Machine(FSM).
In a Moore Machine, we determine the output values by their current state only.
It is a finite state machine in which the next state is decided by the current state and current
input symbol.
The output symbol at a given time depends only on the present state of the machine.
In Moore machine for every state output is associated.
If the length of input string is n, then the length of output string will be n+1.
This machine response for empty string ε.
Moore machine can be described by 6 tuples (Q, q0, ∑, O, δ, λ) where,
Q: finite set of states
q0: initial state of machine
∑: finite set of input symbols
O: output alphabet
δ: transition function where Q × ∑ → Q
λ: output function where Q → O
Example 1: The state diagram for Moore Machine is
Transition table for Moore Machine is:
In the above Moore machine, the output is represented with each input state separated by /.
The output length for a Moore machine is greater than input by 1.
Input: 010
Transition: δ (q0,0) => δ(q1,1) => δ(q1,0) => q2
Output: 1110(1 for q0, 1 for q1, again 1 for q1, 0 for q2)
Example 2: Design a Moore machine to generate 1's complement of a given binary number.
Solution:
To generate 1's complement of a given binary number the simple logic is that if the input is 0
then the output will be 1 and if the input is 1 then the output will be 0.
That means there are three states.
One state is start state.
The second state is for taking 0's as input and produces output as 1.
The third state is for taking 1's as input and producing output as 0.
Hence the Moore machine will be,
For instance, take one binary number 1011 then
Input 1 0 1 1
State q0 q2 q1 q2 q2
Output 0 0 1 0 0
Thus we get 00100 as 1's complement of 1011, we can neglect the initial 0 and the output
which we get is 0100 which is 1's complement of 1011.
The transaction table is as follows:
Thus Moore machine M = (Q, q0, ∑, O, δ, λ); where Q = {q0, q1, q2}, ∑ = {0, 1}, O = {0, 1}.
the transition table shows the δ and λ functions.
Example 3:
Design a Moore machine for a binary input sequence such that if it has a substring 101, the
machine output A, if the input has substring 110, it outputs B otherwise it outputs C.
Solution:
For designing such a machine, we will check two conditions, and those are 101 and 110.
If we get 101, the output will be A, and if we recognize 110, the output will be B. For other
strings, the output will be C.
The partial diagram will be:
Now we will insert the possibilities of 0's and 1's for each state. Thus the Moore machine becomes:
Example 4:
Construct a Moore machine that determines whether an input string contains an even or odd
number of 1's. The machine should give 1 as output if an even number of 1's are in the string
and 0 otherwise.
Solution:
The Moore machine will be:
This is the required Moore machine. In this machine, state q1 accepts an odd number of 1's
and state q0 accepts even number of 1's. There is no restriction on a number of zeros. Hence
for 0 input, self-loop can be applied on both the states.
Example 5:
Design a Moore machine with the input alphabet {0, 1} and output alphabet {Y, N} which
produces Y as output if input sequence contains 1010 as a substring otherwise, it produces N as
output.
Solution:
The Moore machine will be:
Mealy Machine
A Mealy machine is a machine in which output symbol depends upon the present input
symbol and present state of the machine.
The mealy machine is a finite state machine with an output value on each transition.
In the Mealy machine, the output is represented with each input symbol for each state
separated by /.
The Mealy machine can be described by 6 tuples (Q, q0, ∑, O, δ, λ) where
Q: finite set of states
q0: initial state of machine
∑: finite set of input alphabet
O: output alphabet
δ: transition function where Q × ∑ → Q
λ: output function where Q × ∑ →O
The Mealy machine forms an FA of the type:
In the machine above, the transition on input i will give an output x from the state q0.
Moreover, from q1 a transition on input j will provide an output y.
Note: If the input string is of length n, the output produced by a Mealy machine will also be of
length n.
Example
Suppose we have the following Mealy machine:
Now, we take an input string in Σ={0,1} and see its output in Σ={a,b}. Let's
take x=0010.
Transitions Explanation
The first input character is 0. Hence, we move to q1 and output b. Our output
string is b.
For the next 0, we move to q0, which outputs an a. The output string becomes ba.
The next 1 gives another a. The output string becomes baa.
The last 0 takes us to q1 and produces b. The final output string is baab.
Transition table
The transition table for the above machine will be:
Current Destination Output Destination Output
State State for 0 at 0 State for 1 at 1
q0 q1 b q0 a
q1 q0 a q1 b
The Mealy machine is faster than the Moore machine as it is asynchronous to the fluctuations of a
clock pulse.
Example 1: write a mealy machine to convert a binary number to its 2‟s complement.
Logic: Take a binary number 10100. The 2‟s complement of 10100 is 01100.
We move from right to left on the binary number.
We keep the binary values the same until we find the first 1. After finding the first one, we
change the bits from 0 to 1 and 1 to 0.
The below diagram shows the mealy machine to convert binary to its 2‟s complement form.
On state q0, if we find the input symbol zero, we move to state q0 and display zero.
On state q0, if we find the input symbol one, we move to state q1 and display 1.
We are moving to state q1 when we find the first input symbol 1.
We use the state q1 to change the bits 1 to 0 and 0 to 1.
On state q1, if we see input symbol 0, we display 1.
Similarly, for input symbol one, we display 0.
Now the transition table for the above machine will be:
Example 2:
Design a Mealy machine for a binary input sequence such that if it has a substring 101, the
machine output A, if the input has substring 110, it outputs B otherwise it outputs C.
Solution:
For designing such a machine, we will check two conditions, and those are 101 and 110.
If we get 101, the output will be A. If we recognize 110, the output will be B. For other strings
the output will be C.
The partial diagram will be:
Now we will insert the possibilities of 0's and 1's for each state. Thus the Mealy machine
becomes:
Example 3:
Construct a Mealy machine that prints „1‟ whenever the sequence „aa‟ or „bb‟ is encountered in any
input binary string from sigma Σ* where Σ={a, b}.
Example 4:
Construct a Mealy machine that prints „a‟ whenever the sequence „01‟ is encountered in any input
binary string from sigma Σ* where Σ={a, b}.
Difference between Moore Machine and Mealy Machine
The difference between the Mealy machine and Moore machine is as follows:
Moore Machine Mealy Machine
Output depends on the present state as well as
Output depends only upon the present state. present input.
Moore machine also places its output on the Mealy Machine places its output on the
transition. transition.
More states are required. Less number of states are required.
There is less hardware requirement for circuit There is more hardware requirement for circuit
implementation. implementation.
Synchronous output and state generation. Asynchronous output generation.
Output is placed on states. Output is placed on transitions.
Easy to design. It is difficult to design.
Conversion from Mealy machine to Moore Machine
Conversion from Mealy to Moore Machine is little bit complex than conversion of Moore to Mealy
Machine. There are two cases while conversion of Mealy to Moore Machine.
Case 01: When the every entering Input in Mealy state providing the same output, then simply place
that output with state.
Case 02: When the every entering Input in any particular Mealy state is providing the different
output then we cannot represent more than one output in one state of Moore Machine. In this case
that particular state is duplicated.
Examples of Mealy to Moore Machine Conversion
Let explain some examples of Mealy to Moore Machine Conversions.
Example 01: Consider the following Mealy Machine
As in the above Mealy Machine,
q0 is the start state, (0,1) are inputs and “a” is the output.
Every entering input in the state q0 having the similar output “a”.
So, simply cut the output “a” over arrow and place along with state “q0”.
After conversion the Moore Machine is given under
Example 02
Consider the following Mealy Machine
At point q0,
There is no arrow is entering into the state q0. So, the output for the q0 is null. As given Below
At point q1,
There are three arrows are entering into the state q1. Arrow from q0 and q1 has the input “0” with
output “a” and Arrow from q2 has the input “1” with “b” output.
Output of 2 types (0,1) are entering into state q1, So One duplicate of q1 is generated with different
output.
So, the output of type “0” is placed along with state q1. And Output of type “1” is placed along with
duplicated state (q1) as given below
Further Proceeding of above, now make the transition from both states (original q1 and duplicate
q1) for input 0 and 1.
For input “0” transition goes to q1 with “a”.
For input “1” transition goes to q2 with output “b”.
As given below
Now remaining state is only q2 which has to discuss.
There are three arrows are entering into the state q2. Arrow from q0 and q2 (itself) has the input “1”
with output “a” and Arrow from q1 has the input “1” with “b” output.
Output of 2 types (0,1) are entering into state q2, So One duplicate state of q2 is generated.
By completing the transition from both states (original q2 and duplicate q2) for input 0 and 1,
The final Mealy machine is given below : As shown in following diagram
Important.
If “M” is the number of states and “N” is number of outputs in Mealy Machine, then
maximum number of States in Mealy Machine will be “M” multiply by “N”.
Suppose if 3 number of states and 2 number of outputs in Mealy, then 6 will be the maximum
state in Moore Machine
Example 2: The below diagram shows the mealy machine. Convert into Moore Machine
The mealy machine will display output based on transition.
Procedure:
Start from the initial state.
The initial state q0 has two incoming edges.: One incoming edge is from state q3
and the other from state q1.
The output on the two incoming edges is 0 and 1. So we take two different states in
the Moore machine: One state is going to display 0, and the other state display 1.
One state is named q00, and this state display 0. another state is named q01, and
this state display 1.
on state q1, if we take input symbol a, we move to state q0 and display 0.
In the Moore machine, we move to state q00 because the state q00 has output 0.
Similarly, on state q3, if we take input symbol b, we move to state q01. To display 1.
We write the outgoing edges in the mealy machine on both the states in the Moore
machine.
On state q0, we have two outgoing edges. We mention both edges on the states
q00 and q01 in the Moore machine.
The below diagram shows the Moore machine after converting state q0.
Similarly, convert all the states.
Now we will consider state q1.
We have two incoming edges on state q1.
Both incoming edges display output 1, so we take one state q1 and display output 1.
Write the incoming and outgoing edges for state q1.
In the incoming edges, we are eliminating the output symbol.
The below diagram shows the Moore machine after changing state q1.
Now we consider state q3.
We have two incoming edges on state q3.
Both the incoming edges display output zero.
We take only one state, q3, and the state will display output zero.
We write incoming and outgoing edges to state q3.
The below diagram shows the Moore machine after converting state q3
Now we consider state q2.
We have four incoming edges to state q2.
Two incoming edges are displaying output 1.
Two incoming edges are displaying output 0.
We take two different states q20 and q21.
The state q20 will display output zero. And the state q21 will display output 1.
We write the incoming and outgoing edges to states q20 and q21.
The incoming edges which are displaying 0 will move to state q20.
The incoming edges which are displaying one will move to state q21.
Final Moore Machine
Example 3: Convert the following Mealy machine into equivalent Moore machine.
Solution:
Transition table for above Mealy machine is as follows:
Transition diagram for Moore machine will be:
Example 4: Convert the following Mealy machine into equivalent Moore machine.
Solution:
Transition table for above Mealy machine is as follows:
Transition diagram for Moore machine will be:
Conversion from Moore machine to Mealy Machine
In the Moore machine, the output is associated with every state, and in the mealy machine, the
output is given along the edge with input symbol.
The equivalence of the Moore machine and Mealy machine means both the machines generate
the same output string for same input string.
We cannot directly convert Moore machine to its equivalent Mealy machine because the
length of the Moore machine is one longer than the Mealy machine for the given input.
To convert Moore machine to Mealy machine, state output symbols are distributed into input
symbol paths.
We are going to use the following method to convert the Moore machine to Mealy machine.
Method for conversion of Moore machine to Mealy machine
Let M = (Q, ∑, δ, λ, O, q0) be a Moore machine. The equivalent Mealy machine can be
represented by M' = (Q, ∑, δ, λ', O, q0). The output function λ' can be obtained as:
λ' (q, a) = λ (δ (q, a))
Example 1: Convert the following Moore machine into its equivalent Mealy
machine.
Solution:
The transition table of given Moore machine is as follows:
Q a b Output(λ)
q0 q0 q1 0
q1 q0 q1 1
The equivalent Mealy machine can be obtained as follows:
λ' (q0, a) = λ(δ(q0, a))
= λ(q0)
=0
λ' (q0, b) = λ(δ(q0, b))
= λ(q1)
=1
The λ for state q1 is as follows:
λ' (q1, a) = λ(δ(q1, a))
= λ(q0)
=0
λ' (q1, b) = λ(δ(q1, b))
= λ(q1)
=1
Hence the transition table for the Mealy machine can be drawn as follows:
The equivalent Mealy machine will be,
Note: The length of output sequence is 'n+1' in Moore machine and is 'n' in the Mealy machine.
Example 2: Convert the given Moore machine into its equivalent Mealy machine.
Solution:
The transition table of given Moore machine is as follows:
Q a b Output(λ)
q0 q1 q0 0
q1 q1 q2 0
q2 q1 q0 1
The equivalent Mealy machine can be obtained as follows:
λ' (q0, a) = λ (δ (q0, a))
= λ(q1)
=0
λ' (q0, b) = λ (δ (q0, b))
= λ(q0)
=0
The λ for state q1 is as follows:
λ' (q1, a) = λ (δ(q1, a))
= λ(q1)
=0
λ' (q1, b) = λ(δ (q1, b))
= λ(q2)
=1
The λ for state q2 is as follows:
λ' (q2, a) = λ(δ(q2, a))
= λ(q1)
=0
λ' (q2, b) = λ(δ(q2, b))
= λ(q0)
=0
Hence the transition table for the Mealy machine can be drawn as follows:
The equivalent Mealy machine will be,
Example 3: Convert the given Moore machine into its equivalent Mealy machine.
Q a b Output(λ)
q0 q0 q1 0
q1 q2 q0 1
q2 q1 q2 2
Solution:
The transaction diagram for the given problem can be drawn as:
The equivalent Mealy machine can be obtained as follows:
λ' (q0, a) = λ(δ(q0, a))
= λ(q0)
=0
λ' (q0, b) = λ(δ(q0, b))
= λ(q1)
=1
The λ for state q1 is as follows:
λ' (q1, a) = λ(δ(q1, a))
= λ(q2)
=2
λ' (q1, b) = λ(δ(q1, b))
= λ(q0)
=0
The λ for state q2 is as follows:
λ' (q2, a) = λ(δ(q2, a))
= λ(q1)
=1
λ' (q2, b) = λ(δ(q2, b))
= λ(q2)
=2
Hence the transition table for the Mealy machine can be drawn as follows:
The equivalent Mealy machine will be,