0% found this document useful (0 votes)
6 views

Chapter 3

Uploaded by

zy27448
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Chapter 3

Uploaded by

zy27448
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

3 Output Generating Automata

We can classify automatas as,


a. Finite state recognizer
b. Output generating automata
• A recognition model is a model that recognizes a segment of strings
that can be generated from symbols in an input alphabet. This model
is used in many software applications, especially in syntax analysis,
parsing and similar applications related to formal languages.

• It has been seen in the above sections that there are deterministic
and non-deterministic types of the finite state accepting model, and
these two types are equivalent in terms of modeling power.
• An output-generating automaton model, as the name suggests, is one
that produces an output string in response to an input string applied
to its input.
• In this respect, it is also possible to see the output generating
automaton model as a model that converts input strings to output
strings. Thus, the two main types of finite automata can be
characterized as "recognisers" and "converters".
• In fact, recognizers can also be thought of as producing outputs. Since
a recognizer recognizes some of the input strings applied to its input
and not the other, the FA model produces a binary output.
• FA model can be viewed as a binary output generating model. The
outputs produced by the model can be, for example, “1: accepted”
for final states and “0 : not accepted” for other states. From this point
of view, the output generating finite automata model can be seen as a
broader model, including the recognition model.
• There are two types of output-generating automata, called Moore
and Mealy machines. While the Moore machine is a state-level
output-generating model, the Mealy-machine is a state-transition-
level output-generating model. Moore and Mealy machines are
analyzed separately below.
3.1 Moore Machine

The Moore Machine is defined as a sextuple.

𝑀 =< 𝑄, 𝛴, 𝛥, 𝛿, 𝜆, 𝑞0 >

𝑄: is finite state of internal states


𝛴: input alphabet (finite set)
𝛥: output alphabet (finite set)
𝛿: it is a transition funtion from (𝑄 𝑥𝛴) to 𝑄
𝜆 : it is a output funtion from 𝑄 to 𝛥
• The Moore machine can be seen as a generalization of the DFA
model. In other words, the DFA model can be thought of as a special
Moore machine.

• The state transition function (𝛿) and the output function (𝜆) of the
Moore machine can be represented by a table or diagram. The table
created to describe the Moore machine is often called the "State
Table", and the diagram is often called the "State Diagram".
Example 3.1 The 𝑀8 machine is defined as a Moore machine that
produces output 𝑧 = 𝑀𝑜𝑑(𝑋, 5) if the binary number applied to its
input is X.

𝑀8 =< 𝑄, 𝛴, 𝛥, 𝛿, 𝜆, 𝑞0 >
𝑄 = {𝐴, 𝐵, 𝐶, 𝐷, 𝐸}
𝛴 = {0,1}
𝛥 = 0,1,2,3,4
𝑞0 = 𝐴

The definition of 𝛿 and 𝜆 is in the State Table and State Diagram in


Figure 3.1.
Figure 3.1 State diagram and State table
For example, when the input string w=1011110 is applied to the 𝑀8
machine, the machine's states and outputs will change as follows.

Input: 1 0 1 1 1 1 0
State: 𝐴 → 𝐵 → 𝐶 → 𝐴 → 𝐵 → 𝐷 → 𝐶 → 𝐸
Output: 0 1 2 0 1 3 2 4
3.2 Mealy Machine

Like the Moore machine, the Mealy machine is defined as a sextuple.

𝑀 =< 𝑄, 𝛴, 𝛥, 𝛿, 𝜆, 𝑞0 >

The definition of the elements are the same as in the Moore machine
except the output function (𝜆). In other words, the only difference
between Moore and Mealy machines is in the output function. The
output function, defined as mapping from 𝑄 to 𝛥 for Moore machines
and for Mealy machines, is defined as a mapping from (𝑄 𝑥𝛴) to 𝛥.
Example 3.2 The 𝑀9 machine is defined as the Mealy machine with the
input alphabet {0, 1} and the output alphabet {0, 1, 2} and showing how
many of the last two input symbols are different from the previous one with
the output it produces. When determining the first 2 output values that the
machine will produce, the two input values before the initial state will be
assumed to be 00.
𝑀6 =< 𝑄, 𝛴, 𝛥, 𝛿, 𝜆, 𝑞0 >
𝑄 = {𝐴, 𝐵, 𝐶, 𝐷}
𝛴 = {0,1}
𝛥 = 0,1,2
𝑞0 = 𝐴
𝛿 and 𝜆 are defined by state table and state diagram in figure 3.2. According
to the design, the states of the machine are A, B, C or D, respectively,
according to the previous two input symbol values being 00, 01, 10 or 11.
Figure 3.2 Mealy machine
An example input string and the output string that the machine should
generate in response to this input string are as follows:

X: 0 1 1 0 1 0 1 0 1 1 1 1 0 1 0 0 1 1 1 0 0 0 0 1
Z: 0 1 1 1 2 2 2 2 2 1 0 0 1 2 2 1 1 1 0 1 1 0 0 1
3.3 The Equivalence of Mealy and Moore Machine
• Both Moore and Mealy machines are finite automata models that produce
output.
• In Moore and Mealy models, which are defined as a sextet, 5 elements of
the six are common. It is the output function that separates the Moore and
Mealy models.
• In Moore's model, the machine generates an exit symbol for each state.
When an input string consisting of n input symbols is applied to a Moore
machine in a given state, the machine will generate an output string of
length (n+1). In the Mealy model, the machine generates an output symbol
for each state transition. When an input string of n input symbols is applied
to a Mealy machine in a particular state, the machine will generate an
output string of length n.
• If the initial output symbol produced by the Moore machine is excluded,
equivalent Mealy and Moore machines will produce the same output
string, regardless of the input string applied.
3.3.1 Finding the Mealy Machine Equivalent to the Moore Machine

Lemma 3.1 Let 𝑀1 =< 𝑄, 𝛴, 𝛥, 𝛿, 𝜆, 𝑞0 > is a Moore machine. The


Mealy machine equivalent to 𝑀1 is found as follows:

𝑀2 =< 𝑄, 𝛴, 𝛥, 𝛿, 𝜆′, 𝑞0 >, 𝜆′ 𝑞, 𝑎 = 𝜆 𝛿 𝑞, 𝑎

When we try to find Mealy machine equivalent to a Moore machine,


the output value mapped to each state transition is equal to the output
value mapped on the Moore machine to the next state at the end of
the state transition. It is possible to summarize this rule with the
following drawing.
Moore Machine Mealy Machine
The state table and state diagram of mealy machine which is equivalent to the moore
machine 𝑀8 in the example 3.1, is shown in figure 3.3 as below:

Figure 3.3
3.3.2 Finding the Moore Machine Equivalent to the Mealy Machine
Lemma 3.2 Let 𝑀2 =< 𝑄, 𝛴, 𝛥, 𝛿, 𝜆, 𝑞0 > is a Mealy machine. The
Moore machine equivalent to 𝑀1 is found as follows:

𝑀1 =< 𝑄′, 𝛴, 𝛥, 𝛿′, 𝜆′, 𝑞0 ′ >


𝑄 ′ = 𝑄𝑥Δ
𝑞0′ = 𝑞0 , 𝑧𝑗 𝑧𝑗 : one of the output symbol
𝛿 ′ 𝑞𝑖 , 𝑧𝑘 , 𝑥𝑗 = 𝛿 𝑞𝑖 , 𝑥𝑗 , 𝜆 𝑞𝑖 , 𝑥𝑗
𝜆′ 𝑞𝑖 , 𝑧𝑘 = 𝑧𝑘
• If in the Mealy machine the output symbol 𝑧𝑗 is generated during the
transition from state 𝑞1 to state 𝑞2 , then in the equivalent Moore
machine, a transition from each state with the first element 𝑞1 to the
state with the first element 𝑞2 and the second element 𝑧𝑗 with the
input symbol 𝑥𝑖 is created. Accordingly, if the output alphabet has the
output symbol m, for each state transition in the Mealy machine, the
equivalent Moore machine has m transition.
Example 3.3 𝑀10 Mealy machine is as follows:

𝑀10 =< 𝑄, 𝛴, 𝛥, 𝛿, 𝜆, 𝑞0 >


𝑄 = 𝐴, 𝐵, 𝐶
𝛴 = {0,1}
𝛥 = 0,1
𝑞0 = 𝐴
𝛿 𝐴, 0 =𝐵 𝜆 𝐴, 0 = 0
𝛿 𝐴, 1 =𝐴 𝜆 𝐴, 1 = 1
𝛿 𝐵, 0 =𝐵 𝜆 𝐵, 0 = 1
𝛿 𝐵, 1 =𝐶 𝜆 𝐵, 1 = 1
𝛿 𝐶, 0 =𝐴 𝜆 𝐶, 0 = 0
𝛿 𝐶, 1 =𝐶 𝜆 𝐶, 1 = 0
We can find the moore machine which is equivalent to 𝑀10 Mealy machine.

𝑀10 ′ =< 𝑄′, 𝛴, 𝛥, 𝛿′, 𝜆′, 𝑞0 ′ >


𝑄′ = 𝐴, 0 , 𝐴, 1 , 𝐵, 0 , 𝐵, 1 , 𝐶, 0 , 𝐶, 1
𝑞0′ = 𝐴, 0

𝛿′ 𝐴, 0 ,0 = 𝐵, 0 𝜆 𝐴, 0 = 0
𝛿′ 𝐴, 1 ,0 = 𝐵, 0 𝜆 𝐴, 1 = 1
𝛿′ 𝐴, 0 ,1 = 𝐴, 1 𝜆 𝐵, 0 = 0
𝛿′ 𝐴, 1 ,1 = 𝐴, 1 𝜆 𝐵, 1 = 1
𝛿′ 𝐵, 0 ,0 = 𝐵, 1 𝜆 𝐶, 0 = 0
𝛿′ 𝐵, 1 ,0 = 𝐵, 1 𝜆 𝐶, 1 = 0
𝛿′ 𝐵, 0 ,1 = 𝐶, 1
𝛿′ 𝐵, 1 ,1 = 𝐶, 1
𝛿′ 𝐶, 0 ,0 = 𝐴, 0
𝛿′ 𝐶, 1 ,0 = 𝐴, 0
𝛿′ 𝐶, 0 ,1 = 𝐶, 0
𝛿′ 𝐶, 1 ,1 = 𝐶, 0
• Figure 3.4 shows the state diagram of the 𝑀10 Mealy machine and
the equivalent Moore machine. According to Lemme 3.2, when
finding a Moore machine equivalent to a Mealy machine, the states
of the Moore machine should be represented by the pairs [state
name, output symbol].
Figure 3.4 𝑀10 Mealy machine and 𝑀10 ′ equivalent Moore machine
Only after the equivalent Moore machine is found its states can be
renamed. As a matter of fact, the state diagram of the 𝑀10 ′ Moore
machine seen in Figure 3.5, the states of the machine are renamed as:

𝐴, 0 → 𝑞0
𝐴, 1 → 𝑞1
𝐵, 0 → 𝑞2
𝐵, 1 → 𝑞3
𝐶, 0 → 𝑞4
𝐶, 1 → 𝑞5
Figure 3.5 Moore machine – states are renamed
Example 3.4 The Mealy machine is defined as follows:

𝑀 =< 𝑄, 𝛴, 𝛥, 𝛿, 𝜆, 𝑞0 >
𝑄 = {𝑞0 , 𝑞1 }
𝛴 = {0,1}
𝛥 = 𝑎, 𝑏, 𝑐
𝑞0 is the initial state

𝛿 𝑞0 , 0 = 𝑞1 𝜆 𝑞0 , 0 =𝑎
𝛿 𝑞0 , 1 = 𝑞0 𝜆 𝑞0 , 1 =𝑐
𝛿 𝑞1 , 0 = 𝑞0 𝜆 𝑞1 , 0 =𝑏
𝛿 𝑞1 , 1 = 𝑞1 𝜆 𝑞1 , 1 =𝑎
This Mealy machine prints out caab when given the input string 1010.
Example 3.5 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.
For instance, take one binary number 1011 then,

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:
Example 3.6 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.7 Convert the following Mealy machine into equivalent
Moore machine.
Transition table for above Mealy machine is as follows:
The state q1 has only one output. The state q2 and q3 have both
output 0 and 1. So we will create two states for these states. For q2,
two states will be q20(with output 0) and q21(with output 1). Similarly,
for q3 two states will be q30(with output 0) and q31(with output 1).
Transition table for Moore machine will be:
Transition diagram for Moore machine will be:
Example 3.8 Convert the following Mealy machine into equivalent
Moore machine.
• Step 1. First, find out those states which have more than 1 output
associated with them. q1 and q2 are the states
which have both output 0 and 1 associated with them.
• Step 2 Create two states for these states. For q1, two states will be q1
0 (a state with output 0) and q11 (a state with
output 1). Similarly, for q2, two states will be q20 and q21.
• Step 3: Create an empty Moore machine with a
newly generated state. For more machines, Output will be associated
with each state irrespective of inputs.
• Step 4: Fill in the entries of the next state using the mealy machine
transition table shown in Table. For q0 on input 0, the next state is
q10 (q1 with output 0). Similarly, for q0 on input 1, the next state is
q20 (q2 with output 0). For q1 (both q10 and q11) on input 0, the
next state is q10. Similarly, for q1(both q10 and q11), next state is
q21. For q10, the output will be 0 and for q11, the output will be 1.
Similarly, other entries can be filled.
Example 3.8 Convert the following Moore machine into its equivalent
Mealy machine.
The equivalent Mealy machine will be,

You might also like