Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Theory of Computational Finite Automata with Output, Study notes of Printing

A lecture note on the theory of computational finite automata with output. It covers the definition of Moore machines and Mealy machines, their differences, and how they can be converted into each other. The document also includes examples and pictorial representations of Moore machines and Mealy machines.

Typology: Study notes

2022/2023

Uploaded on 03/14/2023

dylanx
dylanx 🇺🇸

4.7

(21)

287 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Anbar University/College of Computer 2012-2013 Computational Theory Lecture note
Lecture eight Lecturer: Dr Ali Jbaeer Dawood
Page 1 of 8
Theory of Computational
Finite Automata with Output
Lecture Objective
Moore Machines
Mealy Machines
Moore = Mealy
Moore Machine Definition:
Moore machine is a collection of five things:
1. A finite set of states q0, q1, q2, ..., where q0 is designated as the start state.
2. An alphabet of letters for forming the input string = {a, b, c, …}.
3. An alphabet of possible output characters Γ = {0, 1, 2, …}.
4. A transition table that shows for each state and each input letter what state is
reached next.
5. An output table that shows what character from Γ is printed by each state as it is
entered.
Notes:
We did not assume that the input alphabet is the same as the output alphabet Γ.
To keep the output alphabet separate from the input alphabet, we give it a
different name Γ (instead of ∑) and use number symbols {0, 1, …} (instead of
{a, b, …}).
We refer to input symbols as letters, whereas we refer to output symbols as
characters.
We adopt the policy that a Moore machine always begins by printing the
character dictated by the mandatory start state. So, if the input string has 7 letters,
then the output string will have 8 characters, because it includes 8 states in its
path.
A Moore machine does not define a language of accepted words, because there is
no such thing as a final state.
Every possible input string creates an output string. The processing is terminated
when the last input letter is read and the last output character is printed.
There are some subtle ways to turn Moore machines into language definers.
pf3
pf4
pf5
pf8

Partial preview of the text

Download Theory of Computational Finite Automata with Output and more Study notes Printing in PDF only on Docsity!

Lecture eight Lecturer: Dr Ali Jbaeer Dawood

Theory of Computational

Finite Automata with Output

Lecture Objective  Moore MachinesMealy MachinesMoore = Mealy

Moore Machine Definition: Moore machine is a collection of five things:

  1. A finite set of states q 0 , q 1 , q 2 , ..., where q 0 is designated as the start state.
  2. An alphabet of letters for forming the input string = {a, b, c, …}.
  3. An alphabet of possible output characters Γ = {0, 1, 2, …}.
  4. A transition table that shows for each state and each input letter what state is reached next.
  5. An output table that shows what character from Γ is printed by each state as it is entered. Notes:
  • We did not assume that the input alphabet is the same as the output alphabet Γ.
  • To keep the output alphabet separate from the input alphabet, we give it a different name Γ (instead of ∑) and use number symbols {0, 1, …} (instead of {a, b, …}).
  • We refer to input symbols as letters , whereas we refer to output symbols as characters.
  • We adopt the policy that a Moore machine always begins by printing the character dictated by the mandatory start state. So, if the input string has 7 letters, then the output string will have 8 characters, because it includes 8 states in its path.
  • A Moore machine does not define a language of accepted words, because there is no such thing as a final state.
  • Every possible input string creates an output string. The processing is terminated when the last input letter is read and the last output character is printed.
  • There are some subtle ways to turn Moore machines into language definers.

Lecture eight Lecturer: Dr Ali Jbaeer Dawood

Example: Moore machine defined by a table:

  • Input alphabet: ∑ = {a, b}
  • Output alphabet: Γ = {0, 1}
  • Names of states: q 0 , q 1 , q 2 , q 3 with q 0 being the start state.
  • Transition and output table (combined):

Pictorial Representation:

  • Moore machines have pictorial representations similar to FAs.
  • The difference is that inside each state, in addition to the state name, we also specify the output character printed by that state, using the format state – name/output.
  • Hence, the Moore machine in the above example has the following pictorial representation: Example:
  • We indicate the start state by an outside arrow since there is no room for the usual - sign.
  • Given the input string abab , the output sequence is 10010.
  • Note that the length of the output string is one longer than the length of the input string. Example:
  • Suppose we are interested in knowing exactly how many times the substring aab occurs in a long input string. The following Moore machine will count this for us:
  • Every state of this machine prints out a 0, except for q3, which prints a 1.
  • To get to q 3 , we must have come from q 2 and have just read a b. To get to q 2 , we must have read at least two a’s in a row.
  • After finding the subtring aab and tallying a 1 for it, the machine looks for the next aab. Hence, the number of 1’s in the output string is exactly the number of substrings aab in the input string.
  • Consider an FA that accepts a language L:

Lecture eight Lecturer: Dr Ali Jbaeer Dawood

Example:

  • The following Mealy machine prints out the 1’s complement of an input bit string.
  • This means that it will produce a bit string that has a 1 whenever the input string has a 0, and a 0 whenever the input has a 1.
  • If the input string is 001010, the output will be 110101 Example:
  • Let consider a Mealy machine, called increment machine , which reads a binary number and prints out the binary number that is one larger.
  • Assume that the input bit string is a binary number fed in backward; that is, unit digit first, then 2’s digit, 4’s digit, etc.
  • The output string will be the binary number that is one greater and that is generated right to left.
  • The machine will have 3 states: start, owe-carry and no-carry. The owe-carry state represents the overflow when two bits of 1’s are added, we print a 0 and we carry a 1.
  • From the start state, if we read a 0, we print a 1 (incrementing process), and we go to the no-carry state. If we read a 1, we print a 0 (incrementing) and we go to the owe-carry state.
  • At any point in the process, in we are in the no-carry state, we print the next bit just as we read it and remains in no-carry.
  • However, if we are in the owe-carry state and read a 0, we print a 1 and go to no- carry. If we are in owe-carry and read a 1, we print a 0 and we loop back to owe- carry.
  • Let the input string be 1011 (binary representation of 11).
  • The string is fed into the machine as 1101 (backwards).
  • The output will be 0011, which when reversed is 1100 and is the binary representation of 12.
  • In Mealy machine, output length = input length. Hence, if input were 1111, then output would be 0000 ( overflow situation ). Example:
  • Although a Mealy machine does not accept or reject an input string, it can recognize a language by making its output string answer some question about the input.
  • Consider the language of all words that have a double letter ( aa or bb ) in them.

Lecture eight Lecturer: Dr Ali Jbaeer Dawood

  • We can build a Mealy machine that can take an input string of a’s and b’s, and print out an output string of 0’s and 1’s such that if the n-th output character is a 1, it means that the n-th input letter is the second letter in a pair of double letters.
  • The complete picture of this machine is as follows:
  • If the input string is ababbaab , the output will be 00001010.
  • This machine recognizes the occurrences of aa or bb.
  • Note that the triple letter word aaa produces the output 011 since the second and third letters are both the back end of a pair of double a’s.

Moore = Melay:

  • So far, we have define that two machines are equivalent if they accept the same language.
  • In this sense, we cannot compare a Mealy machine and a Moore machine because they are not language definers. Definition:
  • Given the Mealy machine Me and the Moore machine Mo (which prints the automatic start state character x), we say that these two machines are equivalent if for every input string, the output string from Mo is exactly x concatenated with the output string from Me. Theorem 8: If Mo is a Moore machine, then there is a Mealy machine Me that is equivalent to Mo. Proof by constructive algorithm:
  • Consider a particular state in Mo , say state q 4 , which prints a certain character, say t.
  • Consider all the incoming edges to q 4. Suppose these edges are labeled with a, b, c, ...
  • Let us re-label these edges as a/t, b/t, c/t, ... and let us erase the t from inside the state q 4. This means that we shall be printing a t on the incoming edges before we enter q 4.

Lecture eight Lecturer: Dr Ali Jbaeer Dawood

  • An edge that was a loop in Me may becomes two edges in Mo , one that is a loop and one that is not.
  • If there is ever a state that has no incoming edges, we can assign it any printing instruction we want, even if this state is the start state.
  • If we have to make copies of the start state in Me , we can let any of the copies be the start state in Mo , because they all give the identical directions for proceeding to other states.
  • Having a choice of start states means that the conversion of Me into Mo is NOT unique.
  • Repeating this process for each state of Me will produce an equivalent Mo. The proof is completed.
  • Together, Theorems 8 and 9 allow us to say Me = Mo. Example:
  • Convert the following Mealy machine into a Moore machine:
  • Following the algorithm, we first need two copies of q 0 :
  • All the edges coming into state q 1 (and also q 3 ) have the same printing instruction. So, apply the algorithm to q 1 and q 3 :

Lecture eight Lecturer: Dr Ali Jbaeer Dawood

  • The only job left is to convert state q 2. There are 0-printing edges and 1-printing edges coming into q 2. So, we need two copies of q 2. The final Moore machine is: