CSci 555: Functional Programming
Mealy Machine Simulator Project

H. Conrad Cunningham

IN WORK 6 March 2019

Copyright (C) 2016, 2017, 2018, 2019, H. Conrad Cunningham
Professor of Computer and Information Science
University of Mississippi
211 Weir Hall
P.O. Box 1848
University, MS 38677
(662)

Browser Advisory: The HTML version of this textbook requires a browser that supports the display of MathML. A good choice as of March 2019 is a recent version of Firefox from Mozilla.

TODO:

Mealy Machine Simulator Project

In this project, you are asked to design and implement a Scala program to represent Mealy Machines and to simulate their execution.

This kind of machine is a useful abstraction for simple controllers that listen for input events and respond by generating output events. For example in an automobile application, the input might be an event such as “fuel level low” and the output might be command to “display low-fuel warning message”.

In the theory of computation, a Mealy Machine is a finite-state automaton whose output values are determined both by its current state and the current input. It is a deterministic finite state transducer such that, for each state and input, at most one transition is possible.

Appendix A of the Linz textbook [Linz 2017] defines a Mealy Machine mathematically by a tuple

M=(Q,Σ,Γ,δ,θ,q0)M = (Q,\Sigma,\Gamma,\delta,\theta,q_{0})

where

QQ is a finite set of internal states
Σ\Sigma is the input alphabet (a finite set of values)
Γ\Gamma is the output alphabet (a finite set of values)
δ:Q×ΣQ\delta: Q \times \Sigma \longrightarrow Q is the transition function
θ:Q×ΣΓ\theta: Q \times \Sigma \longrightarrow \Gamma is the output function
q0q_{0} is the initial state of MM (an element of QQ)

In an alternative formulation, the transition and output functions can be combined into a single function:

δ:Q×ΣQ×Γ\delta: Q \times \Sigma \longrightarrow Q \times \Gamma

We often find it useful to picture a finite state machine as a transition graph where the states are mapped to vertices and the transition function represented by directed edges between vertices labelled with the input and output symbols.

Exercises

TODO: Decide whether these functions are appropriate for the intended Scala structure. In particular should these be methods on a class rather than just functions. Should the constructor be a class constructor? etc.

  1. Specify, design, and implement a general representation for a Mealy Machine as a set of Scala definitions implementing an abstract data type. It should hide the representation of the machine and should have, at least, the following public operations.

  2. Given the above implementation for a Mealy Machine, design and implement a separate Haskell module that simulates the execution of a Mealy Machine. It should have, at least, the following new public operations.

    Note: It is possible to use a Labelled Digraph ADT module in the implementation of the Mealy Machine.

  3. Implement a Scala abstract data type that uses a different representation for the Mealy Machine. Make sure the simulator module still works correctly.

Acknowledgements

I created the original version of this project in Spring 2016 as a programming exercise in the first Scala-based offering of CSci 555, Functional Programming. I adapted and revised this project for possible use in the Haskell-based CSci 556 course in Spring 2017 but did not assign it. In 2018, I revised the project description and merged it into new Chapter 23, Data Abstraction Revisited, in the textbook Exploring Languages with Interpreters and Functional Programming.

In Spring 2019, I separated the Mealy Machine Simulator Project back into a separate document and modified it for use in a Scala-based course.

I maintain this chapter as text in Pandoc’s dialect of Markdown using embedded LaTeX markup for the mathematical formulas and then translate the document to HTML, PDF, and other forms as needed.

References

[Linz 2017]:
Peter Linz. Formal Languages and Automata, 6th Edition, Jones & Bartlett, 2017.

Terms and Concepts

Mealy Machine, simulator, finite-state automaton (machine), deterministic finite state transducer, state, transition, transition graph.