ArticleslgStudy

computer science

Mealy machine

Mealy machine is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Mealy machine rather than just read about it. In short: 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.

Mealy machine — main illustration
Mealy machine — illustration

Key takeaways

  • Mealy machine belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Mealy machine to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Mealy machine from memory before moving on to harder problems.

Reference excerpt

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".

Formal definition A Mealy machine is a 6-tuple ( S , S 0 , Σ , Λ , T , G ) {\displaystyle (S,S_{0},\Sigma ,\Lambda ,T,G)} consisting of the following:

a finite set of states S {\displaystyle S}

a start state (also called initial state) S 0 {\displaystyle S_{0}} which is an element of S {\displaystyle S}

a finite set called the input alphabet Σ {\displaystyle \Sigma }

a finite set called the output alphabet Λ {\displaystyle \Lambda }

a transition function T : S × Σ → S {\displaystyle T:S\times \Sigma \rightarrow S} mapping pairs of a state and an input symbol to the corresponding next state. an output function G : S × Σ → Λ ∗ {\displaystyle G:S\times \Sigma \rightarrow \Lambda ^{*}} mapping pairs of a state and an input symbol to the corresponding output symbol. In some formulations, the transition and output functions are coalesced into a single function T : S × Σ → S × Λ ∗ {\displaystyle T:S\times \Sigma \rightarrow S\times \Lambda ^{*}} . "Evolution across time" is realized in this abstraction by having the state machine consult the time-changing input symbol at discrete "timer ticks" t 0 , t 1 , t 2 , . . . {\displaystyle t_{0},t_{1},t_{2},...} and react according to its internal configuration at those idealized instants, or else having the state machine wait for a next input symbol (as on a FIFO) and react whenever it arrives.

Comparation of Mealy and Moore machines Mealy machines tend to have fewer states: Different outputs on arcs (n2) rather than states (n). When implemented as electronic circuits (rather than as mathematical abstractions or code): Moore machines are safer to use than Mealy machines: Outputs change at the clock edge (always one cycle later). In Mealy machines, input change can cause output change as soon as logic is done — a big problem when two machines are interconnected – asynchronous feedback may occur if one isn't careful. Mealy machines react faster to inputs: React in the same cycle—they don't need to wait for the clock. In Moore machines, more logic may be necessary to decode state into outputs—more gate delays after clock edge.

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 a Helix directed graph (S × Σ, (x, i) → (T(x, i), G(x, i))). This graph has as vertices the couples of state and letters, each node is 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 if the automaton is bireversible.

Examples

Simple

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 1 every time the input flips and a 0 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 a Mealy model could be used 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 modeled as finite state machines. There are many 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.

See also Synchronous circuit Moore machine Algorithmic state machine Richards controller

Footnotes

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Mealy machine

Start with the simplest possible case. Write down what Mealy machine claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Mealy machine before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Mealy machine ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Mealy machine

In research
Mealy machine appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Mealy machine in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Mealy machine is common in secondary-school and first-year university syllabi. It links to neighbouring topics Finite-state machines, Models of computation, so understanding it makes those chapters shorter.
In everyday life
Look for Mealy machine outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Mealy machine in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Mealy machine means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Mealy machine out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Mealy machine in simple terms?

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.

Why does Mealy machine matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Mealy machine?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Mealy machine.

Tags

  • Finite-state machines
  • Models of computation

Keep exploring