You are on page 1of 11

Name : Umar Ali

Roll Number : 522

Class # : BS (CS) – 6th


Semester

Assignment # : 06

Submitted to : Sir Tawab

Subject : “CS-515-Theory of
Automate”
Q#1.
a) What is a Mealy Machine? Give its formal definition.

Answer:

Mealy machine
In the theory of computation, a Mealy machine is a finite-state machine whose
output values are determined both by its current state and the current inputs.
This is in contrast to a Moore machine, whose (Moore) output values are
determined solely by its current state. A Mealy machine is a deterministic
finite-state transducer: for each state and input, at most one transition is
possible.

Formal definition

A Mealy machine is a 6-tuple S ,S, ∑, A,, T,G consisting of the following:

 a finite set of states S


 a start state (also called initial state) S 0 which is an element of S
 a finite set called the input alphabet ∑
 a finite set called the output alphabet A
 a transition function T: S× ∑→ S mapping pairs of a state and an input symbol to the
corresponding next state.
 an output function G: S× ∑→ A, mapping pairs of a state and an input symbol to the
corresponding output symbol.
In some formulations, the transition and output functions are coalesced into a single

function . T: S× ∑→ S × A
b) Construct a Moore Machine that prints 1 whenever it reads baa in
the input string and 0 otherwise. Show its transition for the input
string abaabbabaabbaabaabbab

Solution: Construct a Moore Machine

First, let us draw the DFA that accepts all strings containing the substring "baa":

In the above DFA, q3q3 is the acceping state. Now, let us convert the above DFA
into a Moore machine. For this, we need to mark the outputs also along with states.

Moore Machine-

The above Moore machine will output 1s and 0s. The number of 1s will be the
number of occurrences of the substring "baa".
Transition for the input string abaabbabaabbaabaabbab.
Input
string a b a a b b a b a a b b a a b a a b b a B

State q0 q0 q1 q2 q3 q1 q1 q2 q1 q2 q3 q1 q1 q2 q3 q1 q2 q3 q1 q1 q2 q1

Output 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0
(Moore)
Q#2.
a) How Moore Machine is different from Mealy Machine?

Answer:
Mealy Machine – A mealy machine is defined as a machine in theory of computation whose
output values are determined by both its current state and current inputs. In this machine
atmost one transition is possible.
It has 6 tuples: (Q, q0, ∑, O, δ, λ’)
Q is finite set of states
q0 is the initial state
∑ is the input alphabet
O is the output alphabet
δ is transition function which maps Q×∑ → Q
‘λ’ is the output function which maps Q×∑→ O

Diagram –

Moore Machine – A moore machine is defined as a machine in theory of computation whose


output values are determined only by its current state.
It has also 6 tuples: (Q, q0, ∑, O, δ, λ)
Q is finite set of states
q0 is the initial state
∑ is the input alphabet
O is the output alphabet
δ is transition function which maps Q×∑ → Q
λ is the output function which maps Q → O

Diagram –
Moore Machine –

1. Output depends only upon present state.

2. If input changes, output does change.

3. More number of states are required.

4. There is less hardware requirement for circuit implementation.

5. They react slower to inputs(One clock cycle later).

6. Synchronous output and state generation.

7. Output is placed on states.

8. Easy to design.

Mealy Machine –

1. Output depends on present state as well as present input.

2. If input changes, output also changes.

3. Less number of states are required.

4. There is more hardware requirement for circuit implementation.

5. They react faster to inputs.

6. Asynchronous output generation.


7. Output is placed on transitions.

8. It is difficult to design.
b) Design a Complementing Mealy Machine and an Incrementing
Mealy Machine. And show the out of both your machines for
the input string
0100110101000110

Answer:
Complementing Mealy Machine

A Mealy machine consists of the followingA finite set of states q0, q1, q2, ...
where q0 is the initial state.An alphabet of letters Σ = {a,b,c,...} from which the
input strings are formed.An alphabet G={x,y,z,...} of output characters from
which output strings are generated.A pictorial representation with states and
directed edges labeled by an input letter along with an outputcharacter. The
directed edges also show how to go from one state to another corresponding to
every possible input letter.
It is to be noted that since, similar to Moore machine, in Mealy machine no state
is designated to be a final state,so there is no question of accepting any language
by Mealy machine. However in some cases the relationbetween an input string
and the corresponding output string may be identified by the Mealy machine.
Moreover,the state to be initial is not important as if the machine is
usedb/1q2q1several times and is restarted after some time, the machinewill be
started from the state where it was left

Consider the Mealy machine shown aside, having the states q0, q1, q2, q3 ,
where q0 is the start state and

Σ = {a,b},
G={0,1}
Running the string abbabbba over the above machine, the corresponding output
string will be 11011010, which can be determined by the following table as

it may be noted that in Mealy machine, the length of output string is equal to
that of input string

Consider the following Mealy machine having the only state q0 as the start state andΣ =
{0,1}
G= {0,1}

If 0011010 is run on this machine then the corresponding output string will be
1100101.This machine is called Complementing machine.
So as given question

(show the out put of both your machines for the input string

0100110101000110) will be 1011001010111001


Incrementing Mealy Machine

In the previous example of complementing machine, it has been observed that


the input string and thecorresponding output string are 1's complement of each
other. There is a question whether the Mealy machinecan be constructed, so
that the output string is increased, in magnitude, by 1 than the corresponding
input string?The answer is yes.This machine is called the incrementing
machine. Following is how to construct the incrementing machine.Before
the incrementing machine is constructed, consider how 1 is added to a binary
number.Since, if two numbers are added, the addition is performed from right
to left, so while increasing the binarynumber by 1, the string (binary number)
must be read by the corresponding Mealy machine from right to left,and hence
the output string (binary number) will also be generated from right to
left.Consider the following additions

It may be observed from the above thatIf the right most bit of binary number, to be
incremented, is 0, the output binary number can be obtained by converting the right most bit
to 1 and remaining bits unchanged.If the right most bit of binary number is 1 then the output
can be obtained, converting that 1 along with all its concatenated 1's to 0's, then converting
the next 0 to 1 and remaining bits unchanged. The observations (a) and (b) help to construct
the following Incrementing (Mealy) machine. The Mealy machine have the states q0, q1, q2 ,
where q0 is the start state and
Σ = {0,1},
G={0,1}

It may be observed that, in the incrementing machine, if 0 is read at initial state q0, that 0 is
converted to 1 and ano change state q1 (no carry state) is entered where all 0's and all 1's
remain unchanged. If 1 is read at initialstate, that 1 is converted to 0 and the state q2(owe
carry state) is entered, where all 1's are converted to 0's andat that state if 0 is read that 0 is
converted to 1 and the machine goes to no change state.If the strings 100101110 and
1001100111 are run over this machine, the corresponding output strings will be100101111
and 1001101000 respectively.Note It is to be noted that if the string 111111 is run over the
incrementing machine, the machine will print out000000, which is not increased in
magnitude by 1. Such a situation is called an overflow situation, as the lengthof output string
will be same as that of input string.It may also be noted that there exists another incrementing
machine with two states .

So as given question

(show the out put of your machines for the input string

0100110101000110) will be 0100110101000111

You might also like