SlideShare a Scribd company logo
2
Most read
3
Most read
8
Most read
ComputationTheory1 A.L. Mustafa Ghanem Saeed
1| P a g e
ComputerScience Department Collage of Science CihanUniversity
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 M is the 5 tuple M = (Q,, Г, Ϩ, q0) where
1. A finite set of states q0, q1, q2, …, where q0 is designed as the
start state.
2. An alphabet of letters for forming the input string Σ= { a, b, c, …}.
3. An alphabet of possible output characters Г = { x, y, z, …}.
4. A transition function Ϩ as in table that shows for each state and
each input letter what state is reached next.
5. Start state as q0.
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:
ComputationTheory1 A.L. Mustafa Ghanem Saeed
2| P a g e
ComputerScience Department Collage of Science CihanUniversity
Note1:
 The two symbols inside the circle are separated by a slash "/", on the
left side is the nameof the state and on the right is the outputfrom
that state.
 If the inputstring is abab to the Moore machinethen the output will
be 10010.
Note 2:
A Moore machineis 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 cannothave 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}
ComputationTheory1 A.L. Mustafa Ghanem Saeed
3| P a g e
ComputerScience Department Collage of Science CihanUniversity
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}
Exam
ComputationTheory1 A.L. Mustafa Ghanem Saeed
4| P a g e
ComputerScience Department Collage of Science CihanUniversity
ple 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}
ComputationTheory1 A.L. Mustafa Ghanem Saeed
5| P a g e
ComputerScience Department Collage of Science CihanUniversity
Mealy Machines:
A Mealy machine M is the 5 tuple, M = (Q, , ,Г, Ϩ, q0) where:
1. A finite set of states q0,q1,q2,…, where q0 is designated the start
state
2. An alphabet Σ of input letters
3. An alphabet Г of output characters
4. A finite set of transitions that indicate, for each state and letter of
the input alphabet, the state to go to next and the character that is
output.
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:
ComputationTheory1 A.L. Mustafa Ghanem Saeed
6| P a g e
ComputerScience Department Collage of Science CihanUniversity
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.
Note:
 Two’s complement is especially important because it allows us to represent signed
numbers in binary.
ComputationTheory1 A.L. Mustafa Ghanem Saeed
7| P a g e
ComputerScience Department Collage of Science CihanUniversity
 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}
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}
ComputationTheory1 A.L. Mustafa Ghanem Saeed
8| P a g e
ComputerScience Department Collage of Science CihanUniversity
Note: The machine represented in in example 4, if the input is 1010100,
the output is 0101100. This is a casewhere the input alphabet and output
alphabet are both {0, 1}.
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
 Mealy model might require less states to model but might be more
complex to understand
Note: All examples in Moore machine can be solvein mealy Machine
and vris versa becauseMealy and Mooremachines are equivalent, you
have totry solving themas Homework.

More Related Content

PDF
Bus structure in Computer Organization.pdf
PPTX
Unit iv(simple code generator)
PPT
Ll(1) Parser in Compilers
PPT
Minimum spanning tree
PPTX
Intro to assembly language
PPTX
Cyrus beck line clipping algorithm
PDF
Error detection & correction codes
PDF
Arithmetic and logic unit
Bus structure in Computer Organization.pdf
Unit iv(simple code generator)
Ll(1) Parser in Compilers
Minimum spanning tree
Intro to assembly language
Cyrus beck line clipping algorithm
Error detection & correction codes
Arithmetic and logic unit

What's hot (20)

PDF
Lecture 01 introduction to compiler
PPTX
digital electronics Design of 101 sequence detector without overlapping for...
PPT
chapter3 - Basic Processing Unit.ppt
PPTX
Timing and control
PPTX
First and follow set
PPTX
Types of grammer - TOC
PPTX
Lecture 37
PPTX
Semantic nets in artificial intelligence
PPTX
2D viewing & clipping
PPT
Floating point arithmetic
PDF
TOC 1 | Introduction to Theory of Computation
PPTX
Turing machine
PPTX
1.10. pumping lemma for regular sets
PPT
Line clipping
PPTX
PIPELINE INTERRUPTS
PPTX
Artificial Intelligence (AI) | Prepositional logic (PL)and first order predic...
PPTX
bus and memory tranfer (computer organaization)
PDF
Implementation of boolean function through1 multiplexer
PPT
Polygon filling
Lecture 01 introduction to compiler
digital electronics Design of 101 sequence detector without overlapping for...
chapter3 - Basic Processing Unit.ppt
Timing and control
First and follow set
Types of grammer - TOC
Lecture 37
Semantic nets in artificial intelligence
2D viewing & clipping
Floating point arithmetic
TOC 1 | Introduction to Theory of Computation
Turing machine
1.10. pumping lemma for regular sets
Line clipping
PIPELINE INTERRUPTS
Artificial Intelligence (AI) | Prepositional logic (PL)and first order predic...
bus and memory tranfer (computer organaization)
Implementation of boolean function through1 multiplexer
Polygon filling
Ad

Viewers also liked (20)

PPT
Moore and mealy machines
PDF
PLANEJAMENTO DE APLICATIVO PARA MOBILE E WEB - AGÊNCIA CLASSIC COMUNICAÇÃO
PDF
Syukri 4I 2016
PPT
Continuous integration (d.atanasov)
PDF
安富人生_2010_01
PPT
Violencia en la sociedad
PDF
It's all about apps: a gestão ágil de aplicativos mobile
PDF
Tricia 4R 2016
PDF
Candy Liew 4E 2016
PDF
Inbound Marketing: o que é e por que não podemos ignorá-lo?
PPTX
Internship PPT on JSTI 2016
PPTX
Introducción a la ps. clínica
PPT
Biodiesel production from various oils
PDF
Introducing The Digital Enterprise (SAUG Keynote, Brisbane, May 2016)
PDF
Introduction to working capital
PPTX
Dicas essenciais de SEO para e-commerce
PPTX
Experimental Investigation of Floating slab Incorporated with Pumice stone an...
PDF
Getting Things Done: A Arte de Fazer Acontecer com Salesforce
PDF
O Futuro do Atendimento na Era do Cliente Conectado: Salesforce WT 2016
Moore and mealy machines
PLANEJAMENTO DE APLICATIVO PARA MOBILE E WEB - AGÊNCIA CLASSIC COMUNICAÇÃO
Syukri 4I 2016
Continuous integration (d.atanasov)
安富人生_2010_01
Violencia en la sociedad
It's all about apps: a gestão ágil de aplicativos mobile
Tricia 4R 2016
Candy Liew 4E 2016
Inbound Marketing: o que é e por que não podemos ignorá-lo?
Internship PPT on JSTI 2016
Introducción a la ps. clínica
Biodiesel production from various oils
Introducing The Digital Enterprise (SAUG Keynote, Brisbane, May 2016)
Introduction to working capital
Dicas essenciais de SEO para e-commerce
Experimental Investigation of Floating slab Incorporated with Pumice stone an...
Getting Things Done: A Arte de Fazer Acontecer com Salesforce
O Futuro do Atendimento na Era do Cliente Conectado: Salesforce WT 2016
Ad

Similar to Finite State Machines with Output (20)

PPT
Lesson 18 Automata .ppt
PDF
Theory of computation and automata
PDF
Theory of computation and automata
PPTX
CS 5th.pptx
PPTX
Mealy and moore machine
DOC
Chapter7
PDF
FINITE AUTOMATA WITH OPUTPUT MEALLY AND MOORE.pdf
DOCX
Automata theory introduction
PPTX
Formalization Machines and Sastes
PDF
@vtucode.in-module-1-21CS51-5th-semester (1).pdf
PDF
state_machines1.pdf
PPT
1. Introduction to __Automata Theory.ppt
PPTX
Moore and mealy machines
PDF
Mba ebooks ! Edhole
PDF
Free Ebooks Download ! Edhole
PPT
String Matching with Finite Automata,Aho corasick,
PPTX
symbolic_automata or Advanced Programming Practice.pptx
PPTX
Automaton
PDF
Assignment8
Lesson 18 Automata .ppt
Theory of computation and automata
Theory of computation and automata
CS 5th.pptx
Mealy and moore machine
Chapter7
FINITE AUTOMATA WITH OPUTPUT MEALLY AND MOORE.pdf
Automata theory introduction
Formalization Machines and Sastes
@vtucode.in-module-1-21CS51-5th-semester (1).pdf
state_machines1.pdf
1. Introduction to __Automata Theory.ppt
Moore and mealy machines
Mba ebooks ! Edhole
Free Ebooks Download ! Edhole
String Matching with Finite Automata,Aho corasick,
symbolic_automata or Advanced Programming Practice.pptx
Automaton
Assignment8

Finite State Machines with Output

  • 1. ComputationTheory1 A.L. Mustafa Ghanem Saeed 1| P a g e ComputerScience Department Collage of Science CihanUniversity 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 M is the 5 tuple M = (Q,, Г, Ϩ, q0) where 1. A finite set of states q0, q1, q2, …, where q0 is designed as the start state. 2. An alphabet of letters for forming the input string Σ= { a, b, c, …}. 3. An alphabet of possible output characters Г = { x, y, z, …}. 4. A transition function Ϩ as in table that shows for each state and each input letter what state is reached next. 5. Start state as q0. 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:
  • 2. ComputationTheory1 A.L. Mustafa Ghanem Saeed 2| P a g e ComputerScience Department Collage of Science CihanUniversity Note1:  The two symbols inside the circle are separated by a slash "/", on the left side is the nameof the state and on the right is the outputfrom that state.  If the inputstring is abab to the Moore machinethen the output will be 10010. Note 2: A Moore machineis 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 cannothave 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}
  • 3. ComputationTheory1 A.L. Mustafa Ghanem Saeed 3| P a g e ComputerScience Department Collage of Science CihanUniversity 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} Exam
  • 4. ComputationTheory1 A.L. Mustafa Ghanem Saeed 4| P a g e ComputerScience Department Collage of Science CihanUniversity ple 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}
  • 5. ComputationTheory1 A.L. Mustafa Ghanem Saeed 5| P a g e ComputerScience Department Collage of Science CihanUniversity Mealy Machines: A Mealy machine M is the 5 tuple, M = (Q, , ,Г, Ϩ, q0) where: 1. A finite set of states q0,q1,q2,…, where q0 is designated the start state 2. An alphabet Σ of input letters 3. An alphabet Г of output characters 4. A finite set of transitions that indicate, for each state and letter of the input alphabet, the state to go to next and the character that is output. 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:
  • 6. ComputationTheory1 A.L. Mustafa Ghanem Saeed 6| P a g e ComputerScience Department Collage of Science CihanUniversity 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. Note:  Two’s complement is especially important because it allows us to represent signed numbers in binary.
  • 7. ComputationTheory1 A.L. Mustafa Ghanem Saeed 7| P a g e ComputerScience Department Collage of Science CihanUniversity  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} 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}
  • 8. ComputationTheory1 A.L. Mustafa Ghanem Saeed 8| P a g e ComputerScience Department Collage of Science CihanUniversity Note: The machine represented in in example 4, if the input is 1010100, the output is 0101100. This is a casewhere the input alphabet and output alphabet are both {0, 1}. 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  Mealy model might require less states to model but might be more complex to understand Note: All examples in Moore machine can be solvein mealy Machine and vris versa becauseMealy and Mooremachines are equivalent, you have totry solving themas Homework.