Design and Equivalence of Mealy/Moore Machines Detecting the Overlapping Sequence 1010

Design and Equivalence of Mealy/Moore Machines Detecting the Overlapping Sequence 1010

Verified Sources
Nov 1, 2026

We want a sequential circuit that reads a binary stream x∈{0,1}\*x \in \{0,1\}^\* and outputs 11 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:

  1. a Moore machine (output depends only on state) for 1010 with overlapping,
  2. a Mealy machine directly,
  3. 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

  1. 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. ↩

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 P=1010P = 1010. Its proper prefixes are:

  • ϵ\epsilon (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

  1. 1
    Step 1

    Let Moore states be S0,S1,S2,S3,S4S_0,S_1,S_2,S_3,S_4 where SkS_k means the last kk bits equal the length-kk prefix of 1010 (so S4S_4 means the last 4 bits are exactly 1010).

  2. 2
    Step 2

    Set output Z=1Z=1 only on state S4S_4; set Z=0Z=0 on S0S_0–S3S_3.

  3. 3
    Step 3

    For each state SkS_k and input bit b∈{0,1}b\in\{0,1\}, form the new string suffix candidate by appending bb to the currently matched prefix, then choose the longest suffix that is a prefix of 1010.

  4. 4
    Step 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., 0 can leave you ready for prefix 1 only if it completes it; this follows automatically from the suffix-prefix rule).

  5. 5
    Step 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 Z(s)Z(s) (only depends on current state). States:

  • S0S_0: matched length 0 (no useful suffix),
  • S1S_1: matched 1,
  • S2S_2: matched 10,
  • S3S_3: matched 101,
  • S4S_4: matched 1010 (detection state).

Moore outputs:

  • Z(S4)=1Z(S_4)=1,
  • Z(S0)=Z(S1)=Z(S2)=Z(S3)=0Z(S_0)=Z(S_1)=Z(S_2)=Z(S_3)=0.

Now compute transitions by longest suffix that is also a prefix of 1010.

Present stateInput 00 -> NextInput 11 -> Next
S0S_0S0S_0S1S_1
S1S_1 (1)S2S_2S1S_1
S2S_2 (10)S0S_0S3S_3
S3S_3 (101)S4S_4S1S_1
S4S_4 (1010)S2S_2S1S_1

Reasoning highlights (overlap):

  • From S3S_3 on input 0, we complete 1010, so go to S4S_4.
  • From S4S_4 on input 0, the last two bits are 10, so we land in $S_2`.
  • From S4S_4 on input 1, the last bit is 1, so we land in S1S_1.

Mermaid diagram (Moore)

Mealy machine for detecting overlapping 1010 (output on transitions)

For a Mealy machine, the output YY is associated with the transition labeled by the input.

We can obtain a compact Mealy detector by emitting Y=1Y=1 on the transition that completes 1010.

Define Mealy states to be the same matched-prefix states S0S_0–S3S_3 (no need to keep an “S4S_4 state” because detection is produced on the edge). However, we must still transition correctly after detection for overlap.

Let Y(s,b)=1Y(s,b)=1 iff from state $S_3we read input0(because that edge completes1010`).

Mealy transition/output table

Present stateInput 00 -> (Next, Output)Input 11 -> (Next, Output)
S0S_0(S0,0)(S_0,0)(S1,0)(S_1,0)
S1S_1(S2,0)(S_2,0)(S1,0)(S_1,0)
S2S_2(S0,0)(S_0,0)(S3,0)(S_3,0)
S3S_3(S2,1)(S_2,1)(S1,0)(S_1,0)

Notes:

  • From S3‘oninput‘0‘,wedetect‘1010‘,andafterconsumingthat‘0‘,thelongestsuffixthat′salsoaprefixis‘10‘,i.e.,nextstateS_3` on input `0`, we detect `1010`, and after consuming that `0`, the longest suffix that's also a prefix is `10`, i.e., next state 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 sxrightarrowbs′s \\xrightarrow{b} s', label the Mealy transition with output Z(s′)Z(s').

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

  1. Finite-state machine - Wikipedia - Describes Moore→Mealy conversion by putting destination Moore state output on Mealy transitions. ↩ ↩2

  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)

  1. 1
    Step 1

    Keep the same underlying state graph structure and next-state function δ(s,b)\delta(s,b).

  2. 2
    Step 2

    For each edge s→bs′s \xrightarrow{b} s', create a Mealy edge from the corresponding state.

  3. 3
    Step 3

    Set the Mealy output on s→bs′s \xrightarrow{b} s' to be Y=Z(s′)Y=Z(s').

  4. 4
    Step 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 Y=Z(textnextstate)Y = Z(\\text{next state}), only transitions that enter S4S_4 produce output 11.

From the Moore transition table:

  • The only way to enter S4S_4 is from S3S_3 on input 0.
  • Therefore, the converted Mealy machine labels exactly that transition with output 11.

If we now drop S4S_4 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:

  • Y(S3,0)=Z(S4)=1Y(S_3,0)=Z(S_4)=1,
  • all other Y(s,b)=0Y(s,b)=0.

This matches the Mealy table:

  • From S3S_3 on 0, go to S2S_2 with output $1`,
  • Otherwise output 00.

Proof of equivalence (Moore → Mealy conversion correctness)

We prove that the Moore machine MtextMooreM_{\\text{Moore}} and its converted Mealy machine MtextMealyM_{\\text{Mealy}} produce the same output stream for every input sequence.

Formal definitions (output interpretation)

Let:

  • Moore machine output is Z(st)Z(s_t) where sts_t is the state during the tt-th input step.
  • Mealy machine output is labeled on transitions: if the machine is in sts_t and reads input btb_t, it outputs Yt=Y(st,bt)Y_t = Y(s_t,b_t) on the transition to st+1s_{t+1}.

Using the conversion rule, we set:

Y(s,b)=Z(delta(s,b)).Y(s,b) = Z(\\delta(s,b)).

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 b0b1cdotsbn−1b_0 b_1 \\cdots b_{n-1}, the Mealy output on transition tt equals the Moore output of the destination state at time t+1t+1:

Yt=Z(st+1).Y_t = Z(s_{t+1}).

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 (t=0t=0):
Moore: after applying input b0b_0, the next state is s1=delta(s0,b0)s_1 = \\delta(s_0,b_0), and the Moore output associated with being in s1s_1 is Z(s1)Z(s_1).
Mealy: by construction, the output on the transition reading b0b_0 is

Y0=Y(s0,b0)=Z(delta(s0,b0))=Z(s1).Y_0 = Y(s_0,b_0) = Z(\\delta(s_0,b_0)) = Z(s_1).

So the equality holds.

Inductive step: Assume for some tge0t \\ge 0 that

Yt=Z(st+1).Y_t = Z(s_{t+1}).

Consider transition at time t+1t+1. In both machines, the state before reading input bt+1b_{t+1} is the same reachable state (call it st+1s_{t+1}). The Moore next state is st+2=delta(st+1,bt+1)s_{t+2}=\\delta(s_{t+1},b_{t+1}).
Mealy outputs

Yt+1=Y(st+1,bt+1)=Z(delta(st+1,bt+1))=Z(st+2).Y_{t+1} = Y(s_{t+1},b_{t+1}) = Z(\\delta(s_{t+1},b_{t+1})) = Z(s_{t+2}).

So the equality also holds at t+1t+1.

By induction, the output alignment holds for all tt, hence the machines are equivalent under the conversion mapping. 

Footnotes

  1. 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. ↩

type="warning" title="Equivalence requires consistent output timing" content="When stating equivalence, ensure you compare Moore’s state-output at time tt with Mealy’s transition-output on the corresponding step. The conversion Y=Z(next state)Y=Z(next\ state) guarantees that alignment."

Comparison: Moore vs Mealy for this detector

PropertyMoore machineConverted Mealy machine
Output locationOn states (Z(s)Z(s))On transitions (Y(s,b)Y(s,b))
Detection timingOne step after the completing input reaches state S4S_4On the transition that completes 1010
Overlap handlingVia suffix-prefix state updatesSame next-state logic; overlap preserved
States neededIncludes S4S_4Can omit S4S_4 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

Question 1 of 4
Q1Single choice

In the Moore→Mealy conversion, the Mealy output on a transition s→bs′s \xrightarrow{b} s' is set to: