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.

Slides:



Advertisements
Similar presentations
CS2303-THEORY OF COMPUTATION Closure Properties of Regular Languages
Advertisements

0 - 0.
Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.
Why empty strings? A bit like zero –you may think you can do without –but it makes definitions & calculations easier Definitions: –An alphabeth is a finite.
Specifying Languages Our aim is to be able to specify languages for use in the computer. The sketch of an FSA is easy for us to understand, but difficult.
Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.
Automata Theory Part 1: Introduction & NFA November 2002.
Addition 1’s to 20.
Test B, 100 Subtraction Facts
Finite-state Recognizers
Chapter 6 Languages: finite state machines
Language and Automata Theory
NFAs and DFAs Sipser 1.2 (pages 47-63).
CSE 311 Foundations of Computing I
4b Lexical analysis Finite Automata
Theory Of Automata By Dr. MM Alam
Regular Expressions and DFAs COP 3402 (Summer 2014)
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University 2005.
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
Chapter Section Section Summary Set of Strings Finite-State Automata Language Recognition by Finite-State Machines Designing Finite-State.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture4: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
1 The scanning process Main goal: recognize words/tokens Snapshot: At any point in time, the scanner has read some input and is on the way to identifying.
Validating Streaming XML Documents Luc Segoufin & Victor Vianu Presented by Harel Paz.
1 Single Final State for NFAs and DFAs. 2 Observation Any Finite Automaton (NFA or DFA) can be converted to an equivalent NFA with a single final state.
CS5371 Theory of Computation Lecture 6: Automata Theory IV (Regular Expression = NFA = DFA)
1 Finite state automaton (FSA) LING 570 Fei Xia Week 2: 10/07/09 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAA.
79 Regular Expression Regular expressions over an alphabet  are defined recursively as follows. (1) Ø, which denotes the empty set, is a regular expression.
PZ02B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ02B - Regular grammars Programming Language Design.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Introduction to Finite Automata Adapted from the slides of Stanford CS154.
Finite-State Machines with No Output
Regular Expressions. Notation to specify a language –Declarative –Sort of like a programming language. Fundamental in some languages like perl and applications.
REGULAR LANGUAGES.
PZ02B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ02B - Regular grammars Programming Language Design.
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
Lecture 05: Theory of Automata:08 Kleene’s Theorem and NFA.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
Regular Expressions and Languages A regular expression is a notation to represent languages, i.e. a set of strings, where the set is either finite or contains.
Kleene’s Theorem Group No. 3 Presented To Mam Amina Presented By Roll No Roll No Roll No Roll No Group No. 3 Presented To Mam.
CHAPTER 1 Regular Languages
Copyright © Curt Hill Finite State Automata Again This Time No Output.
Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.
CMSC 330: Organization of Programming Languages Finite Automata NFAs  DFAs.
Overview of Previous Lesson(s) Over View  Symbol tables are data structures that are used by compilers to hold information about source-program constructs.
Lecture # 12. Nondeterministic Finite Automaton (NFA) Definition: An NFA is a TG with a unique start state and a property of having single letter as label.
CMSC 330: Organization of Programming Languages Theory of Regular Expressions Finite Automata.
Chapter 3 Regular Expressions, Nondeterminism, and Kleene’s Theorem Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction.
Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.
CSC312 Automata Theory Nonregular Languages Chapter # 10 by Cohen
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2007.
Chapter 5 Finite Automata Finite State Automata n Capable of recognizing numerous symbol patterns, the class of regular languages n Suitable for.
BİL711 Natural Language Processing1 Regular Expressions & FSAs Any regular expression can be realized as a finite state automaton (FSA) There are two kinds.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Complexity and Computability Theory I Lecture #5 Rina Zviel-Girshin Leah Epstein Winter
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2006.
Theory of Computation Automata Theory Dr. Ayman Srour.
1 Section 11.2 Finite Automata Can a machine(i.e., algorithm) recognize a regular language? Yes! Deterministic Finite Automata A deterministic finite automaton.
Lecture 09: Theory of Automata:2014 Asif NawazUIIT, PMAS-Arid Agriclture University Rawalpindi. Kleene’s Theorem and NFA.
1 Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Kleene’s Theorem and NFA
Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Kleene’s Theorem Muhammad Arif 12/6/2018.
Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Mealy and Moore Machines
Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
PZ02B - Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section PZ02B.
Presentation transcript:

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.

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

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

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

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

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

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

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

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

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.

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.

(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). (....)

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

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

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

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

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

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

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

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

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

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