Copyright © 2011-2014 - Curt Hill Finite State Machines The Simplest and Least Capable Automaton.

17
Copyright © 2011-2014 - Curt Hill Finite State Machines The Simplest and Least Capable Automaton

Transcript of Copyright © 2011-2014 - Curt Hill Finite State Machines The Simplest and Least Capable Automaton.

Page 1: Copyright © 2011-2014 - Curt Hill Finite State Machines The Simplest and Least Capable Automaton.

Copyright © 2011-2014 - Curt Hill

Finite State Machines

The Simplest and Least Capable

Automaton

Page 2: Copyright © 2011-2014 - Curt Hill Finite State Machines The Simplest and Least Capable Automaton.

Automata• Lets imagine a simple machine as

a model of computation• It must have:• Input

– Assume a string of characters from some alphabet

• A control unit with an internal state• Output

– Output is determined by input and state

Copyright © 2011-2014 - Curt Hill

Page 3: Copyright © 2011-2014 - Curt Hill Finite State Machines The Simplest and Least Capable Automaton.

Transition Function• Each Finite State Automaton must

have a transition function• This transition function requires

two parameters:– The current state– The current input value

• The result is the new state• Any pair of parameters that has no

defined result generates an error state

Copyright © 2011-2014 - Curt Hill

Page 4: Copyright © 2011-2014 - Curt Hill Finite State Machines The Simplest and Least Capable Automaton.

Models• This simple automaton may be

modeled in several ways• A state chart

– On one side is the state– On the other is the inputs

• A graph– Each node represents a state– Each arc an input that causes the

state change

Copyright © 2011-2014 - Curt Hill

Page 5: Copyright © 2011-2014 - Curt Hill Finite State Machines The Simplest and Least Capable Automaton.

Examples

Copyright © 2011-2014 - Curt Hill

s0s1

s2

a b

b

a

a

b

s0

s1

s2

ba

s0

s0

s1

s1 s2

s2

Page 6: Copyright © 2011-2014 - Curt Hill Finite State Machines The Simplest and Least Capable Automaton.

Text Example• Rosen gives the example of a

vending machine• This is more complicated that we

can show in PowerPoint– 7 States– 5 possible inputs

Copyright © 2011-2014 - Curt Hill

Page 7: Copyright © 2011-2014 - Curt Hill Finite State Machines The Simplest and Least Capable Automaton.

FSM or FSA?• A Finite State Machine may also be

known as a Finite State Automaton• They come in two flavors

– Producing Output– Not producing Output

• Strangely we will deal with the Output producing first

Copyright © 2011-2014 - Curt Hill

Page 8: Copyright © 2011-2014 - Curt Hill Finite State Machines The Simplest and Least Capable Automaton.

More Formally• An output producing finite state

machine is 6 tupleM=(S,I,O,f,g,s0)

• S is a set of states• I is the set of inputs• O is the set of outputs• f is the transition function• g is the output function

• s0 is the initial stateCopyright © 2011-2014 - Curt Hill

Page 9: Copyright © 2011-2014 - Curt Hill Finite State Machines The Simplest and Least Capable Automaton.

The functions• The functions in the above are f and

g• The transition function, f, takes two

inputs– Current state– Input symbol

• The function then produces the new state

• The output function, g, takes the same two inputs, but produces the output symbol instead of the next state

Copyright © 2011-2014 - Curt Hill

Page 10: Copyright © 2011-2014 - Curt Hill Finite State Machines The Simplest and Least Capable Automaton.

Function Representation• We have already seen the table

representation of the transition function

• The output function has the same form, although the two are often combined into a single table

• In the graph form the arcs are labeled first by the input and then the output

• See next slideCopyright © 2011-2014 - Curt Hill

Page 11: Copyright © 2011-2014 - Curt Hill Finite State Machines The Simplest and Least Capable Automaton.

Output Example

Copyright © 2011-2014 - Curt Hill

s0s1

s2

a,0 b,2

b,1

a,1

a,2

b,0

s0

s1

s2

ba

s0

s0

s1

s1 s2

s2

s0

s1

s2

ba

0

0

1

1 2

2

Transition, f Output, g

Initial is s0

Page 12: Copyright © 2011-2014 - Curt Hill Finite State Machines The Simplest and Least Capable Automaton.

Example Continued

Copyright © 2011-2014 - Curt Hill

s0s1

s2

a,0 b,2

b,1

a,1

a,2

b,0

s0

s1

s2

ba

s0

s0

s1

s1 s2

s2

s0

s1

s2

ba

0

0

1

1 2

2

Transition, f Output, g

Initial is s0

What outputs with these inputs: ababbab aaabbbba aabaaaabab

Page 13: Copyright © 2011-2014 - Curt Hill Finite State Machines The Simplest and Least Capable Automaton.

Other Way• Given a FSM and an input we

should be able to show the output• Can we go the other way?

– Given a language can we compute the FSM?

• How do we specify that language?

Copyright © 2011-2014 - Curt Hill

Page 14: Copyright © 2011-2014 - Curt Hill Finite State Machines The Simplest and Least Capable Automaton.

Problem• We want an FSM that takes a bit

string and outputs a modified bit string

• If we number the bits from 1 – Odd bits are output unchanged– Even bits are reversed

• Lets pause a moment and consider what the state table would look like

Copyright © 2011-2014 - Curt Hill

Page 15: Copyright © 2011-2014 - Curt Hill Finite State Machines The Simplest and Least Capable Automaton.

Output Example

Copyright © 2011-2014 - Curt Hill

s0s1

1,1

1,0

s0

s1

10

s1

s0

s1

s0

Transition, f Output, g

Initial is s0

s0

s1

10

0

0

1

1

0,0

0,1

Page 16: Copyright © 2011-2014 - Curt Hill Finite State Machines The Simplest and Least Capable Automaton.

Finally• Several different machines• Mealy machines (G.H. Mealy) are

the output machines considered here

• Moore machines (E.F. Moore) gives an output based only on state– This is not Gordon Moore of Moore’s

Law

Copyright © 2011-2014 - Curt Hill

Page 17: Copyright © 2011-2014 - Curt Hill Finite State Machines The Simplest and Least Capable Automaton.

Exercises• 13.2

– 3, 5, 13, 19

Copyright © 2011-2014 - Curt Hill