Formal Languages Finite Automata

Post on 19-Jan-2016

99 Views

Category:

Documents

25 Downloads

Preview:

Click to see full reader

DESCRIPTION

Formal Languages Finite Automata. Chomsky Hierarchy. Type-0 : Unrestricted;recursively enumerated; phrase structured; turing m/c Type-1: CSL;LBA Type-2: CFL;PDA Type-3:RL:FA. Finite Automaton. Input. String. Output. “Accept” or “Reject”. Finite Automaton. Transition Graph. - PowerPoint PPT Presentation

Transcript

Fall 2004 Costas Busch - RPI

Formal Languages

Finite Automata

2

Type-0 : Unrestricted;recursively enumerated; phrase structured; turing m/c

Type-1: CSL;LBAType-2: CFL;PDAType-3:RL:FA

Chomsky Hierarchy

3

Finite Automaton

Input

“Accept” or“Reject”

String

FiniteAutomaton

Output

4

Transition Graph

initialstate

accepting state

statetransition

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

5q

a a bb

ba,

ba,

5

Initial Configuration

1q 2q 3q 4qa b b a

5q

a a bb

ba,

Input Stringa b b a

ba,

0q

6

Reading the Input

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

5q

a a bb

ba,

a b b a

ba,

7

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

5q

a a bb

ba,

a b b a

ba,

8

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

5q

a a bb

ba,

a b b a

ba,

9

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

5q

a a bb

ba,

a b b a

ba,

10

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

accept

5q

a a bb

ba,

a b b a

ba,

Input finished

11

Rejection

1q 2q 3q 4qa b b a

5q

a a bb

ba,

a b a

ba,

0q

12

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

5q

a a bb

ba,

a b a

ba,

13

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

5q

a a bb

ba,

a b a

ba,

14

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

5q

a a bb

ba,

a b a

ba,

15

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

5q

a a bb

ba,

reject

a b a

ba,

Input finished

16

Acceptance or Rejection?

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

17

Initial State

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

18

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

reject

Rejection

19

Language?

a

b ba,

ba,

0q 1q 2q

20

Another Example

a

b ba,

ba,

0q 1q 2q

a ba

21

a

b ba,

ba,

0q 1q 2q

a ba

22

a

b ba,

ba,

0q 1q 2q

a ba

23

a

b ba,

ba,

0q 1q 2q

a ba

24

a

b ba,

ba,

0q 1q 2q

a ba

accept

Input finished

25

Rejection Example

a

b ba,

ba,

0q 1q 2q

ab b

26

a

b ba,

ba,

0q 1q 2q

ab b

27

a

b ba,

ba,

0q 1q 2q

ab b

28

a

b ba,

ba,

0q 1q 2q

ab b

29

a

b ba,

ba,

0q 1q 2q

ab b

reject

Input finished

30

Languages Accepted by FAsFA

Definition:The language contains all input strings accepted by

= { strings that bring to an accepting state}

M

MLM

M ML

31

Example: L(M) = ?

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

5q

a a bb

ba,

ba,

M

accept

32

Example

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

5q

a a bb

ba,

ba,

M

accept

33

Example: L(M) = ?

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

5q

a a bb

ba,

ba,

M

acceptacceptaccept

34

Example

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

5q

a a bb

ba,

ba,

abbaabML ,, M

acceptacceptaccept

35

Example: L(M) = ?

a

b ba,

ba,

0q 1q 2q

accept trap state

36

Example

a

b ba,

ba,

0q 1q 2q

}0:{ nbaML n

accept trap state

37

Formal Definition Finite Automaton (FA)

FqQM ,,,, 0

Q

0q

F

: set of states

: input alphabet

: transition function

: initial state

: set of accepting states

38

Input Alphabet

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

5q

a a bb

ba,

ba,

ba,

39

Set of States

Q

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

5q

a a bb

ba,

543210 ,,,,, qqqqqqQ

ba,

40

Initial State

0q

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

41

Set of Accepting States

F

0q 1q 2q 3qa b b a

5q

a a bb

ba,

4qF

ba,

4q

42

Transition Function

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

5q

a a bb

ba,

QQ :

ba,

43

10 , qaq

2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q 1q

44

50 , qbq

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

45

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

5q

a a bb

ba,

ba,

32 , qbq

46

Transition Function

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

5q

a a bb

ba,

a b

0q

1q

2q

3q

4q

5q

1q 5q

5q 2q

5q 3q

4q 5q

ba,5q5q5q5q

47

Extended Transition Function

*

QQ *:*

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

5q

a a bb

ba,

ba,

48

20 ,* qabq

3q 4qa b b a

5q

a a bb

ba,

ba,

0q 1q 2q

49

40 ,* qabbaq

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

5q

a a bb

ba,

ba,

50

50 ,* qabbbaaq

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

51

qwq ,*

Observation: if there is a walk from to with label then

q qw

q qw

q qkw 21

1 2 k

52

50 ,* qabbbaaq

1q 2q 3q 4qa b b a

5q

a a bb

ba,

ba,

0q

Example: There is a walk from to with label

0qabbbaa

5q

53

Recursive Definition )),,(*(,*

,*

wqwq

qq

q qw1q

qq

qwq

),(

,*

1

1

1

,*

),(,*

qwq

qwq

)),,(*(,* wqwq

54

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

5q

a a bb

ba,

ba,

2

1

0

0

0

0

,

,,

,,,*

),,(*

,*

q

bq

baq

baq

baq

abq

55

Language Accepted by FAs

For a FA

Language accepted by :

FqQM ,,,, 0

M

FwqwML ,*:* 0

0q qw Fq

56

ObservationLanguage rejected by :

FwqwML ,*:* 0

M

0q qw Fq

57

L(M) ? ab

a b

ba,

0q 1q 2q

accept

ba,3q

ab

58

Example ML = { all strings with prefix }ab

a b

ba,

0q 1q 2q

accept

ba,3q

ab

59

0 00 001

1

0

1

10

0 1,0

L(M)?

60

Example ML = { all strings without

substring }001

0 00 001

1

0

1

10

0 1,0

61

a

b

ba,

a

b

ba

0q 2q 3q

4q

L(M) ?

62

Example

*,:)( bawawaML

a

b

ba,

a

b

ba

0q 2q 3q

4q

63

Regular LanguagesDefinition:A language is regular if there is FA such that

Observation:All languages accepted by FAs form the family of regular languages

LM MLL

64

abba abbaab,,}0:{ nban

{ all strings with prefix }ab

{ all strings without substring }001

Examples of regular languages:

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

*,: bawawa

65

There exist languages which are not Regular:

}0:{ nbaL nn

There is no FA that accepts such a language

Example:

top related