cl a simple form of computation used widely one way to find - - PowerPoint PPT Presentation

cl
SMART_READER_LITE
LIVE PREVIEW

cl a simple form of computation used widely one way to find - - PowerPoint PPT Presentation

Finite-State Machines (Automata) lecture 12 cl a simple form of computation used widely one way to find patterns 1 current A A B C D D B B C D A next C 2 Application Fields Industry real-time control,


slide-1
SLIDE 1

cl

Finite-State Machines (Automata) lecture 12

  • a simple form of computation
  • used widely
  • one way to find patterns

1

slide-2
SLIDE 2

2

A D B C

current next A B C D B C D A

slide-3
SLIDE 3

Industry

  • real-time control, vending machines, cash dispensers, etc.

Electronic circuits

  • data path / control path
  • memory / cache handling
  • protocols, USB, etc.

Communication protocols

  • initiation and maintenance of communication links
  • error detection and handling, packet retransmission

Language analysis

  • natural languages
  • programming languages
  • search engines

Application Fields

001

3

slide-4
SLIDE 4

Informatics 1 School of Informatics, University of Edinburgh

4

Finite State Machines

  • A conceptual tool for modelling reactive

systems.

  • Not limited to software systems.
  • Used to specify required system behaviour in a

precise way.

  • Then implement as software/hardware (and

perhaps verify behaviour against FSM).

  • Finite state machines can also be viewed as

rules for generating sets of strings 
 ( = sets of finite sequences of symbols)

slide-5
SLIDE 5

A Decimal Number

d d

+⎮−

.

d d d ε start end sta sta alternative paths repetition skip

5

d = {"0","1","2","3","4","5","6","7","8","9"} +⎮− = { "+","-" } ε = "" . = "."

Each path from start to end, with a choice of

  • ne of the labels for each edge traversal, gives a decimal number.
slide-6
SLIDE 6

6

This gives us a new way of defining sets by rules.

d d

+⎮−

.

d ε d d

number whole number A whole number is a digit followed by any number of digits,

  • r a sign followed by a digit followed by any number of digits
slide-7
SLIDE 7

7

This gives us a new way of defining sets by rules.

d d

+⎮−

.

d ε d d

number whole number

A whole number is a digit followed by any number of digits,

  • r a sign followed by a digit followed by any number of digits.

A number is a whole number or a whole number followed by a decimal point followed by a digit followed by any number of digits

slide-8
SLIDE 8

finite state machines

R

8

A labelled directed graph nodes edges with a set of start nodes and a set of end nodes Each edge is labelled with a set of strings

slide-9
SLIDE 9

finite state machines

R

9

A labelled directed graph nodes edges with a set of start nodes and a set of end nodes Each edge is labelled with a set of strings

Each path from a start node to an end node, with a choice of

  • ne of the labels for each edge traversal, gives, by concatenation, a string.

The language defined by the machine is the set of all such strings

slide-10
SLIDE 10

A Decimal Number

d d

+⎮−

.

d d d ε start end sta sta alternative paths repetition skip

10

The language defined by this machine is the set of all decimal numerals

slide-11
SLIDE 11

finite state machines

R S

11

What happens when we link two machines together?

slide-12
SLIDE 12

sequence RS

R S

ε

12

RS = { r ++ s | r ∈ R ∧ s ∈ S }

slide-13
SLIDE 13

alternation R | S

R S

13

R | S = R ∪ S

slide-14
SLIDE 14

iteration R*

ε

14

R

ε ε

"" ∈ R* x ∈ R*, r ∈ R ⇒ x ++ r ∈ R*

slide-15
SLIDE 15

finite state spaghetti

15

A language is a set of finite sequences of words. A language is a set of finite sequences of symbols. A language is regular iff it is the language recognised by some Finite State Machine.

slide-16
SLIDE 16

Start state State Accepting state

s t

a,b Transitions each transition is labelled with a finite sequence of tokens, the tokens, depend on the application, they may be letters, symbols, words, actions, …

2 1

b a,b a,b a Three states Six transitions

slide-17
SLIDE 17

Start state State Accepting state

s t

a,b Transitions

2 1

b a,b a,b a Three states One start state One accepting Six transitions Normally we only use sequences of length 0 or 1 as labels. Then we write a for <a> and ε for <> We generate strings of tokens by tracing a path from a start state to an accepting state. Which strings are accepted by this automaton?

slide-18
SLIDE 18

Start state State Accepting state

s t

a,b Transitions

2 1

b a,b a,b a Three states One start state One accepting Six transitions Normally we only use sequences of length 0 or 1 as labels. Then we write a for <a> and ε for <> Strings that begin with b and are of even length or begin with a and are of odd length

slide-19
SLIDE 19

2 1

b b a a Start state State Accepting state

s t

a,b Transitions This machine is non-deterministic some strings have more than one trace some strings have no traces Which of these strings are accepted? abba abab baba aba bab ab ba a b Three states Two start states One accepting Four transitions

slide-20
SLIDE 20

2 1

b b a a Start state State Accepting state

s t

a,b Transitions This machine is non-deterministic some strings have more than one trace some strings have no traces Which of these strings are accepted? abba abab baba aba bab ab ba a b Three states Two start states One accepting Four transitions

slide-21
SLIDE 21

2 1

b b a a Start state State Accepting state

s t

a,b Transitions This machine is non-deterministic some strings have more than one trace some strings have no traces Which of these strings are accepted? abba abab baba aba bab ab ba a b Three states Two start states One accepting Four transitions a ε L ba ε L x ε L → x ba ε L

slide-22
SLIDE 22

KISS – DFA

22

Deterministic Finite Automaton Exactly one start state, and from each state, q, for each token, t, there is exactly one transition from s with label t

slide-23
SLIDE 23

This machine has four states,
 Q = { s0, s1, s2, s3 } Its alphabet has three symbols
 Σ = { 0, 1, 2 } For each (state, symbol) pair, (q,s) there is exactly one transition
 from q with label s This means that 
 qʹ is determined by (q,s)

q qʹ

s

slide-24
SLIDE 24

For each (state, symbol) pair, (q,s) there is exactly one transition
 from q with label s This means that 
 qʹ is determined by (q,s) It has only one start state, this means that any input string determines a sequence of states.

q qʹ

s

This is a deterministic 
 finite-state 
 automaton

DFA

slide-25
SLIDE 25

For each (state, symbol) pair, (q,s) there is exactly one transition
 from q with label s 
 qʹ is determined by (q,s) It has only one start state Every DFA has a next-state function qʹ = F(q,s)

q qʹ

s

This is a deterministic finite- state automaton, DFA

slide-26
SLIDE 26

DFA ⊂ NFA

26

A DFA has only one start state For each (state, symbol) pair, (q,s) there is exactly one transition
 from q with label s qʹ is determined by q and s

Every DFA has a next-state function qʹ = F(q,s) any input string determines a sequence of states.

We will focus now on DFA and return later to NFA. Then we will show that for any NFA there isa a DFA that defines the same language.

slide-27
SLIDE 27

Every DFA has a next-state function qʹ = F(q,s)

q qʹ

s

This is a deterministic finite- state automaton, DFA

Since we have finitely many symbols and states This can be given by a table

1 2 s0 s0 s1 s2 s2 s3 s3 s1

slide-28
SLIDE 28

Every DFA has a next-state function qʹ = F(q,s)

q qʹ

s

This is a deterministic finite- state automaton, DFA

Since we have finitely many symbols and states This can be given by a next-state table

q\s 1 2 s0 s0 s1 s2 s1 s3 s0 s1 s2 s2 s3 s0 s3 s1 s2 s3

slide-29
SLIDE 29

Every DFA has a next-state function qʹ = F(q,s)

q qʹ

s

This is a deterministic finite- state automaton, DFA

We can also represent the transitions by a relation. Which symbol(s) take us from state q to state r ?

q\r s0 s1 s2 s3 s0 0 1 2 s1 s2 s3 1

slide-30
SLIDE 30

Every DFA has a next-state function qʹ = F(q,s)

q qʹ

s

This is a deterministic finite- state automaton, DFA

We can also represent the transitions by a relation. Which symbol(s) take us from state q to state r ?

q\r s0 s1 s2 s3 s0 0 1 2 s1 1 2 s2 2 1 s3 1 2

slide-31
SLIDE 31

For every DFA, any input string determines a path or trace

This is a deterministic finite- state automaton, DFA

input 000 021 120 11 12 21 22 111 110 212 path s0 s0 s0 s0 s0 s0 s2 s3 s0 s1 s1 s3

slide-32
SLIDE 32

For every DFA, any input string determines a path

This is a deterministic finite- state automaton, DFA

input 000 021 120 path s0 s0 s0 s0 s0 s0 s2 s3 s0 s1 s1 s3 11 12 21 22 111 110 212 s0 s1 s0 s0 s1 s1 s0 s2 s3 s0 s2 s0 s0 s1 s0 s1 s0 s1 s0 s0 s0 s2 s3 s3

slide-33
SLIDE 33

Which paths end in an accepting state?

This is a deterministic finite- state automaton, DFA

input 000 021 120 path s0 s0 s0 s0 s0 s0 s2 s3 s0 s1 s1 s3 11 12 21 22 111 110 212 s0 s1 s0 s0 s1 s1 s0 s2 s3 s0 s2 s0 s0 s1 s0 s1 s0 s1 s0 s0 s0 s2 s3 s3

slide-34
SLIDE 34

This is a deterministic finite- state automaton, DFA

4 5 7 8 13 12 23 Which paths end in an accepting state? 7 15 path s0 s0 s0 s0 s0 s0 s2 s3 s0 s1 s1 s3 s0 s1 s0 s0 s1 s1 s0 s2 s3 s0 s2 s0 s0 s1 s0 s1 s0 s1 s0 s0 s0 s2 s3 s3 input 000 021 120 11 12 21 22 111 110 212

slide-35
SLIDE 35

This is a deterministic finite- state automaton, DFA

What is the meaning of each state? 1 2 3 4 5 6 7 8 9 .Express each of these decimal numbers in ternary notation, and find out what state is reached by the trace they determine

slide-36
SLIDE 36

This is a deterministic finite- state automaton, DFA

What is the meaning of each state? 1 2 3 4 5 6 7 8 9 This machine counts ternary mod 4 F(q, s) = 3 * q + s (mod 4)