class2

64
1 Finite Automata Finite Automata

Upload: issbp

Post on 20-Nov-2014

270 views

Category:

Documents


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Class2

11

Finite AutomataFinite Automata

Page 2: Class2

22

FiniteFinite AutomatonAutomatonInput

String

Output

String

FiniteAutomaton

A string over a given alphabet written on an input file

A control unit consisting of a finite number of internal states

The internal state at the next time step is determined by the transition function

Page 3: Class2

33

FiniteFinite AccepterAccepter

Input

“ Accept” or“Reject”

String

FiniteAutomaton

Output

Page 4: Class2

44

Input String of

Internal states

FiniteFinite AccepterAccepter

““ Accept”Accept”

oror

““Reject”Reject”

q0

q1

q2

q3

q4

q5

Initial state

final state

Page 5: Class2

55

FormalitiesFormalitiesDeterministic Finite Accepter (DFA)

(p.38)

FqQM ,,,, 0Q

0q

F

: set of internal states

: input alphabet

: Q × Q transition function

: initial state

: set of final states

Page 6: Class2

66

configuration

Input String

Internal states

FiniteFinite AccepterAccepter

“ Accept” or“Reject”

q0

q1

q2

q3

q4

q5

abba

a ab b

Leftmost position

initial state

: a particular status of the input file and internal stateInitial

×

Page 7: Class2

77

Internal states

“ Accept” or“Reject”

q0

q1

q2

q3

q4

q5

a ab b 10 , qaq Transition function

current state current input symbol

move to the next state

Next state

At q0 now check for current symbol-

×

Page 8: Class2

88

Internal states

“ Accept” or“Reject”

q0

q1

q2

q3

q4

q5

a ab b 21, qbq Transition function

current state current input symbol

Next state

move to the next state

At q1 now check for current symbol-

×

Page 9: Class2

99

Internal states

“ Accept” or“Reject”

q0

q1

q2

q3

q4

q5

a ab b 32 , qbq Transition function

At q2 now check for current symbol-

×

Page 10: Class2

1010

Internal states

“ Accept” or“Reject”

q0

q1

q2

q3

q4

q5

a ab b 43 , qaq Transition function

At q3 now check for current symbol-

×

Page 11: Class2

1111

Internal states

“ Accept” or“Reject”

q0

q1

q2

q3

q4

q5

a ab b No symbol left and it stops at final state

The string abba is accepted by the machine.

At q4 now check for current symbol-

×

Page 12: Class2

1212

Transition functions are the most important part for a finite accepter.

We use a transition graph to represent a finite accepter such that Node state, and Edge with label transition function

(current symbol)

Transition Graph Transition Graph GGMM

Page 13: Class2

1313

32 , qbq Transition Graph forTransition Graph for

current state current input symbol

Next state

q2 q3b

Initial state

Final state qf

q0

Page 14: Class2

1414

Transition Graph

initialstate

final

state

“accept”statetransition

abba –Finite Accepter

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

32 , qbq It is important to have a clear and intuitive picture to work with DFA. Transition graph: vertices > states, edges > transitions

Page 15: Class2

1515

Initial ConfigurationInitial Configuration

Input Stringa b b a

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

Page 16: Class2

1616

Reading the InputReading the Input

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

One at a time from left to right

a b b a

Page 17: Class2

1717

a b b a

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

a b b a

Page 18: Class2

1818

a b b a

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

a b b a

Page 19: Class2

1919

a b b a

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

a b b a

Page 20: Class2

2020

Output: “accept”

a b b a

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

Input finished

a b b a

Page 21: Class2

2121

Another Example: Another Example: abaaba

a b a

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

Page 22: Class2

2222

a b a

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

Initial ConfigurationInitial Configuration

a b a

Page 23: Class2

2323

a b a

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

a b a

Page 24: Class2

2424

a b a

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

a b a

Page 25: Class2

2525

a b a

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

a b a

Page 26: Class2

2626

Output:“reject”

a b a

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

Input finished

a b a

Page 27: Class2

2727

Another Input StringAnother Input String

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

Page 28: Class2

2828

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

Output:“ reject”

End of input!

Page 29: Class2

2929

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

A Trap StateA Trap State

GGMM

It is important to have a clear and intuitive picture to work with DFA. Transition graph: vertices > states, edges > transitions

Page 30: Class2

3030

What are Q, , , q0, F?

A Deterministic Finite Accepter or DFA is defined as (Def. 2.1 p.38)

FqQM ,,,, 0

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

GGMM

It is important to have a clear and intuitive picture to work with DFA. Transition graph: vertices > states, edges > transitions

Page 31: Class2

3131

InputInput AlphabetAlphabet

ba,

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

Page 32: Class2

3232

SetSet ofof StatesStates

Q

543210 ,,,,, qqqqqqQ

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

Page 33: Class2

3333

InitialInitial StateState

0q

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

Page 34: Class2

3434

SetSet ofof FinalFinal StatesStates

F

4qF

0q 1q 2q 3qa b b a

5q

a a bb

ba,

ba,

4q

Page 35: Class2

3535

TransitionTransition FunctionFunction

QQ :

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

By Transition Graph

GM

Page 36: Class2

3636

What does “deterministic” mean?What does “deterministic” mean?

Other than using Other than using transition graph transition graph GGMM to represent a to represent a

transition function, there are two common ways to transition function, there are two common ways to represent a transition function.represent a transition function.

is a total function

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,GM

FqQM ,,,, 0

It is important to have a clear and intuitive picture to work with DFA. Transition graph: vertices > states, edges > transitions

Page 37: Class2

3737

TransitionTransition FunctionFunction

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

10 , qaq 50 , qbq

51, qaq 21, qbq

52 , qaq 32 , qbq

43 , qaq 53 , qbq

54 , qaq 54 , qbq

55 , qaq 55 , qbq

Page 38: Class2

3838

TransitionTransition FunctionFunction

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

a b

0q

1q

2q

3q

4q

5q

1q 5q

5q 2q

5q 3q

4q 5q

5q5q5q5q

Page 39: Class2

3939

ExtendedExtended Transition Transition Function Function

*QQ *:*

QQ :Transition Transition functionfunction

including including

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

Page 40: Class2

4040

20 ,* qabq

3q 4qa b b a

5q

a a bb

ba,

ba,

0q 1q 2q

QQ *:*

Page 41: Class2

4141

40 ,* qabbaq

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

Page 42: Class2

4242

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

50 ,* qabbbaaq

Page 43: Class2

4343

Extended Transition Extended Transition Function Function

)),,(*(),(*

,),(*

awqwaq

qq

Recursive DefinitionRecursive Definition

for all for all qq Q, w Q, w*, a*, a

QQ *:*

Page 44: Class2

4444

RecursiveRecursive DefinitionDefinition

)),,(*(,*

,*

awqwaq

qq

q qwa

)),,(*(,* awqwaq

qwaq ,*If

1

1

,*

),(,*

qwq

and

aqwaq

then a state, say q1, such that

aq qw1q

Page 45: Class2

4545

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0,

2q

q

1 ,bq

, ,ba0q , 0 ,,* baq

* b 0 ),,( aq * ab

)),,(*(,*

,*

wqwq

qq

Page 46: Class2

4646

qwq ,*kw ...21

In the DFA M, there iswith

q q1 2 k

There is a walk in GM

from to with labelq q

q qw

kw ...21

Page 47: Class2

4747

q q1 2 k

There is a walk in GM

from to with labelq q

q qw

kw ...21

qwq ,*In the DFA M, there iswith kw ...21

Page 48: Class2

4848

q q1 2 k

There is a walk in GM

from to with labelq q

q qw

kw ...21

qwq ,*In the DFA M, there iswith kw ...21

Theorem 2.1Theorem 2.1

Page 49: Class2

4949

50 ,* qabbbaaq

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

There is a walk from to with label

0qabbbaa

5q

If and only if

Page 50: Class2

5050

LanguagesLanguages AcceptedAccepted byby DFAsDFAs

Take DFA

Definition: (p.40)

The language contains all input strings accepted by

= { strings that drive to a final state}

M

MLM

ML

= { = { w w * : * : *(*(qq00, , ww)) FF } }

FqQM ,,,, 0

Page 51: Class2

5151

ExampleExample

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

abbaML

M

acceptaccept

back to complement Ex. p.51

Page 52: Class2

5252

AnotherAnother ExampleExample

abbaabML ,,

M

acceptaccept

0q 1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

acceptacceptacceptaccept

Page 53: Class2

5353

Formally, for a DFA Formally, for a DFA

Since M is DFA, every w*, corresponding to a unique walk in the transition graph of M.

If

If

qwq ,* 0

FqQM ,,,, 0

0q qwFq )(MLw

Fq )(MLw

qw0q

Page 54: Class2

5454

ObservationObservation Language rejected by :

FwqwML ,*:* 0

M

Fq

What is the complement of language on example (p.48)?Example on p.48

qw0q

Page 55: Class2

5555

Examples on Constructing Examples on Constructing DFAsDFAs

}0:{ nbaML n

a

b ba,

ba,

0q 1q 2q

accept trap state

Page 56: Class2

5656

= { all strings with prefix }ab ML

accept

a b

ba,

0q 1q 2q

ba,3q

ab

Page 57: Class2

5757

= { all strings without substring 001} ML

001 0 00

1

0

1

10

0 1,0

What if consider DFA for {strings with What if consider DFA for {strings with 001}?001}?

Page 58: Class2

5858

RegularRegular LanguagesLanguages

A language is regular if there is a DFA such that

All regular languages form a language family

LM MLL

Page 59: Class2

5959

abba abbaab,,

}0:{ nban

{ all strings with prefix }{ all strings with prefix }ab

{ all strings without substring }{ all strings without substring }001

Examples of regular languages:

There exist automata that accept theseLanguages (see previous slides).

Page 60: Class2

6060

abbaIs the complement of also regular?

How can you show that the complement of a regular language is regular? (referring to Hw# 3, 4 on p.47)

Page 61: Class2

6161

AnotherAnother ExampleExample

The language is regular

*,: bawawaL

a

a

b a

b

b

0q 2q 3q

ba,

4q

MLL

since we can find a DFA M such that

L*=L {}

Page 62: Class2

6262

AnotherAnother ExampleExample

The language is regular. How about L2 ?

*,: bawawaL

Can you show LL* is a regular language?Try Hw # 20, 21, 22

Page 63: Class2

6363

Is Is L?L?

If there is a DFA M for L, can you tell if L?

If L is regular, then how about L-{}?

Try hw #17 & 18 p.48

How can you construct a DFA for L-{How can you construct a DFA for L-{} } fromfrom the DFA of L? the DFA of L? How can you construct a DFA for LHow can you construct a DFA for L{{} } from from the DFA of L? the DFA of L?

Page 64: Class2

6464

Homework 2.1 Homework 2.1 p.47

Try: 1 ~7, 9, 11~25 Hand in: 2bd, 4, 6, 7e, 9bf, 18

For hw18, state the general method then use the example to illustrate the method where L {a,b}*L= {w: w= or w contains a substring “ab”}