Chapter 4 Finite State Machines

advertisement

4-1 Theory of Computation

Chapter 4 Finite State Machines

This section also includes Finite State Acceptors.

This section and the next on Turing Machines are concerned with deciding what a computer "can do". We have seen how to prove that a program meets a specification - we now consider whether there are some specifications which can not be met by any program.

Definitions

A process is a sequence of steps which if performed will result in a task being carried out.

An effective process (or algorithm) is a process which may be executed by a machine - i.e. a computable process.

To define the term computable there are three main approaches:

Abstract Machine Approach (Turing)

Functional Approach (Church, Kleene)

Symbol Manipulation (Post)

We shall look at the first two of these during this module.

The Abstract Machine Approach

We have said that an alogorithm is a process which can be executed by a machine - we need a 'yardstick' machine which is

– as simple as possible

– sufficiently powerful to execute all algorithms which can be executed on any machine (ignoring e.g. speed contraints).

Finite State Machines (FSM)

At any moment, a FSM is in one of a finite number of states. Events, which are one of

– receive an input stimulus

– emit an output response

– enter a new state

• happen instantaneously at discrete time intervals.

Input stimuli arrive at regular time intervals from the 'environment'.

Finite State Machine M may be described by

M=[S,I,O,fs,fo] where

S is the set of States{s

0

,s

1

,s

2

,.., s n

}

• I is the input alphabet {

0

,

1

,

2

,..,

 m}

4-1

4-2 Theory of Computation

• O is the output alphabet {

0

,

1

,

2

• fs is a mapping from SxI onto S

,..,

 k}

(state transition mapping)

• fo is a mapping from S onto O

(output mapping)

The functions fs,fo may be defined in one of two ways either

State table or

State graph (state transition diagram)

The action of a Finite State machine may be traced in a

State-Time Table

Example the following FSM has

• S is the set of States{s0,s1,s2}

I is the input alphabet {



}

O is the output alphabet {



}

Present Next State Output

State Present Input

0 1 s

0 s

1 s

2 s

1 s

2 s

2 s

0 s

1 s

0

0

1

1

1

S

0

/0

1

0

S

2

/1

0

S

1

/1

0

• trace for input 00011010

4-2

1

4-3 Theory of Computation

Time t0 t1 t2 t3 t4 t5 t6 t7 t8

Input 0 0 0 1 1 0 1 0

State s

0 s

1

Output 0

State Graph / State Transition Diagram

A state transition diagrams links old states with new states, indicating any corresponding input and output.

A typical element is: s a

/

1 s b

/

2

1

Note:

Different inputs can produce different events

– sb could be the same as sa

– fo(sa)=

 fs(sa,

1 and fo(sb)=

1)= sb

There is always an input.

2

There might be no output.

State Table

Present

State

Next

Present

State

Input

0

  m

Output

s

0 f s

(s

0

,

0

)

… f s

(s

0

,

 m

) f o

(s

0

)

: s n

: f s

(s n

,

0

)

4-3

: f s

( s n

,

 m

)

: f o

( s n

)

4-4 Theory of Computation

Example - Parity Machine

This machine records whether the number of 1s received as input is even or odd.

Need two states

– one records even number of 1s so far

– the other records odd number of 1s so far

S is { s0 ,s1}

I is {0,1}

O is {0,1} 0 for even number of 1s

1 for odd number of 1s

The initial state is s0 (as always). So

– s0 is the even state

– s1 is the odd state

Need to alter state when a 1 is read

Need to stay in same state when 0 is read

4-4

4-5 Theory of Computation

One Moment Delay Machine

A machine which copied input to output as soon as possible would have a given input character appearing as output 1 time interval later.

This machine "holds on" to an input for 1 time interval, so that it becomes the output 2 time intervals later.

Initial 0s used to 'pad out' the output.

Extra 0 used to ‘pad out’ the input.

These 'delay' machines may be regarded as memory machines.

1 time delay

remembers 1 binary signal - 2 states

2 time delay

remembers 2 binary signals - 4 states

To remember N binary signals requires 2 N states.

N binary signals are equivalent to numbers in the range 0.. 2 N -1, so

2 N states can store numbers 0.. 2 N -1, or

M states can store numbers 0..M-1.

FSMs have a finite memory capability.

4-5

4-6 Theory of Computation

Example - Serial Binary Adder

This machine adds two binary numbers from right to left. Each input symbol consists of one bit from each of the two input numbers, so there are four possible inputs, 00, 01, 10 and 11.

So I = {00,01,10,11}

The output from the machine will be a sequence of binary digits.

So O = {0,1}

Trace for adding 6 and 7

6 = 0110

7 = 0111

– our input 01 11 11 00

4-6

4-7 Theory of Computation

The serial binary adder can add two arbitrary numbers. We might say

But….

"computable - computable by a FSM"

FSM Minimisation

Two machines M aand M’ are equivalent if for they are given identical input they always produce identical output sequences.

A FSM is said to be minimal if all machines that are equivalent to it have the same number or more states than it.

A state is said to be unreachable if it cannot be reached from the starting state S0 under any circumstances.

It is easy to see that a minimal machine will not have any unreachable states.

First stage in minimistaion is to remove all unreachable states.

1

1

1

1

Two states are said to be equivalent if for any input they produce identical output sequences.

If we can discover all the equivalent states then we may merge these in order to produce a minimal machine.

A minimal machine will have no equivalent states.

4-7

4-8 Theory of Computation

0

0

1

Two states are k-equivalent if for any input of length k.

1

So we should be able to find the

0-equivalent states

1-equivalent states

:

– n-equivalent states

Whenever the n-equivalent states are identical to the n+1-equivalent states we may deduce that we have found all the equivalent states.

Present State Next State

Present Input

Output s0 s1 s2 s3 s4 s5 s6

0 s2 s3 s0 s1 s6 s2 s4

1 s3 s2 s4 s5 s5 s0 s0

0

1

0

1

1

0

1

4-8

4-9 Theory of Computation

Consider the 0-equivalent states

{s0,s2,s5} {s1,s3,s4,s6}

Then the 1-equivalent states

{s0,s2} {s5} {s1,s3,s4,s6}

Then the 2-equivalent states

{s0,s2}{s5} {s1,s6}{s3,s4}

Then the 2-equivalent states

{s0,s2}{s5} {s1,s6}{s3,s4}

Then the 3-equivalent states

{s0,s2}{s5} {s1,s6}{s3,s4}

As the 3-quivalent and 2-equivalent states are the same we have found all the equivalent states.

4-9

Download