cs480(prasad)l9fsa1 finite state automata. cs480(prasad)l9fsa2 formal specification of languages...

25
CS480(Prasad) L9FSA 1 Finite State Automata

Upload: princess-piggott

Post on 14-Dec-2015

223 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 1

Finite State Automata

Page 2: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 2

Formal Specification of Languages

• Generators• Context-free Grammars

• Regular Expressions

• Recognizers• Parsers, Push-down Automata

• Finite State Automata

• FSA is a mechanism to recognize a set of valid inputs before carrying out an action.

• FSA is a notation for describing a family of language recognition algorithms.

Page 3: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 3

OP

Parity Problem

)( )1(

)()0(

).(

1s. ofnumber even contains )(

:

}1,0{*

*

parityparity

parityparity

parity

parity

booleanparity

EP

1

10 0

Page 4: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 4

Basic Features

• Consumes the entire input string.• Remembers the parity of the bit string by

abstracting from the number of 1s in the string.• Finite amount of memory required for this

purpose.• Observe that counting requires unbounded memory,

while computing the parity requires very small and fixed amount of memory.

• Accepts/Rejects the input in a deterministic fashion.

Page 5: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 5

• State• Indicates the status of the machine after consuming

some portion of the input.

• Summarizes the history of the computation that is relevant to the future course of action.

• Initial / Start State• Final / Accepting state• State Transition

Even Parity Odd Parity

1

0

Page 6: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 6

Q: Finite set of states

Finite Alphabet

: Transition function

total function from Qx to Q

: Initial/Start State

F : Set of final/accepting state

Deterministic Finite State Automaton (DFA)

),,,,( 0 FqQM

0q

Page 7: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 7

Operation of the machine

• Read the current letter of input under the tape head.

• Transit to a new state depending on the current input and the current state, as dictated by the transition function.

• Halt after consuming the entire input.

0 0 1

0q

Input Tape

Finite Control

Page 8: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 8

, where],[ Qqq• Machine configuration:

• Yields relation:

• Language:

Associating Language with the DFA

]),,([ ],[ *M aqaq

} ],[ ],[ |{ *M0

* Fqqq

Page 9: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 9

Examples

Page 10: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 10

• Set of strings over {a,b} that contain bb

• Design states by parititioning *.• Strings containing bb q2

• Strings not containing bb– Strings that end in b q1

– Strings that do not end in b q0

– Initial state: q0– Final state: q2

)()( babbba

Page 11: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 11

q2

State Diagram and Table

q0 q1

ab

a

b

a

b a b

q0 q0 q1

q1 q0 q2

q2 q2 q2

}2{

},{

}2,1,0{

qF

ba

qqqQ

],1[],0[ * qaabq

Page 12: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 12

q0 q2

Strings over {a,b} that do not contain bb

q1

ab

a

b

a

b a b

q0 q0 q1

q1 q0 q2

q2 q2 q2

}1,0{

},{

}2,1,0{

qqF

ba

qqqQ

],0[],0[ * qbaq

Page 13: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 13

DFA for the complement of L given DFA for L

Let M = (Q,,,q0,F) be a DFA. Then,

M’ = (Q,,,q0,Q-F) is a DFA with

L(M’) = * - L(M).

Implication: Languages associated with DFAs are closed under complementation.

(Recall that languages associated with regular expressions are closed under union, concatenation, and Kleene Star operations, by definition.)

Page 14: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 14

Strings over {a,b} containing even number of a’s and odd number of b’s.

*

Ea Oa

Eb Ob ObEb

b

b

b

b

aaa a

[Oa,Ob]

[Ea,Eb] [Ea,Ob]

[Oa,Eb]

Page 15: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 15

(ab)*c

*

valid prefix invalid prefix

end_a

a

b

b

a,b,c

a,cc

Err

Eb Ea

Ec

end_b end_c

a,b,c

a

c

b

Page 16: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 16

(ab)*c

*

valid prefix invalid prefix

end_a

a

b

b

a,b,c

a,cc

Err

Eb Ea

Ec

end_b end_c

a,b,c

Page 17: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 17

Nondeterministic Finite Automata

qi qj

qkq

qi qja a

aDFA

NFA

a

relationsubset

function total)(:

function total :

QQ

QΡowQ

QQ

NFA

NFA

DFA

Page 18: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 18

• How do we associate a language with an NFA?• Every DFA is an NFA. However, does non-

determinism make NFAs strictly more expressive (powerful) than DFAs?

DFA: Unique computation for a given string

NFA: Accept if there exists an accepting computation

)()( DFAsLNFAsL

Page 19: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 19

q2

NFA State Diagram (Strings over {a,b} ending in bb)

q0 q1

a

b b

a b

q0 {q0} {q0,q1}

q1 {q2}

q2

}2{

},{

}2,1,0{

qF

ba

qqqQ

bbba )(

b

Page 20: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 20

],2[],1[],0[],0[ qbqbbqabbq

Halts in accepting state after consuming the input.

],0[],0[],0[],0[ qbqbbqabbq

],1[],0[],0[],0[ qbqbbqabbq

Halts in non-accepting state after consuming the input.

)(NFALabb

Page 21: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 21

NFA State Diagram (a U b)* bb (a U b)*

q2q0 q1

a

b b

b ba

q2q0 q1

a

b b

ba

a

DFA

Page 22: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 22

NFA for (a U b)* (aa U bb) (a U b)*

q2q0 q1

a

a a

b ba

q22q11b b

ba

Page 23: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 23

Introducing -transitions into NFA

• A -transition causes the machine to change its state non-deterministically, without consuming any input.

)(}){(: QPQ

)-()()( sNFALNFAsLDFAsL

Page 24: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 24

Closure Properties of NFA-s

M1

M1

M

M2

M2

LL(M1) U LL(M2)

LL(M1) LL(M2)

LL(M)*

Page 25: CS480(Prasad)L9FSA1 Finite State Automata. CS480(Prasad)L9FSA2 Formal Specification of Languages Generators Context-free Grammars Regular Expressions

CS480(Prasad) L9FSA 25

}|{for NFA niba ii

a0 a1

b1

a2

b2

a3

b3

a aa a

b

b b b

a3

b3

an

bn

This construction cannot be generalized to recognize

}0|{ iba ii

because the machine will have infinite number of states.

b b b