Equivalence of Regular Language Representations

27
cs466(Prasad) L14Equiv 1 Equivalence of Regular Language Representations

description

Equivalence of Regular Language Representations. Regular Languages: Grand Unification. (Parallel Simulation) (Rabin and Scott’s work). (Collapsing graphs; Structural Induction) (S. Kleene’s work). (Construction) (Solving linear equations). - PowerPoint PPT Presentation

Transcript of Equivalence of Regular Language Representations

Page 1: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 1

Equivalence of Regular Language Representations

Page 2: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 2

Regular Languages: Grand UnificationGrand Unification

)( )()(

DFAsLNFAsLsNFAL

)()()()(

RELFALRELFAL

(Parallel Simulation) (Rabin and Scott’s work)

(Collapsing graphs; Structural Induction)(S. Kleene’s work)

)()( RGLFAL (Construction)(Solving linear equations))()( RELRGL

Page 3: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 3

Role of various representations for Regular Languages

• Closure under complemention. (DFAs)• Closure under union, concatenation, and Kleene

star. (NFA-s, Regular expression.)• Consequence:

Closure under intersection by De Morgan’s Laws.

• Relationship to context-free languages. (Regular Grammars.)

• Ease of specification. (Regular expression.)

• Building tokenizers/lexical analyzers. (DFAs)

Page 4: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 4

Application to Scanner (Lexer, Tokenizer)

• High-level view

Regularexpressions

NFA

DFA

LexicalSpecification

Table-driven Implementation of a minimal DFA

Page 5: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 5

M(a)

Construction of Finite Automata from Regular Expressions

)()( FALREL

Show that there are FA for basis elements and there exist constructions on FA for capturing union, concatenation, and Kleene star operations.

Basis Case

Page 6: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 6

Constructions on NFA-s

M(R1)

M(R1)

M(R2)

MM(R1 U R2)

MM(R1 R2)

MM(R*)

M(R2)

M(R)

Page 7: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 7

Construction of Regular Expression from Finite Automaton

• Expression Graph is a labeled directed graph in which the arcs are labeled by regular expressions. An expression graph, like a state diagram, contains a distinguished start node and a set of accepting nodes.

Page 8: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 8

Examples

ab

L(M) = (ab)*

Page 9: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 9

Examples

ba

L(M) = (b+ a)* (a u b) (ba)*

b+ a

a u b

Page 10: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 10

Examples

bb

L(M) = (b a)* b*( bb u (a+(ba)*b*) )*

ba

b*

a+

Page 11: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 11

Main Idea

• To associate an RE with an FA, – reduce an arbitrary expression graph to one

containing at most two nodes, – by repeatedly removing nodes from the graph

and relabeling the arcs to preserve the language.• Without loss of generality, we can assume

one accepting state (because of the presence of the union operation).

Page 12: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 12

Exampleqj qk

qj

qi

qk

Wj,i

Wj,i Wi,k

Wi,k

Page 13: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 13

qj qk

qj

qi

qk

Wj,i

Wj,i (Wi,i)* Wi,k

Wi,k

Wi,i

Page 14: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 14

Final Graph : Alternative 1

u

L(M) = (u)*

Page 15: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 15

Final Graph : Alternative 2

w

L(M) = (u)* v( w u (x (u)* v) )*

u

v

x

Page 16: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 16

Detailed Example

b

a ba

ab

bq0 q1

q2 q3

Page 17: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 17

Delete node q1

b

a ba

ab

bq0 q1

q2 q3

bbab

Page 18: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 18

Delete node q2

b

aa

b u bb

q0

q2 q3

ab

ab*ab

Page 19: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 19

Finally

ab u bb

q0

q3

ab*ab

(ab*ab)*a ((bubb) (ab*ab)*a)*

Page 20: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 20

• For precise details, see Algorithm 6.2.2 on Page 194 in Sudkamp’s Languages and Machines, 3rd Edition.

Page 21: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 21

From Regular Expression to NFA to DFA to Regular Grammars

Via Examples

Page 22: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 22

Exercise

• Construct a DFA for a+b+

q0b

q1 q2a

a b

Page 23: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 23

Equivalent DFA

{q0} {q1,q2}

{q0,q1}

{}

a

a

a

a,b

b

b

b

Page 24: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 24

Two Equivalent (Right-linear) Regular Grammars

<q0> -> a <q0> | a <q1>

<q1> -> b <q1> | b <q2>

<q2> -> λ

<{q0}> -> a <{q0,q1}> <{q0,q1}> ->

a <{q0,q1}> | b <{q1,q2}>

<{q1,q2}> -> λ | b <{q1,q2}>

• All productions involving <{}> can be deleted, as <{}> does not derive any terminal strings.

Page 25: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 25

Two Equivalent (Left-linear) Regular Grammars

<q0> -> λ | <q0> a

<q1> -> <q1> b | <q0> a

<q2> -> <q1> b

<{q0}> -> λ<{q0,q1}> -> <{q0,q1}> a | <{q0}> a

<{q1,q2}> -> | <{q0,q1}> b | <{q1,q2}> b

Page 26: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 26

From Grammars to Finite Automata

S -> aA | cA -> bB | bAB -> λ

S -> aA | cFA -> bB | bAB -> λF -> λ

SA

BF

a bb

c

Page 27: Equivalence of Regular Language Representations

cs466(Prasad) L14Equiv 27

From Grammars to Finite Automata

S -> aA | cA -> bB | bAB -> λ

S -> λA -> Sa | AbB -> AbF -> ScZZ -> B | F

SA

BF

a bb

c