Volume 10 Beginner 5 sub-modules ~25 min read

State Minimisation and Equivalence

Machines designed from a story often have states that secretly do the same job. This volume shows how to find them and merge them - by splitting groups step by step, and by filling in a table of pairs. Both methods are shown in full, on machines that shrink to almost half their size, followed by exam-style problems.

You will learn
  • Why fewer states matter - and when they do not
  • What makes two states equivalent, and how to prove they are not
  • The partition method, step by step
  • The implication table, step by step
  • How to solve exam-style minimisation problems
You need

10.1 Why fewer states matter

Machines designed from a story often contain states that do exactly the same job. Merging them gives a smaller machine that behaves identically.

Where extra states come from

When you design from a word problem, it is natural to make a new state for every situation the story mentions. But two situations that sound different may lead to exactly the same future: the same outputs now, and the same behaviour for every input that follows. Such states are duplicates. Finding them and merging them is called state minimisation.

Here is a machine with seven states, one input x and one Moore output z. It was written without any thought for size:

State Next if x = 0 Next if x = 1 z
A E D 0
B E G 0
C C B 1
D F D 0
E C E 0
F C G 1
G D G 0

No two rows are identical, so there is no obvious duplicate. Yet, as you will see in sub-module 10.3, this machine behaves exactly like a machine with only four states.

Why a smaller machine is better

Remember

Merging equivalent states never changes what the machine does. From the outside - inputs in, outputs out - the smaller machine cannot be told apart from the larger one.

Unreachable states

A simpler kind of waste is an unreachable state: one that no sequence of inputs can ever reach from the reset state. Find them by starting at the reset state and following every arrow; any state you never visit can be deleted at once. Always do this first - the methods in this volume assume every state can be reached.

Common mistake

Do not minimise away a state that you kept on purpose. Sometimes a designer adds a state to make an output last one more cycle, or to give a registered output time to settle. Those states are not equivalent to their neighbours - their outputs or timing differ - so the methods here will keep them. But check before you "tidy up" a machine by hand.

Quick check

A machine with binary state codes shrinks from 6 states to 5. How many flip-flops does it save?

Show the answer

Answer: C. 2 flip-flops give only 4 codes, so both 5 and 6 states need 3 flip-flops. The flip-flop count drops only when the number of states falls to 4 or fewer. The smaller machine may still need less logic, though.

10.2 Equivalent states

Two states are equivalent if no sequence of inputs can tell them apart: from either one, every input sequence gives exactly the same outputs.

Telling states apart

Imagine the machine in a sealed box. You can press its input buttons and watch its outputs, but you cannot see which state it is in. Two states are equivalent if, whatever you press, you can never tell which of the two it started in.

Think of it like this

Think of two identical twins, and a quiz. You may ask as many questions as you like, in any order, but you only hear the answers. If every possible series of questions gets the same answers from both, then for your purposes they are the same person. If some series of questions gets different answers, you have told them apart.

The two tests

To be equivalent, two states must pass both tests:

  1. Same outputs now. In a Moore machine, the same output. In a Mealy machine, the same output for every input.
  2. Equivalent next states. For every input, the two next states must themselves be equivalent - or be the same state.

The second test refers back to equivalence itself. That is why we need a method: we cannot just look at two rows and decide. The methods in the next two sub-modules solve this circle step by step.

A sequence that tells them apart

To prove two states are not equivalent, one input sequence is enough - a sequence that makes them give different outputs. It is called a distinguishing sequence.

In the seven-state machine, take states A and B. Both have z = 0, and on x = 0 both go to E. Only x = 1 differs: A goes to D, and B goes to G. Now feed each the sequence 1, then 0:

Start After 1 After 1, 0 Outputs seen
A D F 0, 0, 1
B G D 0, 0, 0

The third output differs, so A and B are not equivalent. Each takes one input to show that its next states differ, and one more to show it in an output.

Common mistake

Do not judge equivalence by the names of the next states. In the seven-state machine, B goes to (E, G) and G goes to (D, G). The names differ - yet B and G are equivalent, because E and D turn out to be equivalent too. Only a full method can tell.

Quick check

Two states of a Moore machine have different outputs. Can they be equivalent?

Show the answer

Answer: A. Before any input at all, a Moore machine shows the output of its current state. If the outputs differ, you can tell the states apart without pressing anything, so they cannot be equivalent.

10.3 The partition method

The partition method starts with the states grouped by their outputs, then keeps splitting any group whose members lead to different groups, until nothing splits.

A partition is a split of the states into groups, where every state is in exactly one group. The method builds better and better partitions, called P0, P1, P2 and so on.

  1. P0: group by output. States with different outputs can never be equivalent, so they start in different groups.
  2. Refine. In each group, look at where every state goes on each input - not the state's name, only which group it lands in. States that land in the same groups stay together; the others split off.
  3. Repeat the refine step on the new partition.
  4. Stop when a refine step changes nothing. Each group is one state of the minimal machine.

Worked example

Apply it to the seven-state machine from sub-module 10.1.

P0 - group by z. The states with z = 0 are A, B, D, E and G. The states with z = 1 are C and F.

P0 = { A B D E G } { C F }

P1 - refine. For each state in the big group, write the group it lands in for x = 0 and x = 1. Call the groups "zero" and "one" after their output:

State x = 0 goes to x = 1 goes to Pattern
A E (zero) D (zero) zero, zero
B E (zero) G (zero) zero, zero
D F (one) D (zero) one, zero
E C (one) E (zero) one, zero
G D (zero) G (zero) zero, zero

D and E have a different pattern from A, B and G, so they split off. In the group { C F }, C goes to (C, B) and F goes to (C, G) - the same groups, so they stay together.

P1 = { A B G } { D E } { C F }

P2 - refine again, with the new groups:

State x = 0 goes to x = 1 goes to
A E, in { D E } D, in { D E }
B E, in { D E } G, in { A B G }
G D, in { D E } G, in { A B G }

A now lands in a different group on x = 1, so A splits off. The groups { D E } and { C F } still agree inside themselves.

P2 = { A } { B G } { D E } { C F }

P3 - refine once more. B and G both go to { D E } on 0 and { B G } on 1. D and E both go to { C F } on 0 and { D E } on 1. C and F both go to { C F } on 0 and { B G } on 1. Nothing splits, so P3 = P2, and we stop.

The partition rounds P0, P1 and P2 for the seven-state machine, with letters coloured by their final group P0 P1 P2 A B D E G C F A B G D E C F A B G D E C F grouped by output z D and E split off A splits off - stable
Figure 10.1 - The partition method, round by round. Each letter is coloured by the group it ends up in, so you can watch the groups separate: first by output, then D and E split off, then A. P3 would change nothing.

The minimal machine

Each group of P2 becomes one state. Name each after its members:

The minimal four-state machine: A, BG, CF and DE A z=0 DE z=0 CF z=1 BG z=0 0, 1 0 1 0 1 0 1 reset
Figure 10.2 - The minimal machine. Each state is one group from the partition, named after the states it replaces. It behaves exactly like the seven-state original.

To draw it, take any member of each group and follow its arrows. For example, B goes to E on 0 and to G on 1, so the merged state BG goes to DE on 0 and to BG on 1. Any member gives the same answer - that is exactly what the partition guarantees.

Remember

Seven states became four. With binary codes that saves a flip-flop - 3 become 2 - and the next-state logic shrinks too.

Common mistake

In each refine step, compare the groups the next states fall into, using the partition from the step before. Never compare the next states' own names, and never mix old and new groups. Update all the groups at once, at the end of the step.

Quick check

In a refine step, states P and Q are in the same group. On input 0 they go to states that are in different groups. What happens?

Show the answer

Answer: B. If one input sends P and Q into different groups, then some input sequence starting with that input can tell them apart. So they cannot be equivalent, and they must be split.

Try it in FSM StudioFSM Studio runs the partition method for you. Open this six-state machine, look at the Checks tab, and press Minimise to see which states merge.
Open FSM Studio

10.4 The implication table

The implication table checks every pair of states at once. Cross out the pairs with different outputs, write down what each remaining pair depends on, then keep crossing out until nothing changes.

The implication table is the other classic method. It works especially well by hand for Mealy machines, and it answers a slightly different question: not "what are the groups?" but "which pairs are equivalent?".

The example

A Mealy machine with six states, one input x, and one output. Each entry reads next state / output:

State x = 0 x = 1
A B / 1 A / 1
B C / 1 D / 1
C B / 0 B / 1
D E / 1 D / 1
E E / 1 F / 1
F F / 1 D / 1

The method

  1. Draw the table. One cell for every pair of states, in a staircase: rows B to F, columns A to E.
  2. Pass 0. Cross out (X) every pair whose outputs differ for some input.
  3. Fill in. In every other cell, write the pairs of next states that must also be equivalent - one pair per input. Leave out a pair of two identical states, and leave out the cell's own pair.
  4. Repeat passes. Cross out every cell that lists a pair already crossed out. Keep making passes until one pass crosses out nothing.
  5. Read off. Every cell left uncrossed is an equivalent pair.

Pass 0 and filling in

Only C has a different output (0 on x = 0), so every pair containing C is crossed out at once. The other cells list what they depend on. For example, A and B go to B and C on x = 0, and to A and D on x = 1. So the cell A-B lists "A-D, B-C":

A B C D E
B A-D, B-C
C X X
D B-E C-E X
E A-F, B-E C-E, D-F X D-F
F A-D, B-F C-F X E-F D-F

The passes

A B C D E
B X (pass 1)
C X X
D X (pass 2) X (pass 1) X
E X (pass 2) X (pass 1) X equivalent
F X (pass 2) X (pass 1) X equivalent equivalent

The result

D, E and F are all equivalent to each other, so they merge into one state. A, B and C stay alone. Six states become four:

State x = 0 x = 1
A B / 1 A / 1
B C / 1 D / 1
C B / 0 B / 1
D (was D, E, F) D / 1 D / 1

Notice what the three merged states had in common: from any of them, the machine never again reaches C, so the output can never be 0 again. The table found that without anyone having to spot it.

In plain words

A pair stays uncrossed only if nothing can ever tell its two states apart. Pairs that depend on each other in a circle - here D-E, D-F and E-F - survive, because none of them ever meets a difference.

Which method to use?

Partition method Implication table
Works on groups of states pairs of states
Best for Moore machines, and big machines Mealy machines, by hand
Size of the work grows gently with the states one cell per pair: 15 cells for 6 states, 190 for 20

Both always give the same minimal machine.

Going deeper: machines with don't-cares

Everything here assumes a completely specified machine - every next state and output is known. If some entries are don't-cares, the machine is incompletely specified, and the idea of equivalence is replaced by a weaker one called compatibility. Two states can each be compatible with a third without being compatible with each other, so the groups no longer fall out neatly. Finding the smallest machine then becomes a much harder search, and no fast method is known that always finds the best answer.

Common mistake

Stopping after one pass. In this example, pass 1 crossed four cells, and only pass 2 crossed A-D, A-E and A-F - because they depended on cells crossed in pass 1. Always keep going until a whole pass crosses out nothing.

Quick check

A cell lists the pairs P-Q and R-S. After all passes, P-Q is crossed out but R-S is not. What about the cell?

Show the answer

Answer: D. A cell's two states are equivalent only if every pair it lists is equivalent. One crossed pair is enough: some input leads the two states to P and Q, which can be told apart, so the cell's states can be told apart too.

10.5 GATE-style minimisation problems

Exam problems on minimisation test the same two ideas every time: group by output, then split by where the states go. A few patterns come up again and again.

These are practice problems in the style of written exams such as GATE, written for this course. Try each one before you open the solution.

Practice 1

How small can it get?

A Moore machine has five states. Find the minimum number of states of an equivalent machine.

State x = 0 x = 1 z
P Q R 0
Q S R 0
R Q T 0
S S R 0
T Q T 1
Show the solution

P0: by output, { P Q R S } { T }.

P1: in the big group, where does each state go? P goes to (Q, R): both in the big group. Q goes to (S, R), and S goes to (S, R): the same. R goes to (Q, T), and T is in the other group - so R splits off. P1 = { P Q S } { R } { T }.

P2: P, Q and S all go to { P Q S } on 0 and to R on 1. No split, so we stop.

The answer is 3 states: PQS, R and T.

Practice 2

Divisible by 6

A machine reads a binary number, most significant bit first, and outputs 1 when the number so far is divisible by 6. The remainder method from Volume 06 gives six states, R0 to R5. What is the minimum number of states?

Show the solution

The remainder method moves from r to (2r + b) mod 6. Write out two of the rows:

State b = 0 b = 1 z
R1 R2 R3 0
R4 R2 (8 mod 6) R3 (9 mod 6) 0
R2 R4 R5 0
R5 R4 (10 mod 6) R5 (11 mod 6) 0

R1 and R4 have identical rows, and so do R2 and R5. The partition method confirms that nothing else merges, so the minimum is 4 states: R0, {R1, R4}, {R2, R5} and R3. The same reasoning gives 3 states for divisibility by 4 and 5 states for divisibility by 12 - so never assume that the remainder machine is already minimal.

Practice 3

Detector sizes

What is the minimum number of states of a Mealy machine that detects the pattern 1101 in a bit stream, with overlapping? And of a Moore machine?

Show the solution

By the method of Volume 06, a Mealy detector has one state per proper prefix: nothing, 1, 11 and 110 - 4 states. A Moore detector adds one state for the full match - 5 states. These are already minimal: each prefix state remembers something the others do not, and a distinguishing sequence exists for every pair (for instance, the rest of the pattern).

Practice 4

Pairs that lean on each other

Find the equivalent states of this Mealy machine:

State x = 0 x = 1
A B / 0 C / 1
B A / 0 D / 1
C D / 1 A / 0
D C / 1 B / 0
Show the solution

Pass 0: A and B have outputs (0, 1); C and D have (1, 0). So every pair mixing the two sets is crossed out, leaving A-B and C-D.

  • A-B depends on its next states: on 0, B and A (itself, so ignored); on 1, C and D. So A-B lists C-D.
  • C-D depends on: on 0, D and C (itself); on 1, A and B. So C-D lists A-B.

Each depends only on the other, and neither is ever crossed out. So A ≡ B and C ≡ D, and the machine shrinks to 2 states. Pairs that support each other in a circle, with no difference anywhere, are equivalent.

Quick check

A remainder machine for divisibility by 8 (most significant bit first) has 8 states. Why can it shrink?

Show the answer

Answer: C. A number is divisible by 8 exactly when its last three bits are 000. So the machine only needs to know how many 0s the number ends with: none, one, two, or three or more. Many remainders share the same answer, so they merge. The partition method gives 4 states.

What you learned

Key words from this volume

Every word below has a plain-English entry in the glossary.

Interview corner

Interview question 1

Are these two states the same?

"How do you decide whether two states of an FSM can be merged?"

Show the solution

"Two states can be merged if they are equivalent: they give the same outputs, and for every input their next states are equivalent too. Because that definition is recursive, I use the partition method: group the states by output, then repeatedly split any group whose members transition into different groups, until no group splits. Each final group becomes one state. To prove two states are different, a single distinguishing input sequence is enough."

Interview question 2

Is minimal always best?

"Should you always use the minimal state machine?"

Show the solution

"Usually, but not blindly. Minimising never changes the behaviour, so it is safe, and it can save flip-flops and logic. But sometimes a larger machine is clearer to read, or its encoding gives registered outputs or a simpler decode. And on an FPGA with one-hot encoding, the saving may not matter. And for safety-critical machines, what matters more is what happens in illegal states - which minimisation does not address at all. That is the topic of safe FSM design."

Next, Volume 11 asks what happens when a machine lands in a state it should never be in - and how to make sure it always finds its way home.