1 / 25

Kleene's Theorem

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 are (relatively) easy to specify and recognise. Theorem: Kleene's theorem

draco
Download Presentation

Kleene's Theorem

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 are (relatively) easy to specify and recognise. 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) Let T be an alphabet. A regular expression over T defines a language over T as follows: (i) l denotes {l}, f 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. 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 = {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 = L1 + L2 then obtain • A1 = (Q1 , {i1} , {f1} , T , E1) L1 = L(A1) • A2 = (Q2 , {i2} , {f2} , T , E2) L2 = L(A2) • A = (Q1 È Q2 È {i,f}, {i} , {f} , T , E1È E2È {(i,l,i1),(i,l,i2),(f1,l,f),(f2,l,f)}) • if L = L1L2 then obtain A1 and A2 as above • A = (Q1 È Q2 , {i1} , {f2} , T , E1 È E2 È {(f1,l,i2)}) • if L = L1* then obtain A1 as above • A = (Q1 È {i,f}, {i}, {f}, T, E1 È {(i,l,i1),(i,l,f),(f1,l,f),(f1,l,i1)})

  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 = {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 = L1 + L2 then obtain • A1 = (Q1,{i1},{f1},T,E1) L1 = L(A1) • A2 = (Q2,{i2},{f2},T,E2) L2 = L(A2) • A = (Q1 È Q2 È {i,f},{i},{f},T, E1È E2È {(i,l,i1),(i,l,i2),(f1,l,f),(f2,l,f)})Start with i. Following , do either A1 or A2. End in f.Nondeterminism (and  edges)can be useful! i1 A1 f1   f i   f2 A2 i2

  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 = L1 + L2 then obtain • A1 = (Q1,{i1},{f1},T,E1), L1 = L(A1) • A2 = (Q2,{i2},{f2},T,E2), L2 = L(A2) • A = (Q1 È Q2 È {i,f},{i},{f},T,E1È E2È • {(i,l,i1),(i,l,i2),(f1,l,f),(f2,l,f)})(Start with i. Following , do either A1 or A2. End in f.Nondeterminism can be useful!) • if L = L1L2 then obtain A1 and A2 as above • A = (Q1 È Q2,{i1},{f2},T,E1 È E2 È {(f1,l,i2)}) ({(f1,,i2)}) links the end of A1 with the start of A2) • if L = L1* then obtain A1 as above • A = (Q1 È {i,f},{i},{f},T, • E1 È {(i,l,i1),(i,l,f),(f1,l,f),(f1,l,i1)})The edge (i,,f) stands for 0 strings in L1 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 • 1.2.1. a • 1.2.2. b • 2.(b+ab)* • 2.1. (b+ab) (same as 1.) 1.2.1 = ({1,2},{1},{2},T,{(1,a,2)}) 1.2.2 = ({3,4},{3},{4},T,{(3,b,4)}) 1.2 = ({1,2,3,4},{1},{4},T,{(1,a,2), (2,l,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,l,1),(7,l,5), (1,a,2),(2,l,3),(3,b,4), (5,b,6), (4,l,8),(6,l,8) }) 2.1 = ({9,10,11,12,13,14,15,16},{15},{16},T, { (15,l,9),(15,l,13), (9,a,10),(10,l,11), (11,b,12),(13,b,14), (12,l,16),(14,l,16) })

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

  9. 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 where we are at the moment ...

  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 1. create unique initial state 2. create unique final state 3. unique FSA ->Regular Expression 2. Algorithm: create unique final state (informal) 1. a unique initial state is created in the same way Input: (Q, I, F, T, E) Q := Q È {f} (where fÏ Q) for each q Î F, E:= E È {(q,l,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.

  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 r1,r2,...,rn, replace all those • edges by (p,r1+r2+...+rn,p). • For each pair of states p,q in Q with more than • one edge from p to q labelled r1,r2,...,rn, replace • all those edges by (p,r1+r2+...+rn,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 r1,r2,...,rn, replace all those • edges by (p,r1+r2+...+rn,p). • For each pair of states p,q in Q with more than • one edge from p to q labelled r1,r2,...,rn, replace • all those edges by (p,r1+r2+...+rn,q). • select a state s Ï {i,f} • For each pair of states p,q (¹s) s.t. there are • edges (p,r1,s) and (s,r2,q) • begin • if there is an edge (s,r3,s) • add the edge (p,r1r3*r2,q) • else add the edge (p,r1r2,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). r1 r3* r2 r1 r2 p s q r3

  14. Example: FSA -> Regular Expression a a,b 2 3 a b 1 a b 4 b

  15. Example: FSA -> Regular Expression create unique initial and final states; add a+b loop a a+b 2 3 a l b 1 i a b l a f 4 a,b 2 3 a b b 1 a b 4 b

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

  17. Example: FSA -> Regular Expression a+b 3 aa l aa 1 i b l f 4 ab ab b

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

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

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

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

  22. 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 Is this a proper proof?

  23. What follows is optional (not in the exam for 2010-2011)

  24. The Pumping Lemma • Theorem: (The Pumping Lemma) • If L is a regular language, then there exists an • Integer n s.t. for any wÎ L with |w| ≥ n, there • are strings x, u and y s.t. • w = xuy • |xu| n and • |u| > 0, and s.t. • for every m ≥ 0, xumyÎ L.

  25. Using the Pumping Lemma The Pumping Lemma can be used to show languages are not regular. Example: show L = { anbn : InI ≥ 0} is not regular. Suppose L is regular. Then there exists some integer N as in the theorem. Choose i > N/2. w = aibi has length > N. Therefore, it can be split into substrings xuy, such that |xu|  N and |u| > 0. But u must be of the form an, or anbm, or bm. In no case is xu2y in L. But by the Pumping Lemma, xu2yÎ L. Contradiction. Therefore, L is not regular.

More Related