0% found this document useful (0 votes)
206 views12 pages

Finite-State Machines Lecture Notes

The document discusses finite state machines (FSMs), which are a simple model of computation used to describe reactive systems and find patterns. FSMs can be deterministic or non-deterministic. A FSM consists of a set of states, transitions between states, and inputs/outputs. Traces show the sequence of states and inputs/outputs taken as the FSM reacts to inputs over time. FSMs can be represented formally and logically to model system behavior precisely.

Uploaded by

Debashish Pal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
206 views12 pages

Finite-State Machines Lecture Notes

The document discusses finite state machines (FSMs), which are a simple model of computation used to describe reactive systems and find patterns. FSMs can be deterministic or non-deterministic. A FSM consists of a set of states, transitions between states, and inputs/outputs. Traces show the sequence of states and inputs/outputs taken as the FSM reacts to inputs over time. FSMs can be represented formally and logically to model system behavior precisely.

Uploaded by

Debashish Pal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Finite-State Machines

(Automata) lecture 14

cl
• a simple form of computation

• used widely

• one way to find patterns

• one way to describe reactive systems

1
Formal Definition
Non-deterministic FSM model,
M = (Q,s0,F,Σ,Δ)
• Set of states, Q
• Initial state s0∈Q
• Accepting states F ⊆ Q a
• Alphabet Σ s t
• Transition relation, Δ(s, a, t)
where s, t ∈ Q
and a ∈ Σ ∪ {ε}.

Informatics 1
School of Informatics, University of Edinburgh
2
Reactive Systems

• Wait to receive an input


• Respond with:
an output (changing to a new state) or
change to new state without output
• Response depends on (finite) history

Informatics 1
School of Informatics, University of Edinburgh
3
Finite State Machines

• A conceptual tool for modelling reactive


systems.
• Not limited to software systems.
• Pre-dates computing science.
• Used to specify required system behaviour in a
precise way.
• Then implement as software/hardware (and
perhaps verify against FSM).

Informatics 1
School of Informatics, University of Edinburgh
4
Formal Definition

FSM transducer model, M, consists of:


• Set of states, Q
• Initial state s0∈Q
• Alphabets of input and output symbols i/o
• Transition relation, Δ(s, a, t) where s, t ∈ Q
and a ∈ (In ∪ {ε}) x (Out ∪ {ε}).
i/o
s1 s2

state transition next state

Informatics 1
School of Informatics, University of Edinburgh
5
Parking Meter Example

Σ = {m,t,r} money, ticket request, refund request


Λ = {p,d} print ticket, deliver refund
Q = {1,2}
T = {(1,t/ε,1), (1,r/ε,1), (1,m/ε,2), (2,t/p,1), (2,r/d,1), (2,m/ε,2)}
t/p
t/

m/ m/
1 2

r/ r/d

This is a transducer FSM because it has some outputs.


Informatics 1
School of Informatics, University of Edinburgh
6
FSM Traces

• Finite sequence of alternating state and


transition labels, starting and ending with a
state: [s0, i1/o1, s1, i2/o2, s2, … sn-1, in/on, sn]
• s0 is the initial state.
• Each [si-1, ii/oi, si] subsequence must appear
as a transition in T

Informatics 1
School of Informatics, University of Edinburgh
7
Parking Meter Trace Example
t/ m/
t/p m/
1 2
r/d
Traces include: r/

[1, m/, 2, t/p, 1]


[1, m/, 2, m/, 2, r/d, 1]
[1, m/, 2, t/p, 1, m/, 2, m/, 2]
[1, t/, 1, t/, 1, m/, 2]
… etc

Behaviour of FSM is the set of all possible traces.


This is not necessarily a finite set.
Informatics 1
School of Informatics, University of Edinburgh
8
Transducer FSM in Logic

trace(Si, Sf, T, []) ← Si = Sf [] is the empty sequence


[X|R] separates first element, X,
trace(Si, Sf, T, [I/O|R]) ← from rest of sequence, R.

∃Sn . Δ(Si,I/O,Sn) ⋀
trace(Sn, Sf, T, R)

T = {(1,t/ε,1), (1,r/ε,1), (1,m/ε,2), (2,t/p,1), (2,r/d,1), (2,m/ε,2)}


trace(1, 1, T, [m/ε, t/p]) t/ t/p
trace(1, 1, T, [m/ε, m/ε, r/d])
trace(1, 2, T, [m/ε, t/p, m/ε, m/ε]) m/ m/
1 2
trace(1, 2, T, [t/ε, t/ε, m/ε])
… etc r/d
r/
Informatics 1
School of Informatics, University of Edinburgh
9
Deterministic FSMs

A specific class of finite state system:


• deterministic FSMs
• that are acceptors

Informatics 1
School of Informatics, University of Edinburgh
10
Determinism
! In a deterministic FSM, all states have no i1 ≠ i2 i1/o1 s2
more than one transition leaving the state s1
for each input symbol. i2/o2 s3
! In a non-deterministic FSM, some states
have more than one transition leaving to i/o1 s2
different successor states for the same s1
input symbol. i/o2 s3
! Sometimes non-deterministic FSMs are
easier to define.
! Can always convert from a non-
deterministic to a deterministic FSM.

Informatics 1
School of Informatics, University of Edinburgh
11
Determinism and Traces

A FSM, M, is deterministic if for every string x∈Σ*


there is at most one trace for x in M
(where Σ* is the set of all strings in alphabet of M)

non-deterministic (choice) deterministic (no choice)


a b
a a
1 2 1 2
Sequence Trace Sequence Trace
aa [1,a,1,a,2] ba [1,b,1,a,2]
aa [1,a,1,a,1] bb [1,b,1,b,1]

Informatics 1
School of Informatics, University of Edinburgh
12

You might also like