Design and Equivalence of Mealy/Moore Machines Detecting the Overlapping Sequence 1010
We want a sequential circuit that reads a binary stream and outputs exactly when the last four input bits form the pattern 1010, with overlapping allowed (so a new detection can begin before the previous one “finishes”). This is a classic sequence detector design problem using finite-state machines.
We will build:
- a Moore machine (output depends only on state) for
1010with overlapping, - a Mealy machine directly,
- then convert the Moore machine into an equivalent Mealy machine and prove equivalence.
Key automata notions used below:
- Moore machine
- Mealy machine
- overlapping detection
- equivalence of FSMs.
We will use the standard Moore→Mealy edge-labeling rule: move each Moore state's output onto the incoming transitions of the corresponding state in the Mealy model.2
Footnotes
-
Finite-state machine - Wikipedia - Describes Moore→Mealy conversion by putting destination Moore state output on Mealy transitions. ↩
-
Moore to Mealy Machine Conversion - Tutorialspoint - Provides conversion rules moving state outputs to incoming Mealy transitions and notes about equivalence. ↩
Sequence Detector 1010 (Overlapping) using Mealy and Moore models
Strategy: represent “how much of 1010 we have matched so far”
Define machine states to represent the length of the longest suffix of the processed input that is also a prefix of the target pattern 1010.
Let the target be . Its proper prefixes are:
- (length 0),
1(length 1),10(length 2),101(length 3),1010(length 4).
In a suffix-tracking design, after each new input bit, we update to the longest prefix that matches the new suffix—this naturally supports overlapping.
Step-by-step construction of Moore states for overlapping detection of 1010
- 1Step 1
Let Moore states be where means the last bits equal the length- prefix of
1010(so means the last 4 bits are exactly1010). - 2Step 2
Set output only on state ; set on –.
- 3Step 3
For each state and input bit , form the new string suffix candidate by appending to the currently matched prefix, then choose the longest suffix that is a prefix of
1010. - 4Step 4
In particular, when you detect
1010, the next state on the next input must reuse any suffix that can start a new match (e.g.,0can leave you ready for prefix1only if it completes it; this follows automatically from the suffix-prefix rule). - 5Step 5
The resulting Moore transition graph is deterministic and outputs with one-cycle latency relative to Mealy; overlap is preserved because the suffix-prefix method is overlap-aware.
Moore machine for detecting overlapping 1010
Moore transition table
Let Moore output be (only depends on current state). States:
- : matched length 0 (no useful suffix),
- : matched
1, - : matched
10, - : matched
101, - : matched
1010(detection state).
Moore outputs:
- ,
- .
Now compute transitions by longest suffix that is also a prefix of 1010.
| Present state | Input -> Next | Input -> Next |
|---|---|---|
(1) | ||
(10) | ||
(101) | ||
(1010) |
Reasoning highlights (overlap):
- From on input
0, we complete1010, so go to . - From on input
0, the last two bits are10, so we land in $S_2`. - From on input
1, the last bit is1, so we land in .
Mermaid diagram (Moore)
Mealy machine for detecting overlapping 1010 (output on transitions)
For a Mealy machine, the output is associated with the transition labeled by the input.
We can obtain a compact Mealy detector by emitting on the transition that completes 1010.
Define Mealy states to be the same matched-prefix states – (no need to keep an “ state” because detection is produced on the edge). However, we must still transition correctly after detection for overlap.
Let iff from state $S_3we read input0(because that edge completes1010`).
Mealy transition/output table
| Present state | Input -> (Next, Output) | Input -> (Next, Output) |
|---|---|---|
Notes:
- From S_2$—this is exactly the overlap behavior.
Mermaid diagram (Mealy)
type="tip" title="How overlap is handled" content="Using states that store the longest suffix that matches a prefix of the pattern automatically reuses relevant suffix bits after a detection, enabling back-to-back overlapping matches."
Converting the Moore machine into an equivalent Mealy machine
Conversion rule (standard):
- In a Moore machine, output is on the state.
- Convert to an equivalent Mealy machine by transferring that state’s output onto each incoming transition to that state.2
So, for every Moore transition , label the Mealy transition with output .
This yields a Mealy machine whose output timing matches the Moore machine one step “earlier” in the transition-label representation; equivalence is stated in terms of the output sequence produced for the same input stream (after appropriate alignment of Moore’s state-output convention).
Footnotes
-
Finite-state machine - Wikipedia - Describes Moore→Mealy conversion by putting destination Moore state output on Mealy transitions. ↩ ↩2
-
Moore to Mealy Machine Conversion - Tutorialspoint - Provides conversion rules moving state outputs to incoming Mealy transitions and notes about equivalence. ↩
Moore → Mealy conversion (explicit construction)
- 1Step 1
Keep the same underlying state graph structure and next-state function .
- 2Step 2
For each edge , create a Mealy edge from the corresponding state.
- 3Step 3
Set the Mealy output on to be .
- 4Step 4
You may optionally remove redundant Mealy states if multiple transitions lead to identical behavior; for equivalence proof we keep the straightforward conversion.
Resulting Mealy transitions from the Moore machine
Using , only transitions that enter produce output .
From the Moore transition table:
- The only way to enter is from on input
0. - Therefore, the converted Mealy machine labels exactly that transition with output .
If we now drop as a “stabilizing” Moore state (while preserving next-state behavior), the converted Mealy machine coincides with the direct Mealy detector earlier.
Concretely, in the converted Mealy machine:
- ,
- all other .
This matches the Mealy table:
- From on
0, go to with output $1`, - Otherwise output .
Proof of equivalence (Moore → Mealy conversion correctness)
We prove that the Moore machine and its converted Mealy machine produce the same output stream for every input sequence.
Formal definitions (output interpretation)
Let:
- Moore machine output is where is the state during the -th input step.
- Mealy machine output is labeled on transitions: if the machine is in and reads input , it outputs on the transition to .
Using the conversion rule, we set:
This matches the standard Moore→Mealy conversion by placing the destination Moore state’s output on the transition. The correctness argument follows by induction on input length.2
Theorem
For any input string , the Mealy output on transition equals the Moore output of the destination state at time :
Thus, the output sequences align exactly with the intended timing of “output from states” being transferred onto the transition edges.
Proof (by induction)
Base case ():
Moore: after applying input , the next state is , and the Moore output associated with being in is .
Mealy: by construction, the output on the transition reading is
So the equality holds.
Inductive step: Assume for some that
Consider transition at time . In both machines, the state before reading input is the same reachable state (call it ). The Moore next state is .
Mealy outputs
So the equality also holds at .
By induction, the output alignment holds for all , hence the machines are equivalent under the conversion mapping.
Footnotes
-
Finite-state machine - Wikipedia - Describes Moore→Mealy conversion by putting destination Moore state output on Mealy transitions. ↩
-
Moore to Mealy Machine Conversion - Tutorialspoint - Provides conversion rules moving state outputs to incoming Mealy transitions and notes about equivalence. ↩
type="warning" title="Equivalence requires consistent output timing" content="When stating equivalence, ensure you compare Moore’s state-output at time with Mealy’s transition-output on the corresponding step. The conversion guarantees that alignment."
Comparison: Moore vs Mealy for this detector
| Property | Moore machine | Converted Mealy machine |
|---|---|---|
| Output location | On states () | On transitions () |
| Detection timing | One step after the completing input reaches state | On the transition that completes 1010 |
| Overlap handling | Via suffix-prefix state updates | Same next-state logic; overlap preserved |
| States needed | Includes | Can omit without losing detection behavior (when using edge outputs) |
Where does output 1 occur?
Counting only steps where the detector asserts 1 for the Moore and converted Mealy machines.
FAQ / Edge cases
Knowledge Check
In the Moore→Mealy conversion, the Mealy output on a transition is set to: