Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Computation Theory 2 Mr.

Mustafa Ghanem Saeed

Finite State Machines with Output


(Mealy and Moore Machines)
We shall investigate two different models for FA's with output capabilities;
these are Moore machine and Mealy machine.

Moore Machines:
A Moore machine can be described by a 6 tuple (Q, ∑, O, δ, X, q0)
where −

 Q is a finite set of states.

 ∑ is a finite set of symbols called the input alphabet.

 Г is a finite set of symbols called the output alphabet.


 δ is the input transition function where δ: Q × ∑ → Q

 ƛ is the output transition function where ƛ: Q → Г


 q0 is the initial state from where any input is processed (q0 ∈ Q).

An output table that shows what character from Г is printed by each state
that is entered.
A Moore machine does not define a language of accepted words, since
every input string creates an output string and there is no such thing as a
final state. The processing is terminated when the last input letter is read
and the last output character is printed.

Example 1:
Input alphabet: Σ = {a, b}
Output alphabet: Г = {0, 1}
Names of states: q0, q1, q2, q3. (q0 = start state)

Q Ϩ(q, a) Ϩ(q, b) Г(Q)


q0 q1 q3 1
q1 q3 q1 0
q2 q0 q3 0
q3 q1 q2 1

Sol:
The Moore machine is:

|Page1

Computer Science Department Collage of Science Cihan University


Computation Theory 2 Mr. Mustafa Ghanem Saeed

Note1:
 The two symbols inside the circle are separated by a slash "/", on the
left side is the name of the state and on the right is the output from
that state.
 If the input string is abab to the Moore machine then the output will
be 10010.
Note 2:
A Moore machine is very similar to a Finite Automaton (FA), with a few
key differences:
• It has no final states.
• It does not accept or reject input; instead, it generates output from
input.
• Moore machines cannot have nondeterministic states.

Every input gives output not if word belongs to the machine or language
like FA
In each state we stop we have to print out what inside that state (it's
content) so the output will be more than input by one because we start with
start state and print out its content before we trace the input string

Example 2: construct a Moore machine that take set of all strings over
Alphabet {a, b} as input and print 1 as output for every occurrence of 'aab'
as substring.
Sol:
Input alphabet: Σ = {a, b}
Output alphabet: Г = {0, 1}

|Page2

Computer Science Department Collage of Science Cihan University


Computation Theory 2 Mr. Mustafa Ghanem Saeed

Input string aaababbaabb


State q0q1q2q2q3q1q0q0q1q2q3q0
Output 000010000010

this machine gives 1 after each aab


aabaabaaababaab
0001001000100001
Note:
 Moore machine use as a string recognizer to give us a mark (1) after
each substring so we design a machine put 0 in all states except the one
after the one represent end of substring aab
 The output of the machine contains 1 for each occurrence of the
substring aab found in the input string.

Example 3: Construct a Moore machine that take set of all strings over
Alphabet {0, 1} as input and produce 'A' as output if input end with (10) or
produce 'B' as output if input end with (11) otherwise produce 'C' .
Sol:
Input alphabet: Σ = {0, 1}
Output alphabet: Г = {A, B, C}

|Page3

Computer Science Department Collage of Science Cihan University


Computation Theory 2 Mr. Mustafa Ghanem Saeed

Example 4: Construct a Moore machine that take set of all strings over
alphabet {a, b} as input and produce '1' as output if number of a's in string
mod 3=0 otherwise produce '0'.
Sol:
Input alphabet: Σ = {a, b}
Output alphabet: Г = {0, 1}

Example 5: Construct a Moore machine that outputs a binary string that


contains a 1 for every double letter substring in an input string composed
of a’s and b’s. For example if abba is the input string, 0010 is the
corresponding output.
Sol:
Input alphabet: Σ = {a, b}
Output alphabet: Г = {0, 1}

|Page4

Computer Science Department Collage of Science Cihan University


Computation Theory 2 Mr. Mustafa Ghanem Saeed

Mealy Machines:
A Mealy Machine is an FSM whose output depends on the present
state as well as the present input.

It can be described by a 6 tuple (Q, ∑, Г, δ, X, q0) where −

 Q is a finite set of states.

 ∑ is a finite set of symbols called the input alphabet.

 Г is a finite set of symbols called the output alphabet.


 δ is the input transition function where δ: Q × ∑ → Q

 ƛ is the output transition function where ƛ: Q × ∑ → Г


 q0 is the initial state from where any input is processed (q0 ∈ Q).

Note: There are no accept states in Moore and Mealy machine because
they are not a language recognizer, they are an output producer. Its output
will be the same length as its input.
Example 1:
Input alphabet: Σ = {a, b}
Output alphabet: Г = {0, 1}
Names of states: q0, q1, q2, q3. (q0 = start state)

Q Ϩ(q, a) Г(q, a) Ϩ(q, b) Г(q, b)


q0 q1 0 q3 0
q1 q3 1 Q2 1
q2 q3 0 q3 1
q3 q3 1 q0 1

Sol:
The Mealy machine is:

|Page5

Computer Science Department Collage of Science Cihan University


Computation Theory 2 Mr. Mustafa Ghanem Saeed

Quick review for Binary system complements

As the binary system has base r = 2. So the two types of complements for
the binary system are 2's complement and 1's complement.

1's complement
The 1's complement of a number is found by changing all 1's to 0's and all
0's to 1's. This is called as taking complement or 1's complement. Example
of 1's Complement is as follows.

2's complement
The 2's complement of binary number is obtained by adding 1 to the Least
Significant Bit (LSB) of 1's complement of the number.

2's complement = 1's complement + 1

Example of 2's Complement is as follows.

|Page6

Computer Science Department Collage of Science Cihan University


Computation Theory 2 Mr. Mustafa Ghanem Saeed

Note:
 Two’s complement is especially important because it allows us to represent signed
numbers in binary.
 Two’s complement also provides an easier way to subtract numbers using addition
instead of using the longer.

Example 2:
The following Mealy machine prints out the 1's complement of an input bit
string.in other words it flips each digit from a 0 to a 1 or from a 1 to a 0.

Note: If the input is 001010, the output is 110101. This is a case where
the input alphabet and output alphabet are both {0, 1}.

Example 3:
Construct a Mealy machine that take set of all strings over alphabet {0, 1}
as input and produce 'E' as output if number of 1's in string mod 2=0
produce 'O' as output if number of 1's in string mod 2=0.
Sol:
Input alphabet: Σ = {0, 1}
Output alphabet: Г = {E, O}

|Page7

Computer Science Department Collage of Science Cihan University


Computation Theory 2 Mr. Mustafa Ghanem Saeed

Note: The machine represented in in example 2, outputs an E if the number


of 1s read so far is even and an O if it is odd; for example, the translation
of 11100101 is OEOOOEEO.
Example 4:
Construct a Mealy machine that take set of all strings over alphabet {0, 1}
and make 2's complement of an input bit string in binary number.
Sol:
Input alphabet: Σ = {0, 1}
Output alphabet: Г = {0,1}

Note: The machine represented in in example 4, if the input is 1010100,


the output is 0101100. This is a case where the input alphabet and output
alphabet are both {0, 1}.

Exercises: design mealy machine accepting the language consisting of


strings from Σ *, where Σ = {a, b} and the string should end with either aa
or bb. (aa print 1 ,bb print 1 , otherwise print 0).

Mealy and Moore machines are equivalent


If Mealy machine capture a model, so does a Moore machine
 Moore model might require more states to model a system but
simpler to understand

|Page8

Computer Science Department Collage of Science Cihan University


Computation Theory 2 Mr. Mustafa Ghanem Saeed

 Mealy model might require less states to model but might be more
complex to understand

The following table highlights the points that differentiate a Mealy


Machine from a Moore Machine.
Mealy Machine Moore Machine

Output depends both upon the present Output depends only upon the present
state and the present input state.

Generally, it has fewer states than Generally, it has more states than Mealy
Moore Machine. Machine.

The value of the output function is a The value of the output function is a
function of the transitions and the function of the current state and the
changes, when the input logic on the changes at the clock edges, whenever
present state is done. state changes occur.

Mealy machines react faster to inputs. In Moore machines, more logic is


They generally react in the same clock required to decode the outputs resulting
cycle. in more circuit delays. They generally
react one clock cycle later.

Note: All examples in Moore machine can be solve in mealy Machine and
vris versa because Mealy and Moore machines are equivalent, you have
to try solving them as Homework.

|Page9

Computer Science Department Collage of Science Cihan University

You might also like