language recognition (11.4) longin jan latecki temple university

24
1 Language Recognition (11.4) Longin Jan Latecki Temple University Based on slides by Costas Busch from the course http://www.cs.rpi.edu/courses/spri ng05/modcomp/ and …

Upload: annice

Post on 22-Feb-2016

85 views

Category:

Documents


0 download

DESCRIPTION

Language Recognition (11.4) Longin Jan Latecki Temple University. Based on slides by Costas Busch from the course http://www.cs.rpi.edu/courses/spring05/modcomp/ and …. Three Equivalent Representations. Regular expressions. Each can describe the others. Regular languages. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Language Recognition (11.4) Longin Jan Latecki Temple University

1

Language Recognition (11.4) Longin Jan LateckiTemple University

Based on slides by Costas Busch from the coursehttp://www.cs.rpi.edu/courses/spring05/modcomp/and …

Page 2: Language Recognition (11.4) Longin Jan Latecki Temple University

2

Three Equivalent Representations

Finite automata

Regularexpressions

Regular languages

Each can

describethe others

Kleene’s Theorem: For every regular expression, there is a deterministic finite-state automaton that defines the same language, and vice versa.

Page 3: Language Recognition (11.4) Longin Jan Latecki Temple University

3

EXAMPLE 1

Consider the language { ambn | m, n N}, which is represented by the regular expression a*b*.

A regular grammar for this language can

be written as follows: 

S | aS | B B b | bB.

Page 4: Language Recognition (11.4) Longin Jan Latecki Temple University

4

Regular Expression

Regular Grammar

a* S | aS(a+b)* S | aS | bSa* + b* S | A | B

A a | aAB b | bB

a*b S b | aSba* S bA

A | aA(ab)* S | abS

Page 5: Language Recognition (11.4) Longin Jan Latecki Temple University

5

NFAs Regular grammarsThus, the language recognized by FSA

is a regular language Every NFA can be converted into a corresponding regular grammar and vice versa.Each symbol A of the grammar is associated with a non-terminal node of the NFA sA, in particular, start symbol

S is associated with the start state sS.

Every transition is associated with a grammar production: T(sA,a) = sB A aB.

Every production B is associated with final state sB.

Page 6: Language Recognition (11.4) Longin Jan Latecki Temple University

6

Equivalent FSA and regular grammar, Ex. 4, p. 772.

G=(V,T,S,P)V={S, A, B, 0, 1} withS=s0, A=s1, and B=s2,

T={0,1}, and productions areS 0A | 1B | 1 | λA 0A | 1B | 1 B 0A | 1B | 1 | λ

Page 7: Language Recognition (11.4) Longin Jan Latecki Temple University

7

Kleene’s Theorem

LanguagesGenerated byRegular Expressions

LanguagesRecognizedby FSA

Page 8: Language Recognition (11.4) Longin Jan Latecki Temple University

8

LanguagesGenerated byRegular Expressions

LanguagesRecognizedby FSA

LanguagesGenerated byRegular Expressions

LanguagesRecognizedby FSA

We will show:

Page 9: Language Recognition (11.4) Longin Jan Latecki Temple University

9

Proof - Part 1

r)(rL

For any regular expression the language is recognized by FSA (= is a regular language)

LanguagesGenerated byRegular Expressions

LanguagesRecognizedby FSA

Proof by induction on the size of r

Page 10: Language Recognition (11.4) Longin Jan Latecki Temple University

10

Induction BasisPrimitive Regular Expressions: a,,

NFAs

)()( 1 LML

)(}{)( 2 LML

)(}{)( 3 aLaML

regularlanguages

a

Page 11: Language Recognition (11.4) Longin Jan Latecki Temple University

11

Inductive Hypothesis

Assume for regular expressions andthat and are regular languages

1r 2r

)( 1rL )( 2rL

Page 12: Language Recognition (11.4) Longin Jan Latecki Temple University

12

Inductive StepWe will prove:

1

1

21

21

*

rL

rL

rrL

rrL

Are regular Languages

Page 13: Language Recognition (11.4) Longin Jan Latecki Temple University

13

By definition of regular expressions:

11

11

2121

2121

**

rLrL

rLrL

rLrLrrL

rLrLrrL

Page 14: Language Recognition (11.4) Longin Jan Latecki Temple University

14

)( 1rL )( 2rLBy inductive hypothesis we know: and are regular languages

Regular languages are closed under: *1

21

21

rLrLrL

rLrL Union Concatenation

Star

We need to show:

This fact is illustrated in Fig. 2 on p. 769.

Page 15: Language Recognition (11.4) Longin Jan Latecki Temple University

15

Therefore:

** 11

2121

2121

rLrL

rLrLrrL

rLrLrrL

Are regularlanguages

And trivially: ))(( 1rL is a regular language

Page 16: Language Recognition (11.4) Longin Jan Latecki Temple University

16

Proof - Part 2

LanguagesGenerated byRegular Expressions

LanguagesRecognizedby FSA

Lr LrL )(

For any regular language there is a regular expression with

Proof by construction of regular expression

Page 17: Language Recognition (11.4) Longin Jan Latecki Temple University

17

Since is regular take the NFA that accepts it

LM

LML )(

Single final state

Page 18: Language Recognition (11.4) Longin Jan Latecki Temple University

18

From construct the equivalentGeneralized Transition Graph in which transition labels are regular

expressions

M

Example:

a

ba,

cM

a

ba

c

Page 19: Language Recognition (11.4) Longin Jan Latecki Temple University

19

Another Example:

ba a

b

b0q 1q 2q

ba,a

b

b0q 1q 2q

b

b

Page 20: Language Recognition (11.4) Longin Jan Latecki Temple University

20

Reducing the states:ba

ab

b0q 1q 2q

b

0q 2q

babb*

)(* babb

Page 21: Language Recognition (11.4) Longin Jan Latecki Temple University

21

Resulting Regular Expression:

0q 2q

babb*

)(* babb

*)(**)*( bbabbabbr

LMLrL )()(

Page 22: Language Recognition (11.4) Longin Jan Latecki Temple University

22

In GeneralRemoving states:

iq q jqa b

cde

iq jq

dae* bce*dce*

bae*

Page 23: Language Recognition (11.4) Longin Jan Latecki Temple University

23

The final transition graph:

0q fq

1r

2r

3r4r

*)*(* 213421 rrrrrrr

LMLrL )()(

The resulting regular expression:

Page 24: Language Recognition (11.4) Longin Jan Latecki Temple University

24

Three Equivalent Representations

Finite automata

Regularexpressions

Regular languages

Each can

describethe others