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)**

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 A2 f2 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 a 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 l b a l 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) 1 2 3 4 9 10 11 12 l l l l l l l l 7 8 17 15 16 18 l l l l b b 5 6 13 14 l

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**

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) 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 return r, where E = (i,r,f). r1 r3* r2 r1 r2 p s q r3

14
**Example: FSA -> Regular Expression**

2 3 a,b a 1 b a b 4 b

15
**Example: FSA -> Regular Expression**

create unique initial and final states; add a+b loop a 2 3 a+b a l i 1 b a b l a 2 3 a,b 4 f a b 1 b a b 4 b

16
**Example: FSA -> Regular Expression**

create unique initial and final states; add a+b loop a 2 3 a+b a l i 1 b a b l a 2 3 a,b 4 f a b 1 b a b remove state 2 - edges are 1-3, 1-4, 4-3, 4-4 4 b 3 a+b aa l aa i 1 b l ab 4 f ab b

17
**Example: FSA -> Regular Expression**

3 a+b aa l aa i 1 b l ab 4 f ab b

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

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

b+ab b+ab l b+ab 4 f b+ab

20
**Example (cont.) remove edge pairs remove state 3 - no edges 3 a+b aa l**

1 4 f aa i 1 b+ab b+ab l b+ab 4 f remove state 4 - edge is 1-f b+ab l i 1 f (b+ab)(b+ab)*

21
**Example (cont.) remove edge pairs remove state 3 - no edges 3 a+b aa l**

1 4 f aa i 1 b+ab b+ab l b+ab 4 f remove state 4 - edge is 1-f b+ab l i 1 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
**The first half (RE=>FSA) is unproblematic**

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

Similar presentations

OK

Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.

Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on communicative language teaching Ppt on water scarcity facts Download ppt on brain chip technology Ppt on microsoft excel 2010 Ppt on trial and error approach Ppt on summary writing rubric Ppt on world environment day slogans Ppt on tropical deciduous forest in india Ppt on educating girl child Ppt on depth first search algorithms