The Moore Machine

A Comprehensive, Elite Guide to Finite State Transducers

1. Definition & Fundamental Concepts

In the Theory of Computation, a Moore Machine is a finite-state machine whose current output values are determined strictly by its current state. This is in direct contrast to the Mealy Machine, where output depends on both the current state and the current input.

Because the output is tied to the state itself, a Moore machine acts as an unconditional generator—the moment it enters a state, an output character is produced, regardless of what input brought it there.

Formal Mathematical Definition

A Moore Machine is formally defined as a 6-tuple (Q, Σ, Δ, δ, λ, q0) where:

CRITICAL RULE: No Final States
A Moore Machine is a Transducer, not an Acceptor. It does not output "Yes" or "No" by halting on a final state. Instead, it continuously translates an input string into an output string. Never draw double circles (final states) in a Moore Machine.

2. Expert Tips & Tricks for Designing Moore Machines

Designing Moore machines requires a slightly different mindset than designing standard DFAs. Master these core principles:

  1. The N+1 Output Rule: The length of the output string produced by a Moore Machine is always Length of Input String + 1. This is because the machine prints the output of the initial state before any input is even consumed.
  2. State Representation: Each state circle must be divided into two halves. The top half contains the state name (e.g., q0), and the bottom half contains the output symbol (e.g., 1).
  3. Determine Output Meaning First: Before drawing arrows, define exactly what each state represents and what its output should be. E.g., "State q2 means we have seen 'aba' and therefore outputs '1'".
  4. Handling the Start State: Since the start state outputs a character immediately, if the problem requires a specific output only when a condition is met, the start state usually holds a neutral, default, or initial output (like 0 or empty).
  5. Sequence Detection Strategy: For a sequence of length N, you generally need N + 1 states. E.g., To detect "110", you need 4 states: Start, Saw '1', Saw '11', Saw '110'.

3. Complete Masterclass Examples (1 to 10)

Below are precisely engineered step-by-step designs of Moore Machines. The diagrams are generated with absolute geometric clarity.

Example 1: 1's Complement Generator

Problem: Design a Moore machine that takes a binary input string and produces its 1's complement (flips 0s to 1s and 1s to 0s).

Logic & State Definition:
  • q0: Start state. Output is a neutral placeholder, say 0 (this first bit is extra due to the N+1 rule).
  • q1: Represents "Just read a 0". Must output 1.
  • q2: Represents "Just read a 1". Must output 0.
Transitions are based entirely on the input character routing to the state that holds the correct output.
Start q0 0 q1 1 q2 0 0 1 0 1 1 0

Example 2: Residue Modulo 3 (Binary Input)

Problem: Design a Moore machine that outputs the remainder when a binary number (read left to right) is divided by 3. Alphabet Σ = {0, 1}.

Logic & State Definition: When converting binary left-to-right, appending a '0' multiplies the value by 2. Appending a '1' multiplies by 2 and adds 1. Formula: Next_Mod = (Current_Mod * 2 + input) % 3.
  • q0: Current Remainder 0. Output 0. (Start state).
  • q1: Current Remainder 1. Output 1.
  • q2: Current Remainder 2. Output 2.
q0 0 0 q1 1 q2 2 1 1 1 0 0

Example 3: Count 'a's Modulo 2 (Even/Odd)

Problem: Over alphabet Σ = {a, b}, design a Moore machine that outputs 0 if the number of 'a's read so far is Even, and 1 if Odd.

Logic & State Definition:
  • q0: Even number of 'a's. Output 0. (Start state, since 0 'a's is even).
  • q1: Odd number of 'a's. Output 1.
  • Input 'b' has no effect on the count, so it loops back to the same state.
q0 0 b q1 1 b a a

Example 4: Sequence Detector "10" (Overlapping Allowed)

Problem: Output 1 whenever the sequence "10" is detected in a binary stream. Otherwise output 0.

Logic & State Definition: Sequence of length 2 requires 3 states.
  • q0: Start state (nothing seen). Output 0.
  • q1: Saw '1'. Output 0.
  • q2: Saw '10' (Sequence matched!). Output 1.
From q2, if we read '1', it becomes the first '1' of a potential new sequence, so go to q1. If we read '0' (making it "100"), the sequence breaks completely, go to q0.
q0 0 0 q1 0 1 q2 1 1 0 1 0

Example 5: Sequence Detector "11" (Overlapping Allowed)

Problem: Output 1 whenever the string "11" occurs. E.g., for input "111", output "0011".

Logic & State Definition:
  • q0: Start state. Output 0.
  • q1: Saw '1'. Output 0.
  • q2: Saw '11'. Output 1.
From q2, reading another '1' means we just saw another "11" (since overlapping is allowed). So `q2 -1-> q2`.
q0 0 0 q1 0 q2 1 1 1 1 0 0

Example 6: End Character Identification

Problem: Over Σ={a, b}, output A if the string ends in 'a', B if it ends in 'b', and C otherwise (initially).

Logic & State Definition:
  • q0: Initial state (ends in neither). Output C.
  • qa: Last character read was 'a'. Output A.
  • qb: Last character read was 'b'. Output B.
Start q0 C qa A a qb B b a b b a

Example 7: Sequence Detector "aba"

Problem: Output 1 when the sequence "aba" is completed. Output 0 otherwise. Overlapping allowed.

Logic & State Definition: Requires 4 states (Length + 1).
  • q0: Start (out 0).
  • q1: Saw 'a' (out 0).
  • q2: Saw 'ab' (out 0).
  • q3: Saw 'aba' (out 1).
From `q3` (aba), reading 'b' means we now have "...abab" (ending in "ab"), so go to `q2`. Reading 'a' means "...abaa" (ending in "a"), go to `q1`.
q0 0 b q1 0 a q2 0 q3 1 a b a b b a

Example 8: Count 'a's Modulo 4 (Unary Input)

Problem: Input consists only of 'a's. Output the number of 'a's read so far modulo 4.

Logic & State Definition:
  • q0: Mod 0. Output 0.
  • q1: Mod 1. Output 1.
  • q2: Mod 2. Output 2.
  • q3: Mod 3. Output 3.
Start q0 0 q1 1 q2 2 q3 3 a a a a

Example 9: Consecutive Identical Symbols Output

Problem: Output 1 whenever the last two inputs were identical ("00" or "11"). Output 0 otherwise.

Logic & State Definition:
  • q_start: Start. Out 0.
  • q_0: Last was '0' (but not '00'). Out 0.
  • q_1: Last was '1' (but not '11'). Out 0.
  • q_00: Last two were '00'. Out 1.
  • q_11: Last two were '11'. Out 1.
qS 0 q0 0 q1 0 q00 1 q11 1 0 1 0 1 1 0 0 1 1 0

Example 10: "Contains Substring 001" Generator

Problem: Output 1 if the string contains "001" anywhere within it. Once "001" is found, output 1 for all subsequent inputs.

Logic & State Definition: This is a string matching problem where the final matching state acts as a sink.
  • q0: Start. Out 0.
  • q1: Saw '0'. Out 0.
  • q2: Saw '00'. Out 0.
  • q3: Saw '001'. Out 1. (Self-loops on both 0 and 1 forever).
q0 0 1 q1 0 q2 0 0 q3 1 0, 1 0 0 1 1

Example 11: Sequence Detector "010" (Overlapping)

Problem: Output 1 whenever the sequence "010" is detected in the input stream. Overlapping is allowed (e.g., "01010" outputs "000101").

Logic & State Definition:
  • q0: Start state. Out 0.
  • q1: Saw '0'. Out 0.
  • q2: Saw '01'. Out 0.
  • q3: Saw '010' (Match!). Out 1.
From `q3`, reading a '1' means we now have "...0101", which ends in "01", so transition to `q2`. Reading a '0' means "...0100", ending in "0", so transition to `q1`.
q0 0 1 q1 0 0 q2 0 q3 1 0 1 0 1 1 0

Example 12: Binary Divisibility by 2

Problem: Design a Moore Machine to output 0 if the binary string read so far is divisible by 2 (Even), and 1 if not (Odd). Read from left to right.

Logic & State Definition: A binary number is divisible by 2 if and only if its last digit is '0'.
  • q0: Start state. Neutral, assume 0 for empty string. Out 0.
  • q1: Last bit was '0' (Even). Out 0.
  • q2: Last bit was '1' (Odd). Out 1.
q0 0 q1 0 0 q2 1 1 0 1 1 0

Example 13: T-Flip Flop (Toggle on 1)

Problem: Design a Moore machine that toggles its output state between 0 and 1 every time a '1' is received. An input of '0' maintains the current output.

Logic & State Definition:
  • q0: Current output is 0. Loop on 0, switch to q1 on 1.
  • q1: Current output is 1. Loop on 0, switch to q0 on 1.
q0 0 0 q1 1 0 1 1

Example 14: Ends in "aa" or "bb"

Problem: Output 1 if the string ends in a double character ("aa" or "bb"). Otherwise output 0.

Logic & State Definition:
  • q0: Start. Out 0.
  • qa: Last char 'a'. Out 0.
  • qb: Last char 'b'. Out 0.
  • qaa: Ends in 'aa'. Out 1.
  • qbb: Ends in 'bb'. Out 1.
q0 0 qa 0 qb 0 qaa 1 a qbb 1 b a b a b b a b a

Example 15: 2's Complement (LSB to MSB)

Problem: Generate the 2's complement of a binary string read from Least Significant Bit to Most Significant Bit.

Logic & State Definition: Rule for 2's complement: Leave all initial '0's alone. Leave the first '1' alone. Flip every bit after that first '1'.
  • q0: Start / Reading initial 0s. Out 0.
  • q1: Just read the first '1'. Out 1.
  • q2: Flip Mode (Read 0). Out 1.
  • q3: Flip Mode (Read 1). Out 0.
q0 0 0 q1 1 q2 1 0 q3 0 1 1 0 1 1 0

Example 16: Parity Checker (Even '0's and Even '1's)

Problem: Output 1 if the binary string has an Even number of '0's AND an Even number of '1's. Output 0 otherwise.

Logic & State Definition: Requires 4 combinations of parities.
  • qEE: Even 0s, Even 1s (Start state). Out 1.
  • qEO: Even 0s, Odd 1s. Out 0.
  • qOE: Odd 0s, Even 1s. Out 0.
  • qOO: Odd 0s, Odd 1s. Out 0.
qEE 1 qEO 0 qOE 0 qOO 0 1 1 1 1 0 0 0 0

Example 17: String Length Modulo 3

Problem: Output Y if the total length of the string is a multiple of 3. Otherwise output N. Alphabet is {a, b}.

Logic & State Definition: The actual input characters don't matter, only every transition counts as length + 1.
  • q0: Length Mod 0. Out Y.
  • q1: Length Mod 1. Out N.
  • q2: Length Mod 2. Out N.
q0 Y q1 N q2 N a,b a,b a,b

Example 18: Sink State (Contains 'bb')

Problem: Output 1 as soon as the string "bb" is encountered, and keep outputting 1 forever regardless of subsequent inputs.

Logic & State Definition:
  • q0: Start. Out 0.
  • q1: Saw one 'b'. Out 0.
  • q2: Saw 'bb'. Out 1. This is a sink state.
q0 0 a q1 0 q2 1 a,b b b a

Example 19: D-Flip Flop (Delay by 1 / Previous Input)

Problem: Output the exact bit that was received in the previous clock cycle (a delay). For the first character, output a default 0.

Logic & State Definition:
  • qS: Start state. Output 0.
  • q0: Previous input was '0'. Output 0.
  • q1: Previous input was '1'. Output 1.
qS 0 q0 0 0 q1 1 1 0 1 1 0

Example 20: Sequence Detector "111" (Overlapping Allowed)

Problem: Output 1 every time three consecutive 1's are seen.

Logic & State Definition:
  • q0: Start / Reset on 0. Out 0.
  • q1: Saw one '1'. Out 0.
  • q2: Saw two '1's. Out 0.
  • q3: Saw three '1's. Out 1. Loops on '1' to keep matching.
q0 0 0 q1 0 q2 0 q3 1 1 1 1 1 0 0 0