Top Banner
State Machine Design 1
54

State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

May 13, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

State Machine Design

1

Page 2: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Topics

• Finite State Machine Model • Capabilities & Limitations of FSMs • State Equivalence and Minimization • Simplification of Incompletely Specified

Machines

2

Page 3: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Finite State Machine Model

• Deterministic machines: Next state S(t + 1) determined uniquely by the present state S(t) and the present input x(t).

S(t + 1) = δ {S(t), x(t)} Where δ is called the state transition function. Output z(t) can be determined in two ways: z(t) = λ {S(t), x(t)} or z(t) = λ {S(t)} 3

Page 4: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Synchronous Sequential Machine

A synchronous sequential machine M is a quintuple M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty sets of

inputs, output, and states, respectively. δ: I x S → S is the start transition function λ is the output function such that λ: I x S → O for Mealy machines λ: S → O for Moore machines

4

Page 5: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Input/Output Transformations

S = {A, B, C, D} I = {0, 1} O = {0, 1} Say initial state is A and input sequence is 110 Output sequence = 001 i.e., m/c transforms input sequence 110 to 001

5

Page 6: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Input/Output Transformations

• Any problem that can be expressed as transformation of sequences can be solved by an FSM

• Also, FSM can be used to determine whether a given input sequence is a member of some pre-specified set of sequences

6

Page 7: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Problem • Design an FSM that generates a 1 whenever it

detect a pattern “1101”

7

Page 8: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

X-successor

8

1-successor of A is __________ 111-successor of A is ________ If M is known to be initially in either B or C, the

10-successor will be _________________

Page 9: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Definitions

• If an input sequence X takes a machine from Sa to Sb, then Sb is the said to be the X-successor of Sa

• A state is called a terminal state, if either the state is a – sink state - has no outgoing arcs to other states – source state – has no incoming arcs from other

states

9

Page 10: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Strongly connected machine

• If for every pair of states Sa and Sb of a machine M there exists an input sequence which takes M from Sa to Sb, then M is said to be strongly connected.

10

Page 11: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

State Equivalence and Minimization

• Redundant state – A state whose function can be achieved by

another state

• Redundant states cost hardware – Number of bits used is prop. to states.

11

Page 12: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

k-equivalence

• Two states Sa and Sb of machine M are distinguishable if and only if there exists at least one finite input sequence for which M produces different output sequences on whether Sa or Sb is the initial state.

• The sequence which distinguishes these states is called a distinguishing sequence of the pair (Sa ,Sb)

• If there exists for pair (Sa ,Sb) a distinguishing sequence of length k, the states are said to be k-distinguishable

12

Page 13: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Example: Machine M1

13

Q) Is the pair (A, B), 1-distinguishable?______ Q) Pair (A, E) is ____- distinguishable and the

dist., sequence is _______

Page 14: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

• States that are not k-distinguishable are said to be k-equivalent – For example, (A, E) of M1 are 2-equivalent

• States which are k-equivalent are also r-equivalent for all r < k

• States that are k-equivalent for all k are said to be equivalent

14

Page 15: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Definition

• States Sa and Sb of machine M are said to be equivalent if and only if, for every possible input sequence, the same output sequence will be produced regardless of whether Sa or Sb is the initial state.

Observations: • Sa and Sb are equivalent is denoted by Sa = Sb

• If Sa = Sb and Sb = Sc then Sa = Sc i.e., transitivity property holds for state equivalence relation

15

Page 16: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

State equivalence is an equivalence relation

• Show that this is true.

16

Page 17: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

State Partitioning

The set of states of a machine can be partitioned into disjoint subsets, known as the equivalence classes, so that two states are

– in the same equivalence class iff they are equivalent

– in different classes iff they are distinguishable.

17

Page 18: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Minimization Procedure

• The procedure of determining the sets of equivalent states i.e., the equivalence classes can be built based on the following property:

If Sa and Sb are equivalent states, their corresponding X-successors, for all X, are also equivalent.

18

Page 19: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Minimization Example

19

Step 0 – Assume all states are 0-equivalent P0 = (A B C D E F) Step 1 – Partition M into

subsets such that all states in the same subset are 1-equivalent.

P1 = ________________

Page 20: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Minimization Example…contd.

20

Step 2 – P1 = (ACE) (BDF) Let us consider (ACE) On x=0, A → E C → E E → C i.e., (ACE) → (CEE) i.e., the next

state is same as current state On x=1, (ACE) → (BDF) i.e., all

the next states are equivalent Therefore, we cannot split

(ACE)

Page 21: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Minimization Example…contd.

21

Step 2 (contd.) – P1 = (ACE) (BDF) Now let us consider (BDF) On x=0, B → F D → F F → B On x=1, B → D D → B F → C Can we split (BDF)? P2 = _____________

Page 22: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Minimization Example…contd.

22

Step 3– P2 = ________________ P3 = ________________ Show your work:

Page 23: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Minimization Example…contd.

23

Step 4– P3 = ________________ P4 = ________________ Show your work:

Page 24: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Minimization Example…contd.

24

Step 5 – P4 = ________________ P5 = ________________

Page 25: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Theorem 10-1

Theorem 10-1: The equivalence partition is unique.

Proof:

25

Page 26: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Theorem 10-2

Theorem 10-2: If two states Sa and Sb of machine M are distinguishable, then they are distinguishable by a sequence of length n-1 or less, where n is the number of states in M.

Proof:

26

Page 27: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Machine equivalence

Definition: Two machines M1 and M2 are equivalent if and only if for every state in M1, there is a corresponding equivalent state in M2 and vice versa.

Observations: • Since the equivalence partition of a m/c M is

unique, it gives the minimum number of states a machine equivalent to M should have

• A machine with no equivalent states and is equivalent to M, is referred to as minimal or reduced form of M

27

Page 28: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Example

28

α β γ δ Equivalence partition = (AC), (E), (BD), (F)

M1 M1*

Page 29: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

State Minimization Example 2

• Partition the states of M2. Show your work.

29

M2

Page 30: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Equivalent Machine of M2

Based on equivalence partition, equivalent machine M2* is:

30

Page 31: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Isomorphism

• Labels α, β,… is chosen arbitrarily • Different assignment will give a machine with

same behavior • If one machine can be obtained from the

other by relabeling its states, they are said to be isomorphic to each other

31

Page 32: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Theorem: To every machine M there corresponds a minimal machine M* which is equivalent to M and is unique up to isomorphism

Detection of isomorphism is not always easy and

can be accomplished by using a canonical representation of the machine.

32

Page 33: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Canonical representation

• Select a state and label it A (preferably the start state if specified)

• Next labels are chosen such that when read from left to right, the first occurrence of each new label will be in alphabetical order

33

Page 34: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Standard form of M2*

34

Page 35: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Incompletely Specified Machines

• For a machine, – For a given input in a state, the next state and

output may not be specified, because that input never occurs

– For a given input, next state is specified, but the output is not, because the output value may not be critical (don’t-care)

Such a machine is known as an incompletely specified machine.

35

Page 36: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Incompletely Specified Machines

• Whenever a state transition is unspecified the future behavior becomes unpredictable

• Assumption: For any input sequence for any of possible starting states, no unspecified next state is encountered, except possibly in the final state. Such an input sequence is said to be applicable to the starting state of M.

36

--,0 A, 1

→ Introduce a

terminal state

Page 37: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Definitions

• State Sa of M1 is said to cover, or contain, Sb of M2 if and only if every input sequence applicable to Sb is also applicable to Sa, and its application to both M1 and M2 when they are initially in Sa and Sb, respectively, results in identical output sequences whenever the outputs of M2 are specified

• Machine M1 is said to cover machine M2 iff for every Sb in M2, there is a corresponding state Sa in M1 such that Sa covers Sb

37

Page 38: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Definitions…contd.

• Two states Sa and Sb of machine M are compatible if and only if for every input sequence applicable to both Sa and Sb the same output sequence will be produced whenever both outputs are specified regardless of whether Sa or Sb is the initial state. – In other words, Sa and Sb are compatible iff their

outputs are not conflicting and their X-successors are either the same or also compatible (for every X)

– We can generalize: a set of states (Sa , Sb , Sc ,…) is called a compatible if all its members are compatible

38

Page 39: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Difficulties with Incompletely Specified Machines

• Difficulty: Non-uniqueness of reduced & minimal machines

• Example: M4

39

Page 40: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Difficulty – Example 1

• Minimization 1: Replace all “—” with “1”s

40

M4 M4*

Page 41: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Difficulty – Example 1…contd.

• Minimization 2: Replace all “—” with “0”s

41

M4 M4#

Page 42: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Difficulty – Example 2

• Difficulty: Non-uniqueness of reduced & minimal machines

• Example: Is M5 in a reduced form?

42

M5:

Page 43: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Difficulty – Example 2

• Augmenting by state splitting • B+ means either B’ or B’’

43

Page 44: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Two different machines

44

Page 45: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

The merger graph • Consider Machine M6 • We can build a merger graph as follows:

– Each state is represented by a node – An edge exists between two nodes if the represented states are

compatible – An edge is annotated with an implied pair; for the two states to be

compatible, the implied pair of states must be compatible

45

Machine M6:

Page 46: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Compatible Sets • Based on the merger graph, we identify

the following 9 compatible pairs: { (A B), (A C), (A D), (B C), (B D), (B E), (C D), (C F), (E F) } • Further we can reduce the above by

finding maximal compatibles: { (A B C D), (B E), (C F), (E F) } • Consider: S1 = { (A B C D), (E F) } as a solution From the merger graph, this implies that (C F) and (B E) must be compatible which is not the case Therefore, the compatible set, S1, is not a valid solution However, it gives a lower bound on the solution

46

Page 47: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Closed Covering - Definition

• A set of compatibles (for machine M) is said to be closed if, for every compatible contained in the set, all its implied compatibles are also contained in the set.

• A closed set of compatibles which contains all the states of M is called as closed covering.

47

Page 48: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Closed Covering • Maximal compatibles: { (A B C D), (B E), (C F), (E F) } What are the closed coverings for M6?

48

Page 49: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Compatibility Graph

• The final solutions are obtained by trial-and-error. We can do better.

49

Machine M7:

Merger Graph:

Page 50: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

50

Compatibility Graph:

• Compatibility Graph: – Each node is a compatible pair – A directed edge from node u to node v if the state pair represented by node u

implies that by node v

• Solution is found by identifying a subgraph such that: – It is closed – each state is covered by atleast one compatible pair in the graph

• A subgraph is closed if all outgoing edges are contained within the graph

Merger Graph:

Page 51: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Capabilities and Limitations

• What can a machine do? • Are there any limitations on the type of input-

output transformations that can be performed by a machine?

• What restrictions are imposed on the capabilities of the m/c by the finiteness of the number of its states?

51

Page 52: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Limitation of FSM - Periodicity

• Let there be an n-state machine • Input: sequence of 1’s • After consuming no more than n 1’s the

machine should arrive at a visited state. Why? • From there on, the output should repeat.

Why?

52

Page 53: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Limitation - Example 1

• Problem: Can we build an FSM which receives a long sequence of 1’s and should produce an output 1 when and only when the number of inputs it has received so far is equal to

k (k + 1)/2 where k = 1, 2, 3, … Example input/output sequence:

Such a machine cannot be built why?

53

Page 54: State Machine Design - Help-A-Bull · Synchronous Sequential Machine A synchronous sequential machine M is a quintuple . M = (I, O, S, δ, λ) Where I, O, and S are finite, nonempty

Limitation – Example 2

Serial multiplication is not solvable by a fixed FSM. In other words, no finite-state machine with a fixed number of states can multiply two arbitrarily large numbers. Why? Hint: Consider multiplying 2p and 2p where p > n

54