Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

NI VER

U S

IT
TH

Y
O F

H
G
E

R
D I U
N B

Finite State Machines


Murray Cole

Finite State Machines


1
Embedded Systems

Already 10’s of processor chips per person in the world

There will “soon” be 100’s or 1000’s

Most of these are not in “computers” but are embedded in


everyday real world systems (cars, TVs, vending machines,
watches, (people?!))

These often implement quite simple reactive systems

Finite State Machines


2
Reactive Systems

Wait to receive an input

Respond with an output

Response may depend upon finite history (i.e. not just the most
recent input)

Finite State Machines


3
Finite State Machines (Automata)

A conceptual tool for modelling reactive systems

Pre-date “Computer Science”

Force us to make precise definitions (unlike natural language)

Can then implement in hardware or software or both

Finite State Machines


4
FSM - Formal Definition

An input alphabet, (“sigma”), which is a set of symbols, one for


each distinct possible input (e.g. buttons, coin slots, ...)

An output alphabet, (“lambda”), which is another set of symbols,




one for each distinct possible output (e.g. lights, can dispensed, ...)

Some named states, each capturing some state of the system (e.g.
“coin inserted but no can dispensed”), drawn as circles, one
indicated as the start state with an arrow

A collection of transitions, each an arrow between two states,


labelled with the input which activates it and the output which
results (or (“epsilon”) indicating no input or output respectively)


Finite State Machines


5
An FSM for a Simple Ticket Machine
m/
1 2 m/
t/p

r/d

t/
r/

for insert money, request ticket, request refund







for print ticket, deliver refund




 



for convenience, label the same arrow with several i/o pairs

for convenience, just write as a blank




Finite State Machines


6
FSM Traces

For some FSM called , a trace describes one possible sequence of


activities and is

1. A finite sequence of alternating states and transition labels


starting and ending with a state: .





 






2. The first state, , is the start state of .



3. For each state, label, state sequence appearing in the












sequence, there must be a transition in from state to







labelled .




 


Finite State Machines


7
m/
1 2 m/
t/p

r/d

t/
r/

For the ticket machine

m/ m/ m/ r/d











is a trace, but

m/ m/ m/ r/d












isn’t.
The overall behaviour of a FSM is the set of all its possible traces.

Finite State Machines


8
Acceptors

Acceptors are FSMs with

empty output alphabet (all outputs are )


some states marked as “accepting” (double circle)

Input sequence is accepted if it can generate a trace from the start


state to an accepting state.
The language accepted by an (acceptor) FSM is the set of all input
sequences which it accepts.

Finite State Machines


9
Acceptors

0 0
A B C

1 1
0 1

1,0

Accepts strings of 0s and 1s in which the number of 0s so far never


exceeds the number of 1s so far by more than one and vice versa

Finite State Machines


10
Determinism

FSMs in which for every state, there is at most one transition


leaving the state for each input symbol are called determinstic.

Other FSMs are called non-deterministic

Sometimes easier to define non-deterministic FSMs

Can always convert a non-deterministic FSM into an equivalent


deterministic FSM

Finite State Machines


11
What FSMs can’t do

FSM states do not have any memory inside

The FSM “remembers” simply being in a given state, so that “Have


seen three 0’s” and “Have seen four 0’s” must be two different
states, not one state with a counter variable inside

Consequently, FSMs can’t “count” arbitrarily large histories


– accept all strings including 287 0’s - possible
– accept all strings with equal numbers of 0’s and 1’s - not
possible

Finite State Machines


12
Summary

Embedded and reactive systems

Finite State Machines to model these

FSM traces

Acceptors and Transducers

Determinism

Limits to FSM power

Finite State Machines

You might also like