24
Finite State Automaton By : AmmAr mobark Second stage Software department Babylon university Information Technology collage JAN. 2017

Finite state automaton

Embed Size (px)

Citation preview

Page 1: Finite state automaton

Finite State Automaton

By:AmmAr mobark

Second stage Software department

Babylon universityInformation

Technology collage

JAN. 2017

Page 2: Finite state automaton

Index• Introduction• The historical of finite state automaton• Types of finite state automaton• The advantages and disadvantages of finite state automaton• examples for finite state automaton

Page 3: Finite state automaton

Introduction Definition of finite state automaton: computation. It is an abstract

machine that can be in exactly one of a finite number of states at any given time. The FSM can change from one state to another in response to some external inputs; the change from one state to another is called a transition. A FSM is defined by a list of its states, its initial state, and the conditions for each transition.

Page 4: Finite state automaton

Introduction The behavior of state machines can be observed in many devices in

modern society that perform a predetermined sequence of actions depending on a sequence of events with which they are presented. Examples are vending machines, which dispense products when the proper combination of coins is deposited, elevators, whose sequence of stops is determined by the floors requested by riders, traffic lights, which change sequence when cars are waiting, and combination locks, which require the input of combination numbers in the proper order.

Page 5: Finite state automaton

Introduction The finite state machine has less computational power than some other

models of computation such as the Turing machine. The computational power distinction means there are computational tasks that a Turing machine can do but a FSM cannot. This is because a FSM's memory is limited by the number of states it has. FSMs are studied in the more general field of automata theory.

Page 6: Finite state automaton

The historical of finite state automaton

Systems which could transition between a finite number of internal states have been known of for a long time, but it was not until relatively late in the early history of computer science that they were formally studied.

The following quotes are from Rabin and Scott ,"Finite automata and their decision problems "

"Turing machines are widely considered to be the abstract prototype of digital computers; workers in the field, however, have felt more and more that the notion of a Turing machine is too general to serve as an accurate model of actual computers. It is well known that even for simple calculations it is impossible to give an a priori upper bound on the amount of tape a Turing machine will need for any given computation. It is precisely this feature that renders Turing's concept unrealistic."

Page 7: Finite state automaton

The historical of finite state automaton

"In the last few years the idea of a finite automaton has appeared in the literature. These are machines having only a finite number of internal states that can be used for memory and computation. The restriction of finiteness appears to give a better approximation to the idea of a physical machine. Of course, such machines cannot do as much as Turing machines, but the advantage of being able to compute an arbitrary general recursive function is questionable, since very few of these functions come up in practical applications."

Page 8: Finite state automaton

Types of finite state automatonFinite automata may have outputs corresponding to each transition. There are two types of finite state machines that generate output • Mealy Machine• Moore machine

Page 9: Finite state automaton

A Mealy Machine is an FSM whose output depends on the present state as well as the present input.It can be described by a 6 tuple (Q, ∑, O, δ, X, q0) where• Q is a finite set of states.• ∑ is a finite set of symbols called the input alphabet.• is a finite set of symbols called the output alphabet.• δ is the input transition function where δ: Q × ∑ → Q• X is the output transition function where X: Q × ∑ → O• q0 is the initial state from where any input is processed (q0 Q).∈

Types of finite state automatonMealy Machine

Page 10: Finite state automaton

The state table of a Mealy Machine is shown below

Types of finite state automatonMealy Machine

Present state

Next state

input = 0 input = 1

State Output State Output

→ a B x1 C x1

B B x2 D x3

C D x3 C x1

D D x3 D x2

Page 11: Finite state automaton

The state diagram of the above Mealy Machine is

Types of finite state automatonMealy Machine

Page 12: Finite state automaton

Moore machine is an FSM whose outputs depend on only the present state. A Moore machine can be described by a 6 tuple (Q, ∑, O, δ, X, q0) where • Q is a finite set of states.• ∑ is a finite set of symbols called the input alphabet.• is a finite set of symbols called the output alphabet.• δ is the input transition function where δ: Q × ∑ → Q• X is the output transition function where X: Q → O• q0 is the initial state from where any input is processed (q0 Q).∈

Types of finite state automatonMoore Machine

Page 13: Finite state automaton

The state table of a Moore Machine is shown below

Types of finite state automatonMoore Machine

Present state

Next State

OutputInput = 0 Input = 1

→ a b c x2

b b d x1

c c d x2

d d d x3

Page 14: Finite state automaton

The state diagram of the above Moore Machine is

Types of finite state automatonMoore Machine

Page 15: Finite state automaton

The following table highlights the points that differentiate a Mealy Machine from a Moore Machine.

Types of finite state automatonMealy Machine vs. Moore Machine

Mealy Machine Moore Machine

Output depends both upon present state and present input.

Output depends only upon the present state.

Generally, it has fewer states than Moore Machine.

Generally, it has more states than Mealy Machine.

Output changes at the clock edges. Input change can cause change in output change as soon as logic is done.

Mealy machines react faster to inputs In Moore machines, more logic is needed to decode the outputs since it has more circuit delays.

Page 16: Finite state automaton

Algorithm 4Input − Moore MachineOutput − Mealy MachineStep 1 − Take a blank Mealy Machine transition table format.Step 2 − Copy all the Moore Machine transition states into this table format.Step 3 − Check the present states and their corresponding outputs in the Moore Machine state table; if for a state Qi output is m, copy it into the output columns of the Mealy Machine state table wherever Qi appears in the next state.

Types of finite state automatonMoore Machine to Mealy Machine

Page 17: Finite state automaton

Algorithm 5Input − Mealy MachineOutput − Moore MachineStep 1 − Calculate the number of different outputs for each state (Qi) that are available in the state table of the Mealy machine.Step 2 − If all the outputs of Qi are same, copy state Qi. If it has n distinct outputs, break Qi into n states as Qin where n = 0, 1, 2.......Step 3 − If the output of the initial state is 1, insert a new initial state at the beginning which gives 0 output.

Types of finite state automatonMealy Machine to Moore Machine

Page 18: Finite state automaton

The advantages and disadvantages

• Their simplicity make it easy for inexperienced developers to implement with little to no extra knowledge (low entry level)• Predictability (in deterministic FSM), given a set of inputs and a known

current state, the state transition can be predicted, allowing for easy testing• Due to their simplicity, FSMs are quick to design, quick to implement and

quick in execution• FSM is an old knowledge representation and system modeling technique, and

its been around for a long time, as such it is well proven even as an artificial intelligence technique, with lots of examples to learn from

Advantages of FSM

Page 19: Finite state automaton

The advantages and disadvantages

• FSMs are relatively flexible. There are a number of ways to implement a FSM based system in terms of topology, and it is easy to incorporate many other techniques• Easy to transfer from a meaningful abstract representation to a coded

implementation• Low processor overhead; well suited to domains where execution time is

shared between modules or subsystems. Only the code for the current state need be executed, and perhaps a small amount of logic to determine the current state.• Easy determination of reachability of a state, when represented in an abstract

form, it is immediately obvious whether a state is achievable from another state, and what is required to achieve the state

Advantages of FSM

Page 20: Finite state automaton

The advantages and disadvantages

• The predictable nature of deterministic FSMs can be unwanted in some domains such as computer games (solution may be non-deterministic FSM).• Larger systems implemented using a FSM can be difficult to manage and

maintain without a well thought out design. The state transitions can cause a fair degree of "spaghetti- factor" when trying to follow the line of execution• Not suited to all problem domains, should only be used when a systems

behavior can be decomposed into separate states with well defined conditions for state transitions. This means that all states, transitions and conditions need to be known up front and be well defined• The conditions for state transitions are ridged, meaning they are fixed (this

can be over come by using a Fuzzy State Machine (FuSM))

Disadvantages of FSM

Page 21: Finite state automaton

examples of finite state automatonStep 1: Describe the machine in words.

In this example, we’ll be designing a controller for an elevator. The elevator can be at one of two floors: Ground or First. There is one button that controls the elevator, and it has two values: Up or Down. Also, there are two lights in the elevator that indicate the current floor: Red for Ground, and Green for First. At each time step, the controller checks the current floor and current input, changes floors and lights in the obvious way.

Page 22: Finite state automaton

examples of finite state automatonStep 2: Draw the FSM diagram

In this diagram, the bubbles represent the states, and the arrows represent state transitions. The arrow labels indicate the input value corresponding to the transition. For instance, when the elevator is in the Ground state, and the input is Up, the next state is First. The information in the brackets indicates the output values for the lights in each state.

Page 23: Finite state automaton

examples of finite state automatonStep 3: Select numbers to represent states and values

Before converting the above FSM diagram to a circuit, we need to represent every value in our example as a binary number. Here is some convenient numbers to use.

Ground = 0 Down = 0 Off = 0First = 1 up = 1 no = 1

Page 24: Finite state automaton

examples of finite state automatonStep 4: Write the truth tableFrom the FSM diagram, it is easy to read off the correct truth table

green red Next state

input Current state

0 1 0 0 0

0 1 1 1 0

1 0 0 0 1

1 0 1 1 1