A Comprehensive, Elite Guide to Input-Driven Finite State Transducers
In the Theory of Computation, a Mealy Machine is a finite-state machine whose output values are determined by both its current state AND the current input. This makes it fundamentally different from a Moore machine, where output is tied solely to the state.
Because the output is generated during the transition between states, Mealy machines react instantly to inputs. They generally require fewer states than Moore machines to perform the same task.
A Mealy Machine is formally defined as a 6-tuple (Q, Σ, Δ, δ, λ, q0) where:
Q × Σ → Q.Q × Σ → Δ.Designing Mealy machines is highly efficient once you grasp that the transition arrow does all the heavy lifting.
Input / Output. E.g., 1 / 0 means "When reading input 1, output 0 and take this path."q0), not the output.Below are meticulously engineered step-by-step designs of Mealy Machines. Notice how the outputs live exclusively on the transition arrows.
q0: Base state. If input is 0, output 1. If input is 1, output 0.q_wait: Waiting for first '1'. Read 0 -> Out 0. Read 1 -> Out 1 (and go to flip state).q_flip: Flip mode. Read 0 -> Out 1. Read 1 -> Out 0.1 whenever the exact sequence "10" is completed. Output 0 otherwise.q0: Start / Haven't seen '1'.q1: Just saw '1'. If we see '0' now, the sequence is complete! Transition to `q0` and output `1`.1 when "101" is completed, else 0.q0: Start state.q1: Saw '1'.q2: Saw '10'. If we see '1' from here, sequence is met! Go to `q1` (since this '1' could start a new "101") and output `1`.Next_Mod = (Current_Mod * 2 + input) % 3. Output equals the destination state's mod value.
q0: Current mod 0.q1: Current mod 1.q2: Current mod 2.q0: Represents output state 0.q1: Represents output state 1.A if the string ends in "aa", B if it ends in "bb", and C otherwise.q0: Start state (Neither).qa: Last char was 'a'. If 'a' read -> output A. If 'b' read -> output C.qb: Last char was 'b'. If 'b' read -> output B. If 'a' read -> output C.qE: Received Even number of 1s. If '1' is received -> becomes Odd -> Output 1 to make it Even again.qO: Received Odd number of 1s. If '0' is received -> remains Odd -> Output 1 to make it Even.q_carry_1: Start state. Add 1 to input. Input 0 -> Out 1, Carry becomes 0. Input 1 -> Out 0, Carry remains 1.q_carry_0: No carry. Pass inputs unchanged (0/0, 1/1).1 if the current symbol matches the immediately preceding symbol (e.g., "00" or "11"). Output 0 otherwise.qS: Start state. Output 0 for any first symbol.q0: Last symbol was '0'. Read 0 -> Out 1. Read 1 -> Out 0.q1: Last symbol was '1'. Read 1 -> Out 1. Read 0 -> Out 0.1 whenever the sequence "010" is completed in the input stream. Overlapping is allowed.q0: Start state.q1: Saw '0'.q2: Saw '01'. If '0' is read next -> Match! Output 1. The new string ends in '0', so transition back to `q1`.1 when "aba" is completed. Alphabet {a, b}.q0: Start state.qa: Saw 'a'.qab: Saw 'ab'. If 'a' is read -> Match! Output 1 and transition to `qa` (overlapping 'a').E if the total number of '1's read so far is Even, and O if it is Odd. Alphabet {0,1}.qE: Currently Even. Read 0 -> Out E. Read 1 -> Out O (and transition to qO).qO: Currently Odd. Read 0 -> Out O. Read 1 -> Out E (and transition to qE).q0: Mod 0. Read 'b' -> Out 0. Read 'a' -> Out 1 (transition to q1).q1: Mod 1. Read 'b' -> Out 1. Read 'a' -> Out 2 (transition to q2).q2: Mod 2. Read 'b' -> Out 2. Read 'a' -> Out 0 (transition to q0).1 when "1011" is completely detected. Overlapping allowed.q0: Start.q1: Saw '1'.q2: Saw '10'.q3: Saw '101'. Read '1' -> Output 1 (Match!). Next state `q1` because the '1' can overlap.1 if the current bit matches the very first bit of the string. Output 0 otherwise.qS: Start. Records first bit. If 0 -> Out 1, go to q0. If 1 -> Out 1, go to q1.q0: First bit was 0. Read 0 -> 1. Read 1 -> 0.q1: First bit was 1. Read 1 -> 1. Read 0 -> 0.0.q0: Previous bit was 0 (also the Start State). Input 0 -> Out 0. Input 1 -> Out 0 (transition to q1).q1: Previous bit was 1. Input 1 -> Out 1. Input 0 -> Out 1 (transition to q0).1 if the last two characters read are "ab" or "ba" (Alternating ends). Output 0 otherwise.qS: Start state.qa: Last char 'a'. Read 'b' -> Out 1 (transition to qb). Read 'a' -> Out 0.qb: Last char 'b'. Read 'a' -> Out 1 (transition to qa). Read 'b' -> Out 0.1 exactly once when the input transitions from 0 to 1. Output 0 at all other times.q0: Currently reading 0s. Read 0 -> Out 0. Read 1 -> Out 1 (Rising Edge! transition to q1).q1: Currently reading 1s. Read 1 -> Out 0. Read 0 -> Out 0 (Falling Edge, transition back to q0).1 only after the string "111" has been encountered. Once "111" is seen, output 1 for all subsequent inputs indefinitely.q0: Start / Reset on 0. Read 0 -> Out 0. Read 1 -> Out 0 (goto q1).q1: Saw one 1. Read 0 -> Out 0. Read 1 -> Out 0 (goto q2).q2: Saw two 1s. Read 0 -> Out 0. Read 1 -> Out 1 (Match! goto q3).q3: Sink State. Read 0 or 1 -> Out 1.