Sie sind auf Seite 1von 3

1

Theory of Computation - Assignment 1


Subhadeep Dash,
Computer Science and Engineering - S20160010021,
Indian Institute of Information Technology Sri City,
IIITS,
Sri City, India
Email id:subhadeep.d16@iiits.in

Abstract—This article is based on various aspects of finite 0 1


machines like constructing a DFA. It also includes output 1
based machines like Moore and Mealy machines. It has a brief 1
description on Myhill-Nerode theorem and it’s applications along r0 r1 0 r2 r3
start
with an example. 1 0
Index Terms—Moore and Mealy Machines, DFA, finite ma-
chines, Myhill-Nerode Theorem
0
Fig. 2: DFA for binary strings divisible by 4

I. B UILDING DFA FOR DIVISIBILITY BY 3 AND NOT 4 C. Building DFA for binary strings not divisible by 4

A. Building DFA for binary strings divisible by 3 0 1


1
1
States 0 1 start r0 r1 0 r2 r3
1 0
q0 q0 q1
q1 q2 q0 0
q2 q1 q2 Fig. 3: DFA for binary strings not divisible by 4

TABLE I: State Transition Table

D. Building Final DFA


0 1
1 0
0
q0 q1 q2 0
start
q0 r0 q0 r1 0 q0 r2 0 q0 r3
1 0 start

Fig. 1: DFA for binary strings divisible by 3 1 1 1


1 1 1
1 1

B. Building DFA for binary strings divisible by 4 q1 r0 q1 r1 q1 r2 q1 r3

0 0 0
0 0
States 0 1 0 0 0
r0 r0 r1 q2 r0 q2 r1 q2 r2 q2 r3
r1 r2 r3 1 1
r2 r0 r1 1
r3 r2 r3 1
Fig. 4: DFA for binary strings divisible by 3 and not divisible
TABLE II: State Transition Table by 4
2

II. M OORE AND M EALY M ACHINES C. Equivalence of Moore and Mealy Machines
Finite State Machines are basically mathematical models As far as equivalence of both the machines is concerned, a
of computation. Many finite state machines do exist which Moore machine can never be correctly equivalent to a Mealy
produce output apart from just accept and reject states. Moore Machine since the length of the output string varies from
and Mealy Machines are examples of such machines. The Moore Machine to Mealy Machine. Nevertheless we can say
machines are discussed in much more detail below. that a Moore Machine M and a Mealy Machine M 0 can be
considered equivalent if for all inputs w if

A. Moore Machines
bTM 0 (w) = TM (w)
Moore Machines are finite state machines whose output where b = output of initial state of Moore machine M for its
depends only on the current state. Unlike regular DFA and initial state
NFA, it is defined by a six-tuple (Q, Σ, O, δ, λ, q0 ). T(w) = output of the machine taking word w as input
where Q = finite set of states. We can observe here that the Moore Machine and Mealy
Σ = input alphabet. Machine mentioned earlier are infact equivalent. It can be
O = output alphabet. verified by the output of the input string we had taken
q0 = initial state. earlier ”baab”. Moore Machine gives ”00110” where as Mealy
δ is the input transition function where δ:Q × Σ → Q Machine gives ”0110”. So when we concatenate the initial
λ is the output transition function where λ:Q → O output of Moore’s Machine i.e. ”0”, we find that the output
strings are infact equivalent. Similarly we can test for any
string which belongs to the input language defined to hold
b a a, b
equal result for these two machines, provided the initial state
of Moore’s Machine is appended to Mealy’s Machine output
a b at the beginning. The idea is clearly presented in the following
start q0 |0 q1 |1 q2 |0 figure.

Fig. 5: An example of Moore Machine b|0 a|1 a|0, b|0

Consider the example of a Moore Machine mentioned here. |0 a|1 b|0
If we consider the string ”baab” as input, we get ”00110” as start q q0 q1 q2
output. The first ”0” from the starting state q0 and then ”b”
giving ”0” in q1 , followed by ”a”, ”a” and ”b” giving ”1”, ”1”, Fig. 7: An example of Mealy Machine adjusted to make it a
”0” from the states q1 , q1 and q2 respectively. The length of a Moore Machine
output string in a Moore Machine is always greater than the
length of the input string by 1. III. M YHILL -N ERODE T HEOREM
A. Definition
B. Mealy Machines Myhill-Nerode theorem states that a language L over alpha-
Mealy Machines are finite state machines whose output bet Σ is regular if and only if the set of equivalence classes
depends not only on the current state but on the current input of relation RL is finite.
as well. Similar to Moore Machines, it is also described by a This is because the number of states in the smallest DFA
six-tuple (Q, Σ, O, δ, λ, q0 ). possible is equal to the number of equivalence classes since
according to the formal definition of RL , xRL y if and only
if x and y are indistinguishable with respect to L. It can be
b|0 a|1 a|0, b|0 more formally defined as follows:
If RL is a relation on Σ∗ , then for strings x and y of Σ∗ ,
xRL y if and only if {z|xz ∈ L} = {z|yz ∈ L} i.e. both x
a|1 b|0
start q0 q1 q2 and y are indistinguishable with respect to L.

Fig. 6: An example of Mealy Machine B. Uses


This theorem can be used to identify if a given language is
Considering the same example of input string ”baab” for regular or not. If the number of equivalence classes obtained
the Mealy Machine mentioned here, we get the output ”0110” is not finite, then the number of states needed to be built
as it traverses through b outgoing edge of q0 first followed by for building the respective machine is infinite and hence the
a edge of q0 , a edge of q1 and b edge of q1 . We observe here language can’t be treated as a regular one.
that the length of the output string is equal to the length of Another use of this theorem is to minimize a given DFA
the input string unlike in the case of Moore Machine. using table filling algorithm.
3

C. Table Filling Algorithm taken as [a, b] due to pruning of the upper triangle to avoid
1) Draw a table for all pairs of states[q, r]. duplicate values) and with s = 1, they give [c, d] which is
2) After drawing the table, prune the part above the diago- also unmarked. Considering [c, d] with s = 0, 1 gives the same
nal since it’s no longer needed as all pair combinations [c, d] which is still unmarked. Therefor we have completed this
are present below the diagonal itself. step too and head towards the final step i.e. combining states.
3) Mark all cells as marked where q ∈ F and r ∈ / F. Therefore, the final unmarked states are [a, b] and [c, d]. The
4) For every unmarked cell [q, r], if [δ(q, s), δ(r, s)] where final minimized DFA can be shown as follows.
a is an input symbol is marked, then mark [q, r] as
marked. 0 0, 1
Repeat this until maximum number of cells are marked.
5) Combine the unmarked pairs to make them a single state
in minimized DFA. 1
start (a, b) (c, d)
t]
D. Example
Fig. 9: Minimized DFA
0, 1
We observe that the final minimized DFA consists of only 2
states unlike the original one which has 4 states. We observe
1 that this finite machine works the same as the previous one
start a c
with minimized states.
Hence, in this way Myhill-Nerode theorem can be used to
0 0 minimize the DFA and also check if a language is regular or
not based on the number of equivalence classes.
b d REFERENCES
1
1) https://www.geeksforgeeks.org/mealy-and-moore-
0, 1 machines/
2) https://www.slideshare.net/lavishka anuj/moore-and-
Fig. 8: An example of non-minimised DFA mealy-machines-12176634
3) https://www.cs.odu.edu/ toida/nerzic/390teched/regular/reg-
lang/Myhill-Nerode/index.html
States a b c d 4) https://www.tutorialspoint.com/automata theory/dfa minimization.ht
a − − − −
b − − −
c − −
d −

TABLE III: Table Filling Algorithm


States a b c d
a − − − −
b √ −
√ − −
c √ √ − −
d −

TABLE IV: Table after marking

Let’s consider an example of non-minimized DFA and try


to minimize it using this technique. The first table is the table
we have constructed keeping the number of states in mind. We
have pruned off the upper part as per our procedure and then
we start marking the cells which have only one final state
in them. So we have successfully completed our third step
too. Now we proceed to the fourth step where we check for
transitivity. So only 2 cells are left out viz. [a, b] and [c, d].
The transition function with s = 0 gives [b, a] state (can be

Das könnte Ihnen auch gefallen