Finite State Machines Murray Cole Finite State Machines 1 - - PowerPoint PPT Presentation

finite state machines
SMART_READER_LITE
LIVE PREVIEW

Finite State Machines Murray Cole Finite State Machines 1 - - PowerPoint PPT Presentation

I V N E U R S E I H T Y T O H F G R E U D I B N Finite State Machines Murray Cole Finite State Machines 1 Embedded Systems Already 10s of processor chips per person in the world There will


slide-1
SLIDE 1

T H E U N I V E R S I T Y O F E D I N B U R G H

Finite State Machines

Murray Cole

Finite State Machines

slide-2
SLIDE 2

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

slide-3
SLIDE 3

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

slide-4
SLIDE 4

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

slide-5
SLIDE 5

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,

  • ne 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

slide-6
SLIDE 6

5

An FSM for a Simple Ticket Machine

m/ t/p r/d m/ t/ r/ 1 2

  • ✁✄✂
☎✝✆ ☎✟✞ ✠

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

slide-7
SLIDE 7

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

slide-8
SLIDE 8

7

m/ t/p r/d m/ t/ r/ 1 2

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

slide-9
SLIDE 9

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

slide-10
SLIDE 10

9

Acceptors

1 1 1 1,0 B A C D

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

slide-11
SLIDE 11

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

slide-12
SLIDE 12

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

slide-13
SLIDE 13

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