Download presentation

Presentation is loading. Please wait.

Published byMonserrat Fick Modified over 2 years ago

1
Kleene's Theorem We have defined the regular languages, using regular expressions, which are convenient to write down and use. We have also defined the languages which are accepted by FSAs, which make it easy to tell whether a string is a member of the language. Theorem: Kleene's theorem A language L is accepted by a FSA iff L is regular Not only are regular expressions and FSA's equivalent, there are algorithms allowing us to translate between the two.

2
Recall: Regular Expressions (REs) (i) denotes { }, denotes {}, t denotes {t} for t T; (ii) if r and s are regular expressions denoting languages R and S, then (r + s) denoting R + S, (rs) denoting RS, and (r*) denoting R* are regular expressions; (iii) nothing else is a regular expression over T. Let T be an alphabet. A regular expression over T defines a language over T as follows: Note: a recursive definition of the language of REs

3
Algorithm: Reg Ex => NDFSA (overview page) Let L be a regular language over T. We will create A, a NDFSA accepting L. Recall: (Q,I,F,T,E) if L = { }, then A = ({q}, {q}, {q}, T, {}) if L = {}, then A = ({q}, {q}, {}, T, {}) if L = {t}, then A = ({p,q}, {p}, {q}, T, {(p,t,q)}) if L = L 1 + L 2 then obtain A 1 = (Q 1, {i 1 }, {f 1 }, T, E 1 ) L 1 = L(A 1 ) A 2 = (Q 2, {i 2 }, {f 2 }, T, E 2 ) L 2 = L(A 2 ) A = (Q 1 Q 2 {i,f} , {i}, {f}, T, E 1 E 2 {(i,,i 1 ),(i,,i 2 ),(f 1,,f),(f 2,,f)}) if L = L 1 L 2 then obtain A 1 and A 2 as above A = (Q 1 Q 2, {i 1 }, {f 2 }, T, E 1 E 2 {(f 1,,i 2 )}) if L = L 1 * then obtain A 1 as above A = (Q 1 {i,f}, {i}, {f}, T, E 1 {(i,,i 1 ),(i,,f),(f 1,,f),(f 1,,i 1 )})

4
Regular Expression => NDFSA (with added comments) Where necessary, draw the DFAs constructed here! Let L be a regular language over T. We will create A, a NDFSA accepting L. Recall: (Q,I,F,T,E) if L = { }, then A = ({q},{q},{q},T,{}) (I=F) if L = {}, then A = ({q},{q},{},T,{}) (F={}) if L = {t}, then A = ({p,q},{p},{q},T, {(p,t,q)}) NB: So far, the NDFSAs we’re constructing have exactly one initial state and at most one final state. Later constructs will keep it that way! (We return to the case where L={} later.)

5
Regular Expression => NDFSA (with added comments) Let L be a regular language over T. We will create A, a NDFSA accepting L. Recall: (Q,I,F,T,E) if L = L 1 + L 2 then obtain A 1 = (Q 1,{i 1 },{f 1 },T,E 1 ) L 1 = L(A 1 ) A 2 = (Q 2,{i 2 },{f 2 },T,E 2 ) L 2 = L(A 2 ) A = (Q 1 Q 2 {i,f} ,{i},{f},T, E 1 E 2 {(i,,i 1 ),(i,,i 2 ),(f 1,,f),(f 2,,f)}) Start with i. Following, do either A 1 or A 2. End in f. Nondeterminism (and edges) can be useful! i i1 i2 f1 f2 f A1 A2

6
Regular Expression => NDFSA (with added comments) Let L be a regular language over T. We will create A, a NDFSA accepting L. Recall: (Q,I,F,T,E) if L = L 1 + L 2 then obtain A 1 = (Q 1,{i 1 },{f 1 },T,E 1 ), L 1 = L(A 1 ) A 2 = (Q 2,{i 2 },{f 2 },T,E 2 ), L 2 = L(A 2 ) A = (Q 1 Q 2 {i,f} ,{i},{f},T,E 1 E 2 {(i,,i 1 ),(i,,i 2 ),(f 1,,f),(f 2,,f)}) (Start with i. Following, do either A 1 or A 2. End in f. Nondeterminism can be useful!) if L = L 1 L 2 then obtain A 1 and A 2 as above A = (Q 1 Q 2,{i 1 },{f 2 },T,E 1 E 2 {(f 1,,i 2 )}) ({(f1,,i2)}) links the end of A 1 with the start of A 2 ) if L = L 1 * then obtain A 1 as above A = (Q 1 {i,f},{i},{f},T, E 1 {(i,,i 1 ),(i,,f),(f 1,,f),(f 1,,i 1 )}) The edge (i,,f) stands for 0 strings in L 1 The edge (f1,,i1) causes a loop

7
Example: Regular Expression => NDFSA Let L = (b+ab)(b+ab)*, T = {a,b} Find NDFSA's for 1. (b+ab) 1.1. b 1.2. ab a b 2.(b+ab)* 2.1. (b+ab) (same as 1.) = ({1,2},{1},{2},T,{(1,a,2)}) = ({3,4},{3},{4},T,{(3,b,4)}) 1.2 = ({1,2,3,4},{1},{4},T,{(1,a,2), (2,,3),(3,b,4)}) 1.1 = ({5,6},{5},{6},T,{(5,b,6)}) 1 = ({1,2,3,4,5,6,7,8},{7},{8},T, { (7,,1),(7,,5), (1,a,2),(2,,3),(3,b,4), (5,b,6), (4,,8),(6, 8) }) 2.1 = ({9,10,11,12,13,14,15,16},{15},{16},T, { (15,,9),(15,,13), (9,a,10),(10,,11), (11,b,12),(13,b,14), (12,,16),(14,,16) })

8
Example (cont.) 2. = ({9,10,11,12,13,14,15,16,17,18},{17},{18},T, {(17,,15),(17,,18),(15,,9),(15,,13),(9,a,10), (10,,11),(11,b,12),(13,b,14),(12,,16), (14,,16),(16,,18),(16,,15)}) A = ({1,2,...,18},{7},{18},T, { (7,,1),(7,,5),(1,a,2),(2,,3),(3,b,4),(5,b,6), (4,,8),(6, 8), (8, 17), (17,,15),(17,,18), (15,,9),(15,,13),(9,a,10),(10,,11),(11,b,12), (13,b,14),(12,,16),(14,,16),(16,,18),(16,,15) }) a b b a b b This is nondeterministic... but we know that any NDFSA can be converted into a DFSA (although we skipped the details of how this is done)

9
where we are at the moment... We’ve seen how for each Regular Expression one can construct an NDFSA that accepts the same language Now let’s do the reverse: given a NDFSA Expression, we construct a regular expression that denotes the same language

10
Recall: FSAs A Finite State Automaton (FSA) is a 5-tuple (Q, I, F, T, E) where: Q = states = a finite set; I = initial states = a nonempty subset of Q; F = final states = a subset of Q; T = an alphabet; E = edges = a subset of Q (T + ) Q. FSA = labelled, directed graph =set of nodes (some final/initial) + directed arcs (arrows) between nodes + each arc has a label from the alphabet.

11
Algorithm: FSA -> Regular Expression 2. Algorithm: create unique final state (informal) Input: (Q, I, F, T, E) Q := Q {f} (where f Q) for each q F, E:= E {(q,,f)} F := {f} A regular finite state automaton (RFSA) is a FSA where the edge labels may be regular expressions. An edge labelled with the regular expression r indicates that we can move along that edge on input of any string included in r. 1. create unique initial state 2. create unique final state 3. unique FSA ->Regular Expression 1. a unique initial state is created in the same way

12
(3) Unique FSA -> Regular Expresssion Let A be a FSA with unique initial and final states. In a number of steps, A can be converted to a RFSA with just one edge, whose label is the required Regular Expression. Here’s the start of the proof: While there are states in Q\{i,f} begin For each state p in Q with more than one edge to itself, labelled r 1,r 2,...,r n, replace all those edges by (p,r 1 +r r n, p). For each pair of states p,q in Q with more than one edge from p to q labelled r 1,r 2,...,r n, replace all those edges by (p,r 1 +r r n, q). (....)

13
Unique FSA -> Regular Expresssion Let A be a FSA with unique initial and final states. A can be converted to a RFSA. While there are states in Q\{i,f} begin For each state p in Q with more than one edge to itself, labelled r 1,r 2,...,r n, replace all those edges by (p,r 1 +r r n, p). For each pair of states p,q in Q with more than one edge from p to q labelled r 1,r 2,...,r n, replace all those edges by (p,r 1 +r r n, q). select a state s {i,f} For each pair of states p,q ( s) s.t. there are edges (p,r 1,s) and (s,r 2,q) begin if there is an edge (s,r 3,s) add the edge (p,r 1 r 3 *r 2,q) else add the edge (p,r 1 r 2,q) end remove all edges to or from s remove all states & edges with no path from i end return r, where E = (i,r,f). psq r3 r1r2 r1 r3* r2

14
Example: FSA -> Regular Expression a b b b a a a,b

15
Example: FSA -> Regular Expression a b b b a a a,b create unique initial and final states; add a+b loop a b b b a a a+b i f

16
Example: FSA -> Regular Expression a b b b a a a,b create unique initial and final states; add a+b loop a b b b a a a+b i f remove state 2 - edges are 1-3, 1-4, 4-3, aa b b a+b i f ab

17
Example: FSA -> Regular Expression aa b b a+b i f ab

18
Example (cont.) aa b+ab aa a+b i f combine: b+ab, b+ab

19
Example (cont.) aa b+ab aa a+b i f remove state 3 - no edges 1 4 b+ab i f b+ab

20
Example (cont.) aa b+ab aa a+b i f remove edge pairsremove state 3 - no edges 1 4 b+ab i f b+ab remove state 4 - edge is 1-f 1 i f (b+ab)(b+ab)*

21
Example (cont.) aa b+ab aa a+b i f remove edge pairsremove state 3 - no edges 1 4 b+ab i f b+ab remove state 4 - edge is 1-f 1 i f (b+ab)(b+ab)* remove state 1 - edge is i-f i f (b+ab)(b+ab)* expression is: (b+ab)(b+ab)*

22
Is this a proper proof? The first half (RE=>FSA) is unproblematic –Proof follows the (recursive) definition of the language of REs –Wrinkle: A may lack a final state (the case where L={}) The second half (FSA=>RE): –Algorithm not fully specified. (e.g., “select a state s”) Does the order in which states are selected not matter? –Is the resulting RE always equivalent to the initial FSA? These wrinkles can be ironed out

23

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google