You are on page 1of 4

Mealy Machines and Moore Machines

Lecture notes by Dr. K S Sudeep

Mealy Machines and Moore Machines are finite state machines that generate
output strings (or a sequence of output symbols). They don’t have accept states.

They can be used for computing some simple function that requires reading the
input string only once, and memory given by a finite number of states.

For example, counting the number of zeroes in a string.

Output: A string of m zeroes, if input string contains m zeroes.

Moore machine:

 They have one output symbol for each state it goes to.

𝛿 is similar to DFA; plus we have an output function λ: Q → O

 λ(q) = a means ‘If the automata (machine) goes to state q, output a’.

Example: λ(q1) = 0 means that if the machine goes to state q1, output 0.

While drawing the state diagram, we write the output symbol along with the
state name (see the figure below). Here, q1/0 means that on going to state q1, it
generates symbol ‘0’ on its output stream.
It has an initial output symbol (that corresponds to the initial state q0), so the
total length of the output = (n+1) bits, if input has n bits.

Formally, we can define a Moore Machine as a 6-tuple: (Q, q0, ∑, O, δ, λ)


 Q: the (finite) set of states
 q0: the initial state
 ∑: the input alphabet
 O: the output alphabet
 δ: transition function, Q × ∑ → Q
 λ: the output function which maps Q → O
An example of a Moore Machine: (source: geeksforgeeks.org)

Let us see what happens on this machine on different inputs:

 On input 0011: It goes through states q0 → q1 → q1 → q3 → q2, and


hence generates the output sequence: ‘0 0 0 1 0’. (5 symbols).
 On input 110: It goes through states q0 → q2 → q2 → q4, and hence
generates the output sequence: ‘0 0 0 1’. (4 symbols).
Mealy machine:

 Here, the output is defined on moves (i.e., it depends on the current state
and the current symbol, just like δ)
 On an input of length n, it has an output string also of length n.
 On the arrow from state q to state r, we write two symbols. For example,
if we have transition δ(q0, 0) = (q1) and output function λ’(q0, 0) = 1, we
draw the states and the move (along with the output) as follows:

(On the label of the arrow, the first symbol is input symbol, second one is output
symbol. It means that on seeing a 0 when in state q0, the machine moves to state
q1, and generates an output symbol ‘1’.)

Formally, a Mealy Machine is a 6 tuple: (Q, q0, ∑, O, δ, λ’)

 Q: the (finite) set of states


 q0: the initial state
 ∑: the input alphabet
 O: the output alphabet
 δ: transition function, Q × ∑ → Q
 λ’: the output function, which maps Q × ∑ → O
An example of a Mealy Machine:

Verify that an input string 1101 generates output 1110 on this machine.

[Note: A Mealy Machine can be converted to a Moore Machine and vice versa.
We are not doing conversion in the class right now.]

You might also like