ICS-E5010 Computer-Aided Verification and Synthesis, Spring 2016
Stavros Tripakis
Homework 1: State machines, automata, transition systems
Assigned: January 13, 2016
Due: January 21, 2016
Total: 100 points.
1. (20 points)
(a) Model a modulo-4 counter as a state machine. The counter has a single binary input,
reset, which resets it to 0. That is, when reset is 1, the counter is reset to 0, and as long
as reset is 0, the counter keeps counting. Is the counter a finite-state machine? Is it a
Mealy or a Moore machine?
Solution
The machine is finite-state: it has four states, 0, 1, 2, 3. It is a Moore machine: the output
is the count, equal to the state number. It has one input, the reset signal, denoted r.
r
r
r
0
r
1
r
2
r
3
true
(b) Model the same counter in Lustre. You can use the if c then e1 else e2 expression of
Lustre which results in e1 when c is true and e2 otherwise.
Solution
node CounterMod4 (R : bool) returns (C : int);
let
C = 0 -> if (R or (pre C)=3) then 0 else (1 + pre C);
tel
2. (20 points)
Consider the following digital circuit:
1
where r1 and r2 are registers (flip-flops) and the rest are logical gates. The inputs-outputs
go from left to right for the combinational part, and from right to left for the registers. For
instance, x is the input to the machine, y is the output, and the top XOR gate has two inputs,
x and the output of r2 .
Draw the finite-state machine corresponding to this circuit. Is it a Moore or a Mealy machine?
Solution
The machine (not drawn) is a Moore machine. We can tell by following the wire of the output
y to its source, which is register r2 . Therefore, the output y is equal to the state r2 , and thus
does not depend on the input x.
3. (30 points)
(a) Is a Moore machine a special case of a Mealy machine? In what sense?
Solution
Yes, a Moore machine is a special case of a Mealy machine, in the sense that a Moore
output function which has signature λ0 : S → O is a special case of a Mealy output
function which has signature λ : S × I → O. By “special case” we mean that given λ0
we can define λ as follows:
λ(s, i) = λ0 (s), for all i ∈ I.
In that sense, every Moore machine can be translated to a Mealy machine whose output
function ignores the input i and computes the output only based on the state s.
(b) Can we translate a Mealy machine to an “equivalent” Moore machine?
If the answer is “yes”, give a simple example to explain your answer. That is, draw a
simple Mealy machine (2 states should be enough) and translate it into a Moore machine. Also explain what “equivalent” means exactly (even better, provide a formal
translation).
If the answer is “no”, explain why not.
Solution
2
The translation Mealy to Moore is possible, although the resulting Moore machine is
not strictly equivalent to the original Mealy machine. But it is almost equivalent in the
sense that, for a given sequence of inputs, the resulting Moore machine produces the
same sequence of outputs as the original Mealy machine but delayed by one cycle. (You
may want to see the example that follows first, before reading the formal translation
below.)
To achieve this, the idea is to encode outputs into the state of the Moore machine. That
is, if M = (I, O, S, s0 , δ, λ) is the original Mealy machine, then the resulting Moore
machine will be:
M 0 = (I, O ∪ {⊥}, S × (O ∪ {⊥}), (s0 , ⊥), δ 0 , λ0 )
where ⊥ is a new output symbol, used for “undefined” output. The initial state of the
Moore machine is (s0 , ⊥), meaning the initial output is undefined.
The output function λ0 of the Moore machine simply returns the second component of
the (state,output) pair:
λ0 ((s, x)) = x, for any s ∈ S, x ∈ O ∪ {⊥}.
The transition function δ 0 of the Moore machine is defined as follows:
δ 0 ((s, x), i) = (δ(s, i), λ(s, i)), for any s ∈ S, x ∈ O ∪ {⊥}, i ∈ I.
This means that the Moore machine transitions to the same state s0 = δ(s, i) as the
original Mealy machine, but it also remembers the output o = λ(s, i) that the Mealy
machine would produce. So the resulting state is the pair (s0 , o).
We illustrate the translation from Mealy to Moore with the following example. Given
the Mealy machine with inputs {a, b}, outputs {0, 1}, and states {s0 , s1 }:
a/0
a/1
b/1
s0
s1
b/1
we generate the Moore machine:
3
a
a
(s0 , ⊥)
⊥
b
(s0 , 0)
0
b
a
b
a
(s1 , 1)
1
(s0 , 1)
b
1
4. (30 points)
Can we translate a Kripke structure to an “equivalent” LTS (labeled transition system)? (and
what does equivalent mean?) And vice-versa?
If the answer is “yes”, give a simple example to explain your answer.
Solution
The answers here follow the same principles as in the translations between Mealy and Moore
machines. Kripke structures can be seen as Moore machines, where the outputs are sets of
atomic propositions. LTSs can be seen as Mealy machines where the outputs are the labels
on the transitions. In both cases, the machines have no inputs (i.e., a single input symbol).
5. Install the model-checker Spin and play with it: http://spinroot.com
6. Install the model-checker NuXMV and play with it: https://es-static.fbk.eu/
tools/nuxmv/
We will use both Spin and NuXMV in subsequent homeworks, it is therefore a good idea to
start getting familiar with these tools as early as possible.
4
© Copyright 2026 Paperzz