Mealy machine

In the theory of computation, a Mealy machine is a finite-state machine whose output values are determined both by its current state and the current inputs. (This is in contrast to a Moore machine, whose output values are determined solely by its current state.) A Mealy machine is a deterministic finite state transducer: for each state and input, at most one transition is possible.

History

The Mealy machine is named after George H. Mealy, who presented the concept in a 1955 paper, “A Method for Synthesizing Sequential Circuits”.[1]

Formal definition

A Mealy machine is a 6-tuple (S, S_0, \Sigma, \Lambda, T, G) consisting of the following:

In some formulations, the transition and output functions are coalesced into a single function T : S \times \Sigma \rightarrow S \times \Lambda.

The Steps

It's easier to get an idea of what to do when you know the steps involved.

Create a state transition table

This is basically a truth table that records the information of the finite state machine.

Decide how many flip flops you need, and what kind

This is usually simple, because you have to encode each state of the finite state machine using ceil( lg( k ) ) bits. Or even better, someone's already given you an FSM with that information encoded.

Choosing the kind of flip flop you want is usually an academic exercise. You'll often be told to use a certain flip flop, so you need to be able to handle the kind give.

Use the flip flop excitation table, to fill out the rest of the chart.

We'll talk about the excitation table momentarily.

Implement the circuit using a ROM.

Look at the diagram of the black box in the previous section. See the box inside the black box labelled combinational logic? We're using a ROM (read-only memory) to implement the combinational logic.

Technically, a ROM is not combinational logic. It's memory, thus, it basically has flip flops in it. However, you could use gates to implement the equivalent behavior of a ROM, using sum-of-products representation.

And that's it! Each step is quite easy. The real problem that most students have really lies in understanding what they're doing.

It's like someone told you to fold a piece of paper this way, then that way, and eventually when you're done, they say congratulations, you've made a "glurble". You're happy and proud of this paper concoction you've created! "A glurble!", you exclaim.

Then you realize you have absolutely no idea what you've made. You know the steps, but you don't know why it matters.

For now, the quickest way to learn this is to follow the steps, understand how they work, and then try to get the big picture a little later

Comparison

1. Mealy machine tend to have fewer states:

2. Moore machine are safer to use:

3. Mealy machine react faster to inputs:

Diagram

The state diagram for a Mealy machine associates an output value with each transition edge (in contrast to the state diagram for a Moore machine, which associates an output value with each state).

When the input and output alphabet are both Σ, one can also associate to a Mealy Automata an Helix directed graph.[2] (S × Σ, (x, i) → (T(x, i), G(x, i))) This graph has as vertices the couples of state and letters, every nodes are of out-degree one, and the successor of (x, i) is the next state of the automata and the letter that the automata output when it is instate x and it reads letter i. This graph is a union of disjoint cycles iff the automaton is bireversible.

Examples

Simple

State diagram for a simple Mealy machine with one input and one output.

A simple Mealy machine has one input and one output. Each transition edge is labeled with the value of the input (shown in red) and the value of the output (shown in blue). The machine starts in state Si. (In this example, the output is the exclusive-or of the two most-recent input values; thus, the machine implements an edge detector, outputting a one every time the input flips and a zero otherwise.)

Complex

More complex Mealy machines can have multiple inputs as well as multiple outputs.

Applications

Mealy machines provide a rudimentary mathematical model for cipher machines. Considering the input and output alphabet the Latin alphabet, for example, then a Mealy machine can be designed that given a string of letters (a sequence of inputs) can process it into a ciphered string (a sequence of outputs). However, although one could use a Mealy model to describe the Enigma, the state diagram would be too complex to provide feasible means of designing complex ciphering machines.


Moore/Mealy machines, are DFAs that have also output at any tick of the clock. Modern CPUs, computers, cell phones, digital clocks and basic electronic devices/machines have some kind of finite state machine to control it.


Simple software systems, particularly ones that can be represented using regular expressions, can be modelled as Finite State Machines. There are many of such simple systems, such as vending machines or basic electronics.

By finding the intersection of two Finite state machines, one can design in a very simple manner concurrent systems that exchange messages for instance. For example, a traffic light is a system that consists of multiple subsystems, such as the different traffic lights, that work concurrently.


Some examples of applications:

-number classification

-watch with timer

-vending machine

-traffic light

-bar code scanner

-gas pumps

Summary

Implementing a Moore or Mealy machine is not that hard, especially if you don't intend to minimize the circuit (which we don't).

However, it does take practice to be able to do it reasonably fast, and is difficult to understand conceptually, at least, at first. You should trace out a few steps just to convince yourself of how it behaves. There is a subtle difference in the behavior of the implementation of a Mealy and Moore machine. Tracing out a few steps can show the differences more clearly.

Usually, it's harder to understand why the circuit does the right thing (i.e., implements the FSM) than it is to know how to build it. Certainly, you should devote time to both understanding why this technique works, as well as mastering the technique.

See also

Footnotes

  1. Mealy, George H. (September 1955). "A Method for Synthesizing Sequential Circuits". Bell System Technical Journal 34: 1045–1079. doi:10.1002/j.1538-7305.1955.tb03788.x.
  2. Akhavi et al (2012)

References