1. Gyanastra
  2. Theory of Computation
  3. Moore and Mealy Machines
  4. Formal Definition of Moore and Mealy Machines
Free lesson, no account needed 5 min read 8 practice questions after it
Asked in past papers1 time
  • GATE CSE2006

Theory of Computation · Moore and Mealy Machines

Formal Definition of Moore and Mealy Machines

Overview

Finite automata with output extend the DFA/NFA model, which only accepts or rejects, by printing a symbol while processing input. The two such machines, the Moore machine and the Mealy machine, share the same 6-tuple structure and differ only in their output function λ\lambda.

Key concepts

  • Finite automaton with output: a machine that takes an input and, while processing it, keeps writing an output. Ordinary DFA and NFA have no output — they only accept or reject.
  • Moore machine: a finite automaton with output whose output function is λ:Q→Δ\lambda : Q \to \Delta, so an output is associated with every state; the output depends only on the state, not on the input.
  • Mealy machine: a finite automaton with output whose output function is λ:Q×Σ→Δ\lambda : Q \times \Sigma \to \Delta, so the output is associated with (state, input) pairs.
  • Common 6-tuple: M=(Q,Σ,δ,q0,Δ,λ)M = (Q, \Sigma, \delta, q_0, \Delta, \lambda) represents both machines.
    • QQ — finite set of states (e.g. q0,q1,…q_0, q_1, \dots)
    • Σ\Sigma — input alphabet (same meaning as in ordinary finite automata)
    • δ\delta — transition function
    • q0q_0 — initial state
    • Δ\Delta — output alphabet
    • λ\lambda — output function
  • Output alphabet Δ\Delta: the set of symbols the automaton is allowed to print as output.
  • Determinism: transitions are determined completely by (state, input), so both the Moore machine and the Mealy machine are deterministic. They should not be called DFAs, but both are deterministic machines.
  • The only difference between a Moore machine and a Mealy machine is the λ\lambda function.

How it works

  1. The machine reads an input string over Σ\Sigma, starting in the initial state q0q_0.
  2. The transition function δ:Q×Σ→Q\delta : Q \times \Sigma \to Q gives the next state from the current state and the input symbol — exactly the same behaviour as a DFA.
  3. The output function λ\lambda determines what is printed:
    • In a Moore machine, λ:Q→Δ\lambda : Q \to \Delta: each state carries a fixed printed symbol, so the output depends only on the state.
    • In a Mealy machine, λ:Q×Σ→Δ\lambda : Q \times \Sigma \to \Delta: for a given state and a given input there is an output, so the output depends on the state and the input.
Figure. Each state carries its output. q0 prints 1 and q1 prints 0, so the printed symbol is fixed by the state alone.

Formulas

  • M=(Q,Σ,δ,q0,Δ,λ)M = (Q, \Sigma, \delta, q_0, \Delta, \lambda) — common 6-tuple for both Moore and Mealy machines; QQ = finite set of states, Σ\Sigma = input alphabet, δ\delta = transition function, q0q_0 = initial state, Δ\Delta = output alphabet, λ\lambda = output function.
  • δ:Q×Σ→Q\delta : Q \times \Sigma \to Q — transition function: (current state, input symbol) → next state; same for both machines.
  • Moore machine: λ:Q→Δ\lambda : Q \to \Delta — output function maps each state to an output symbol.
  • Mealy machine: λ:Q×Σ→Δ\lambda : Q \times \Sigma \to \Delta — output function maps (state, input symbol) to an output symbol.

Worked examples

Moore machine with outputs attached to states:

  • State q0q_0 → output 1
  • State q1q_1 → output 0

Whenever the machine is in q0q_0 it prints 1, and whenever it is in q1q_1 it prints 0; the printed symbol is fixed by the state alone.

Comparison

AspectMoore machineMealy machine
Output function λ\lambdaλ:Q→Δ\lambda : Q \to \Deltaλ:Q×Σ→Δ\lambda : Q \times \Sigma \to \Delta
Output depends onOnly the current stateCurrent state and current input
Difference between the two machines—Only the λ\lambda function differs

Revision summary

  • DFA and NFA have no output; Moore and Mealy machines are finite automata with output.
  • Both machines use the same 6-tuple (Q,Σ,δ,q0,Δ,λ)(Q, \Sigma, \delta, q_0, \Delta, \lambda).
  • δ:Q×Σ→Q\delta : Q \times \Sigma \to Q is identical in both and makes both machines deterministic.
  • Both are deterministic, but they should not be called DFAs.
  • The only difference between Moore and Mealy is λ\lambda.
  • Moore: output attached to states (λ:Q→Δ\lambda : Q \to \Delta); Mealy: output attached to (state, input) pairs (λ:Q×Σ→Δ\lambda : Q \times \Sigma \to \Delta).
  • Δ\Delta is the output alphabet — the set of symbols the machine can print.

Previous-year exam insights

  • A Moore machine prints its output for the initial state q0 before any input symbol is read, so an input string of length n produces an output string of length n+1; a Mealy machine produces output only on transitions, so length n input gives length n output.
    Asked inGATE 2006
  • Moore and Mealy machines are equivalent in expressive power: every Moore machine can be converted to an equivalent Mealy machine and vice versa (a Moore output on a state is shifted onto all incoming transitions; a Mealy output on a transition is placed on the destination state, with the initial state's output handled separately).
  • In a Moore machine the output is a function of the present state only, so it is stable for the whole duration of the state; in a Mealy machine the output can change within a state as soon as the input changes, so Mealy machines typically need fewer states but can produce glitches.
  • The transition function of a Moore/Mealy machine is total (defined for every state-input pair), so the machine never halts or blocks; unlike a DFA there is no set of final/accepting states — the machine's purpose is to produce an output sequence, not to accept.
  • For a Moore machine the output sequence for input w = a1a2...an is λ(q0) λ(δ(q0,a1)) λ(δ(δ(q0,a1),a2)) ...;
    for a Mealy machine it is λ(q0,a1) λ(q1,a2) ... where qi is the state reached after i symbols.
  • When drawing state diagrams: Moore machines label the output inside/next to the state circle, Mealy machines label the output on the transition arrow together with the input symbol (input/output).
Pages 1–2 of 2