finite automaton variants - wmich.eduelise/courses/cs6800/mohamed-finite-autom… · • finite...

Post on 31-Jul-2020

8 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Finite Automaton VariantsFinite Automaton Variants

Mohamed M. El Wakil

mohamed@elwakil.netmohamed@elwakil.net

1

AgendaAgenda

• Finite State Automaton/Machine (FSA)Finite State Automaton/Machine (FSA)– State transition tables

Non deterministic Finite State Automaton(NFA)– Non‐deterministic Finite State Automaton(NFA)

– Two‐way Deterministic Finite Automaton (2FA)

Fi it St t T d• Finite State Transducer– Mealy machine

– Moore machine

2

Finite State Automaton/MachineFinite State Automaton/Machine

• It is a model of computation that consists of:– States

• Start/Initial state• Acceptance states

h• Other states– Transitions 

• Moving from a state to anotherInp t string– Input string

• Finite set of symbols– Actions

• Entry action• Entry action• Exit action• Transition action• Input actionp

3

Recognition/AcceptanceRecognition/Acceptance

• A FSA is said to recognize or accept an inputA FSA is said to recognize, or accept an input string, if it ends at an acceptance state, and the whole input string has been processedthe whole input string has been processed.

4

Example• This machine has 7 states, 8 transitions, and 0 actions.

• State “Start” is the start state. 

• If the input is the word “nice” this machine• If the input is the word  nice , this machine will end at the state “Success”, otherwise it will end at the “Error” statewill end at the  Error  state.

5

Transitions• A transition is a move from a state A to another state B• A transition is a move from a state A to another state B based on the current state (i.e. A), and the current symbol of the input string. 

• Transitions can be viewed as a function with two inputs (current state, and current input symbol), and one(current state, and current input symbol), and one output (next state). For example: – (S1, “n”)  S2(S1 “not n”) S6– (S1,  not_n )  S6

• When a symbol is input to a transition function, it is said to be consumed.

• Symbols in the input string are consumed from left to• Symbols in the input string are consumed from left to right.

6

State Transition TableState Transition Table

• Transition functions are expressed via stateTransition functions are expressed via state transition tables.

• State transition tables can be either oneState transition tables can be either one dimension or two dimensions.

• This machine accepts– 1111000 1010 and 0001111000, 1010, and 000

• but, does not accept– 1001 111 or 0011001, 111, or 001

7

State Transition Tables• One dimension table:

Input Current State Next State

0 P Q

0 Q R0 Q R

0 R S

1 P  P

1 Q  R

1 R  ‐

• Two dimension tables:Input 0 1Input

State0 1

P Q P

NextCurrent

P Q R S

P 1 0 ‐ ‐

Q R R

R S ‐

Q ‐ ‐ {0,1} ‐

R ‐ ‐ ‐ 0 8

Mathematically speakingMathematically speaking

• A finite state machine is quintuple (Σ S s0 δ F):A finite state machine is quintuple (Σ,S,s0,δ,F):– Σ: Finite non‐empty set of symbols (Input).

S: Finite non empty set of states (States)– S: Finite, non‐empty set of states    (States).

– S0: Initial state S0 belongs to S         (Start state).  

F S t f fi l t t b t f S– F: Set of final states, a subset of S.

– δ: Transition function                         (Transitions)δ S Σ S• δ: S x Σ  S

9

Non‐deterministic Finite State h ( )Machine (NFA)

• The FSA is deterministic IfThe FSA is deterministic, If– for each pair of state and input symbol there is one and only one transition to a next stateone and only one transition to a next state.

• The FSA is non deterministic if• The FSA is non‐deterministic, if– it is allowed for a pair of state and input symbol to have more than one possible next state or ahave more than one possible next state, or a transition can take place without consuming input symbol (ε transitions)y ( )

10

NFA Example 1NFA Example 1

• This machine is non‐deterministic as for theThis machine is non deterministic as for the pair (P,0), there is more than one possible next state (P and Q)state (P, and Q)

InputState

0 1

P P,Q P

Q R R

R S ‐R S

11

NFA Example 2NFA Example 2

• This machine is non‐deterministic it can moveThis machine is non deterministic it can move from state Q to state R, without consuming any inputany input.

InputState

0 1 ε

P Q P ‐

Q ‐ R R

R S ‐ ‐

12

Deterministic Vs. Non‐deterministic / hFinite State Automaton/Machine

• NFA– Easier to design– Harder to implementSl– Slower

– Smaller

• DFA– Easier to implement– Harder to design– Faster– Bigger– Bigger

13

Two‐way Finite AutomatonTwo way Finite Automaton

• In DFA, input can be read only once from left to right., p y g

• In 2DFA, input can be read back and forth with no limit on how many times an input symbol can be read.

A 2DFA i li ti f th DFA• A 2DFA is a generalization of the DFA.

• Transition functions in 2DFA outputs a new state and• Transition functions in 2DFA, outputs a new state, and a direction (left, right, or stand still)

14

DFA Vs. 2DFADFA Vs. 2DFA

• 2DFA can solve any problem solvable by DFA2DFA can solve any problem solvable by DFA.– Why?

• Also problems solvable by a 2DFA can be• Also, problems solvable by a 2DFA, can be solved by a DFA1. 

• But, 2DFA is – much simpler, and

– more realistic.

1M. O. Rabin and D. Scott, “Finite automata and their decision problems”, IBM Journal of Research and Development, 3 (1959), 114–125.

15

Finite State Transducers (FST)Finite State Transducers (FST)

• A FSA can be viewed as a function that maps anA FSA can be viewed as a function that maps an input string into the set {0,1}, {True, False}, {Accept Reject}{Accept, Reject}… 

A FST i ( i )• A FST may generate a new string (output string) while consuming the input string.

• A FST is a FSA with actions producing output!p g p

16

FST ExampleFST Example

• This machine outputs the one’s complementThis machine outputs the one s complement of its input, while it is recognizing this input.

• For input 000, it outputs 111

• For input 1010, it outputs 0101 

17

FST variantsFST variants

• A FST may be non‐deterministic if it canA FST, may be non deterministic, if it can produce more than one output string for a given input stringgiven input string.

• A FST is either a Mealy machine or a Moore• A FST is either a Mealy machine, or a Moore machine.

18

Mealy MachinesMealy Machines

• A Mealy machine is finite state transducer thatA Mealy machine is finite state transducer that produces an output for each transition (i.e has input actions)input actions)

E l• Example: 

19

Moore MachinesMoore Machines

• A Moore machine is finite state transducerA Moore machine is finite state transducer that produces an output for each state it enters (i e has entry actions)enters (i.e. has entry actions)

E l• Example:– We have to add a new state X

20

Mathematically speakingMathematically speaking

• A finite state transducer is a sextuple (Σ Γ S S0 δ ω):A finite state transducer is a sextuple (Σ, Γ,S,S0,δ, ω):– Σ: Finite non‐empty set of symbols (Input).

– Γ: Finite non‐empty set of symbols (Output).Γ: Finite non empty set of symbols (Output).

– S: Finite, non‐empty set of states    (States).

– S0: Initial state S0 belongs to S (Start state).S0: Initial state S0 belongs to S         (Start state).  

– δ: Transition function                         (Transitions)• δ: S x Σ  S

– ω: Output function• ω: S x Σ  Γ (Mealy machine)

• ω: S  Γ (Moore machine)

21

top related