Top Banner
1 Languages and Finite Automata or how to talk to machines...
55

Languages and Finite Automata

Jan 07, 2016

Download

Documents

Reese

Languages and Finite Automata. or how to talk to machines. Languages. A language is a set of strings String: A sequence of letters (a word) Examples: “cat”, “dog”, “house”, … Defined over an alphabet: set of symbols (letters). Alphabets and Strings. We will use small alphabets Strings. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Languages and Finite Automata

1

Languages and Finite Automata

orhow to talk to machines...

Page 2: Languages and Finite Automata

2

A language is a set of strings

String:A sequence of letters (a word)

Examples: “cat”, “dog”, “house”, …

Defined over an alphabet:set of symbols (letters)

Languages

zcba ,,,,

Page 3: Languages and Finite Automata

3

Alphabets and StringsWe will use small alphabets

Strings

abbaw

bbbaaav

abu

ba,

baaabbbaaba

baba

abba

ab

a

Page 4: Languages and Finite Automata

4

String Operations

Concatenation

Reverse

abbaw

aaaw n

21

bbbaaav

bbbv m

21

abbabbbaaawv

bbbaaawv mn

2121

aaabbbv

bbbvR

mR

12

Page 5: Languages and Finite Automata

5

String Length

Length:

Examples:

naaaw 21

nw

1

2

4

a

aa

abba

Page 6: Languages and Finite Automata

6

Recursive Definition of LengthFor any letter:

For any string :

Example:

1a

1wwawa

4

1111

111

11

1

a

ab

abbabba

Page 7: Languages and Finite Automata

7

Length of Concatenation

Example:

vuuv

853

8

5,

3,

vuuv

aababaabuv

vabaabv

uaabu

Page 8: Languages and Finite Automata

8

Proof of Concatenation LengthClaim:

Proof:By induction on the length

Induction basis:

is only one symbol

From definition of length:

vuuv

v

1v

vuuuv 1

v

Page 9: Languages and Finite Automata

9

Inductive hypothesis:

for all with

Inductive step: we will prove

for

vuuv

v nv ,,2,1

1nv

vuuv

Page 10: Languages and Finite Automata

10

Inductive StepWrite , where

From definition of length:

From inductive hypothesis:

Thus:

wav 1, anw

1

1

wwa

uwuwauv

wuuw

vuwauwuuv 1

Page 11: Languages and Finite Automata

11

Empty StringA string with no letters:

Observations:

abbaabbaabba

www

0

Page 12: Languages and Finite Automata

12

SubstringDefinition:

A substring of a string is any sequence of consecutive characters

Example: Substrings

w

abbab

bbab

b

abba

ab

Page 13: Languages and Finite Automata

13

Prefix and Suffix

Prefixes Suffixes

abbab

abbab

abba

abb

ab

a

b

ab

bab

bbab

abbabuvw

prefix

suffix

Page 14: Languages and Finite Automata

14

Another Operation

Example:

Definition for any :

n

n wwww

abbaabbaabba 2

w 0w

0abba

Page 15: Languages and Finite Automata

15

The * Operation : the set of all possible strings from alphabet

Example:

*

,,,,,,,,,*

,

aabaaabbbaabaaba

ba

*

,,,,,,,, aabaaabbbaabaaba

Page 16: Languages and Finite Automata

16

LanguageA language is any subset of

Examples:

A string is called “sentence”

*

,,,,,,,,,*

,

aabaaabbbaabaaba

ba

},,,,,{

,,,

aaaaaaabaababaabba

aabaaa

Page 17: Languages and Finite Automata

17

Another ExampleAn infinite language

0: nbaL nn

aaaaabbbbb

aabb

ab

L Labb

Page 18: Languages and Finite Automata

18

Operations on LanguagesThe usual set operations

Complement:

aaaaaabbbaaaaaba

ababbbaaaaaba

aaaabbabaabbbaaaaaba

,,,,

}{,,,

},,,{,,,

LL *

,,,,,,, aaabbabaabbaa

Page 19: Languages and Finite Automata

19

Reverse

Definition:

Examples:

LwwL RR :

ababbaabababaaabab R ,,,,

0:

0:

nabL

nbaL

nnR

nn

Page 20: Languages and Finite Automata

20

Concatenation

Definition:

Example:

2121 ,: LyLxxyLL

baaabababaaabbaaaab

aabbaaba

,,,,,

,,,

Page 21: Languages and Finite Automata

21

Another OperationDefinition:

Example:

Special case:

n

n LLLL

bbbbbababbaaabbabaaabaaa

babababa

,,,,,,,

,,,, 3

0

0

,, aaabbaa

L

Page 22: Languages and Finite Automata

22

Example

0: nbaL nn

0,:2 mnbabaL mmnn

2Laabbaaabbb

Page 23: Languages and Finite Automata

23

Star-Closure (Kleene *)

Definition:

Example:

210* LLLL

,,,,

,,,,

,,

,

*,

abbbbabbaaabbaaa

bbbbbbaabbaa

bbabba

Page 24: Languages and Finite Automata

24

Positive Closure

Definition:

*

21

L

LLL

,,,,

,,,,

,,

,

abbbbabbaaabbaaa

bbbbbbaabbaa

bba

bba

Page 25: Languages and Finite Automata

25

Finite Automata

Input

String

Output

String

FiniteAutomaton

Page 26: Languages and Finite Automata

26

Finite Accepter

Input

“Accept” or“Reject”

String

FiniteAutomaton

Output

Page 27: Languages and Finite Automata

27

Transition Graph

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

initialstate

final state“accept”state

transition

5q

a a bb

ba,Abba -Finite Accepter

ba,

Page 28: Languages and Finite Automata

28

Initial Configuration

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

5q

a a bb

ba,

Input Stringa b b a

ba,

Page 29: Languages and Finite Automata

29

Reading the Input

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

5q

a a bb

ba,

a b b a

ba,

Page 30: Languages and Finite Automata

30

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

5q

a a bb

ba,

a b b a

ba,

Page 31: Languages and Finite Automata

31

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

5q

a a bb

ba,

a b b a

ba,

Page 32: Languages and Finite Automata

32

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

Output: “accept”

5q

a a bb

ba,

a b b a

ba,

Page 33: Languages and Finite Automata

33

Rejection

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

5q

a a bb

ba,

a b a

ba,

Page 34: Languages and Finite Automata

34

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

5q

a a bb

ba,

a b a

ba,

Page 35: Languages and Finite Automata

35

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

5q

a a bb

ba,

a b a

ba,

Page 36: Languages and Finite Automata

36

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

5q

a a bb

ba,

Output:“reject”

a b a

ba,

Page 37: Languages and Finite Automata

37

FormalitiesDeterministic Finite Accepter (DFA)

FqQM ,,,, 0

Q

0q

F

: set of states

: input alphabet

: transition function

: initial state

: set of final states

Page 38: Languages and Finite Automata

38

Input Aplhabet

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

5q

a a bb

ba,

ba,

ba,

Page 39: Languages and Finite Automata

39

Set of States

Q

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

5q

a a bb

ba,

543210 ,,,,, qqqqqqQ

ba,

Page 40: Languages and Finite Automata

40

Initial State

0q

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

5q

a a bb

ba,

ba,

Page 41: Languages and Finite Automata

41

Set of Final States

F

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

5q

a a bb

ba,

4qF

ba,

Page 42: Languages and Finite Automata

42

Transition Function

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

5q

a a bb

ba,

QQ :

50

10

,

,

qbq

qaq

ba,

Page 43: Languages and Finite Automata

43

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

2q 3q

4q 5q

ba,5q5q5q5q

Page 44: Languages and Finite Automata

44

Extended Transition Function

*

QQ *:*

50

40

20

,*

,*

,*

qabbaaq

qabbaq

qabq

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

5q

a a bb

ba,

ba,

Page 45: Languages and Finite Automata

45

Recursive Definition

)),,(*(,*

,*

awqwaq

qq

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

Page 46: Languages and Finite Automata

46

Languages Accepted by DFAsTake DFA

Definition:The language accepted by contains all input strings accepted by

In other words: = { strings that drive to a final

state}

M

ML MM

M ML

Page 47: Languages and Finite Automata

47

Example

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

5q

a a bb

ba,

ba,

abbaML M

accept

Page 48: Languages and Finite Automata

48

Another Example

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

5q

a a bb

ba,

ba,

abbaabML ,, M

acceptacceptaccept

Page 49: Languages and Finite Automata

49

Formally

For a DFA

Language accepted by :

FqQM ,,,, 0

M

FwqwML ,*:* 0

alphabet transitionfunction

initialstate

finalstates

Page 50: Languages and Finite Automata

50

Observation Language accepted by :

Language rejected by :

FwqwML ,*:* 0

M

FwqwML ,*:* 0

M

Page 51: Languages and Finite Automata

51

More Examples

a

b ba,

ba,

0q 1q 2q

0: nbaML n

accept trap state

Page 52: Languages and Finite Automata

52

ML = { all substrings with prefix }ab

a b

ba,

0q 1q 2q

accept

ba,3q

ab

Page 53: Languages and Finite Automata

53

ML = { all strings without substring }001

0 00 001

1

0

1

10

0 1,0

Page 54: Languages and Finite Automata

54

Regular LanguagesDefinition:

A language is regularif there is a DFA such that

All the regular languages form a family

LM

MLL

Page 55: Languages and Finite Automata

55

ExampleThe languageis regular:

*,: bawawaL

a

b

ba,

a

b

ba

0q 2q 3q

4q