Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Finite Automata 1 Representation Application and Examples.

Similar presentations

Presentation on theme: "1 Finite Automata 1 Representation Application and Examples."— Presentation transcript:

1 1 Finite Automata 1 Representation Application and Examples

2 2 What are FA? uFinite automata are finite collections of states with transition rules that take you from one state to another.

3 3 Representing FA uSimplest representation is a graph. wNodes = states. wArcs indicate state transitions. wLabels on arcs tell what causes the transition.

4 FA model of on-off switch 4 off push on Start push

5 5 Protocol for Sending Data ReadySending data in done timeout Start

6 6 FA Recognizing Strings Ending in “ing” emptySaw i i Not i Saw ing g i Not i or g Saw in n i Not i or n Start Double circle denotes “finish” or “accepting” state Get next character in any state except the finish state Where we go depends on which character String recognized may not be the entire input

7 7 Automata to Code uIn C/C++, make a piece of code for each state that does the following 1.Reads the next input. 2.Decides on the next state. 3.Jumps to the beginning of the code for that state.

8 8 Code for state “saw i” 2: /* i seen */ c = getNextInput(); if (c == ’n’) goto 3; else if (c == ’i’) goto 2; else goto 1; 3: /* ”in” seen */...

9 E-commerce example uE-commerce requires protocols to prevent fraud uProtocols can be modeled by finite automata uExample: protocol to ensure that e- money is transferred from customer to merchant on shipped purchases 9

10 E-commerce 2 uPay does not change state of customer. Free to cancel order uBank can go down either cancel path or path that leads to e-money transfer following a redeem request from e-store 10 pay cancel customer cancel start redeem transfer bank

11 E-commerce 3 uStore preferred path a->b->c->f->g uAlternate paths allow ship before transfer complete 11 a redeem start b c f c eg pay redeem ship transfer ship transfer store

12 This representation is not complete 12 a redeem start b c f c eg pay redeem ship transfer ship transfer cancel start redeem transfer pay cancel All parts must have a defined response to every input even if the response is no change of state.

13 13 P,C,R,S,T a R start b c f c eg P R S T S S T C P,C C start RT P,S P,C,R,S Each loop labeled by actions that do not change states P=pay C=cancel R=redeem S=ship T=transfer

14 14 P,C,S,R,T a R start b c f c eg P R S T S S T C P,C C start RT P,S P,C,R,S Customer is in a “free” state No interactions between store and bank can change customer’s state

15 Analysis of Store-Bank interactions reveals paths to failure of e-protocols uAnalysis requires “product” FA with all possible combinations of (store, bank) states and paths that connect them. uWill discuss construction of product FAs later in course 15

16 Store-Bank product FA 16 Paths exist to state (c,2) that has no exit. Customer cancelled and store shipped before transfer of payment from bank.

17 17

18 18 P,C,S,R,T a R start b c f c eg P R S T S S T C P,C C start RT P,S P,C,R,S Analysis of protocol using FA If customer state is C, then interactions between store and bank can lead to failure

19 19 a R start b c f c eg P R S T S S T C P,C C start RT P,S P,C,R,S Store-Bank product automaton 3 State (c,2) is case where store has shipped before redeeming payment from bank and customer has canceled Product automaton reveals problem with the protocol. State (c,2) is accessible from (a,1) but only loops back.

20 20 Far out example uOn a distant planet, there are three species, a, b, and c. uAny two different species can mate. If they do: 1.The participants die. 2.Two children of the third species are born.

21 21 Strange Planet – (2) uObservation: the number of individuals never changes. uThe planet fails if at some point all individuals are of the same species. wThen, no more breeding can take place. uState = sequence of three integers – the numbers of individuals of species a, b, and c.

22 22 Strange Planet – Questions uIn a given state, must the planet eventually fail? uIn a given state, is it possible for the planet to fail, if the wrong breeding choices are made?

23 23 Relationship to Computers uThese questions mirror real ones about protocols. uPlanet “failure” is like protocol “termination” uWe want protocols to terminate w“Must the planet fail” is like asking whether a protocol, in its current state, is guaranteed to terminate.

24 24 Strange Planet – Transitions uAn a-event occurs when individuals of species b and c breed and are replaced by two a’s. uAnalogously: b-events and c-events. uRepresent these by symbols a, b, and c, respectively.

25 25 Strange Planet with 2 Individuals acb all states are “must-fail” all possible events lead to states where have all same species analogous to “termination” states automata

26 26 “Meta-states” are populations of different size acb This analysis of a “meta-state” consist of “exhaustive enumeration”. List all possible species distributions. For each distribution, list all possible transitions.

27 27 Strange Planet with 3 Individuals ac b “can’t-fail” states are parts of cycles a c bb a c “must-fail” state

28 28 Strange Planet with 4 Individuals “might-fail” states appear Some breeding choices lead to termination Others lead to a cycle a cb bc a b ac ca b c ba ab c

29 29 Taking Advantage of Symmetry uIn exhaustive enumeration of meta- states, we see repeated patterns. uNodes and edges have different labels but topology is same acb

30 30 Taking Advantage of Symmetry 2 Outcome (termination) is the same regardless of which species is extinct and which 2 have a single individual acb

31 31 Taking Advantage of Symmetry 3 Develop a “prototype” that illustrates states and transitions allowed for populations of various size List species-specific populations in decreasing order Replace specific type of transition (a, b, c) with x acb x prototype

32 Prototypes for 2, 3, x x x x x x x The “might-fail” state of prototype 4 is a nondeterminism. Different transitions are possible from 211 on the same input.

33 33 Prototype for meta-state Drop the unnecessary edge label “x” Prototype has standard form of a directed graph Basic graph algorithms can find cycles 1 must-fail state; 1 can’t fail cycle; 1 might fail state

34 34 Strange planet example illustrates u3 types of states you could find in finite automata: must terminate, might terminate and can’t terminate uMethods of analysis to find those states: exhaustive enumeration and graph theory

Download ppt "1 Finite Automata 1 Representation Application and Examples."

Similar presentations

Ads by Google