Complexity and Computability Theory I

Slides:



Advertisements
Similar presentations
Lecture 24 MAS 714 Hartmut Klauck
Advertisements

Complexity and Computability Theory I Lecture #4 Rina Zviel-Girshin Leah Epstein Winter
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture2: Non Deterministic Finite Automata 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 Introduction to Computability Theory Lecture2: Non Deterministic Finite Automata (cont.) Prof. Amos Israeli.
Lecture 3: Closure Properties & Regular Expressions Jim Hook Tim Sheard Portland State University.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Regular.
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)
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
79 Regular Expression Regular expressions over an alphabet  are defined recursively as follows. (1) Ø, which denotes the empty set, is a regular expression.
1 A Single Final State for Finite Accepters. 2 Observation Any Finite Accepter (NFA or DFA) can be converted to an equivalent NFA with a single final.
THEORY OF COMPUTATION 08 KLEENE’S THEOREM.
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
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.
Lesson No.6 Naveen Z Quazilbash. Overview Attendance and lesson plan sharing Assignments Quiz (10 mins.). Some basic ideas about this course Regular Expressions.
CHAPTER 1 Regular Languages
Complexity and Computability Theory I Lecture #2 Rina Zviel-Girshin Leah Epstein Winter
Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein.
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.
Complexity and Computability Theory I Lecture #8 Instructor: Rina Zviel-Girshin Lea Epstein.
CSCI 2670 Introduction to Theory of Computing September 13.
CS 203: Introduction to Formal Languages and Automata
Chapter 3 Regular Expressions, Nondeterminism, and Kleene’s Theorem Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction.
Regular Expressions Section 1.3 (also 1.1, 1.2) CSC 4170 Theory of Computation.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Conversions Regular Expression to FA FA to Regular Expression.
Regular Expressions CS 130: Theory of Computation HMU textbook, Chapter 3.
1 Chapter 3 Regular Languages.  2 3.1: Regular Expressions (1)   Regular Expression (RE):   E is a regular expression over  if E is one of:
 2004 SDU Lecture4 Regular Expressions.  2004 SDU 2 Regular expressions A third way to view regular languages. Say that R is a regular expression if.
1 Introduction to the Theory of Computation Regular Expressions.
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
Complexity and Computability Theory I Lecture #5 Rina Zviel-Girshin Leah Epstein Winter
1 Section 11.2 Finite Automata Can a machine(i.e., algorithm) recognize a regular language? Yes! Deterministic Finite Automata A deterministic finite automaton.
CS412/413 Introduction to Compilers Radu Rugina Lecture 3: Finite Automata 25 Jan 02.
Lecture 15: Theory of Automata:2014 Finite Automata with Output.
1/29/02CSE460 - MSU1 Nondeterminism-NFA Section 4.1 of Martin Textbook CSE460 – Computability & Formal Language Theory Comp. Science & Engineering Michigan.
Topic 3: Automata Theory 1. OutlineOutline Finite state machine, Regular expressions, DFA, NDFA, and their equivalence, Grammars and Chomsky hierarchy.
Theory of Computation Automata Theory Dr. Ayman Srour.
Complexity and Computability Theory I
Kleene’s Theorem and NFA
Foundations of Computing Science
Non Deterministic Automata
Regular Expressions.
Complexity and Computability Theory I
Formal Language & Automata Theory
Lecture 9 Theory of AUTOMATA
Single Final State for NFA
REGULAR LANGUAGES AND REGULAR GRAMMARS
Non-deterministic Finite Automata (NFA)
CS 154, Lecture 3: DFANFA, Regular Expressions.
Kleene’s Theorem Muhammad Arif 12/6/2018.
Definitions Equivalence to Finite Automata
Definitions Equivalence to Finite Automata
CSCI 2670 Introduction to Theory of Computing
Compiler Construction
Definitions Equivalence to Finite Automata
Chapter 1 Regular Language
Theory of computing, part 3
CSCI 2670 Introduction to Theory of Computing
CSC312 Automata Theory Kleene’s Theorem Lecture # 12
Kleene’s Theorem (Part-3)
NFAs accept the Regular Languages
Presentation transcript:

Complexity and Computability Theory I Lecture #6 Instructor: Rina Zviel-Girshin Lea Epstein

Rina Zviel-Girshin @ASC Overview Regular expressions Examples Properties of regular languages Transforming regular expressions into FA Transforming FA into regular expressions Rina Zviel-Girshin @ASC

Algebraic expressions Regular languages are often described by means of algebraic expressions called regular expressions. In arithmetic we use the +, * operations to construct expressions: (2+3)*5 The value of the arithmetic expression is the number 25. Rina Zviel-Girshin @ASC

Rina Zviel-Girshin @ASC Regular operations We can use regular operations to construct expressions describing regular languages: (0+1)* 0* where : + means OR * Kleene star  concatenation The value of a regular expression is a regular language. Rina Zviel-Girshin @ASC

Formal definition A set of regular expressions over an alphabet  is defined inductively as follows: Basis: , , and  (for all ) are regular expressions. Induction: If r and s are regular expressions then the following expressions are also regular: (r) , r+s, r  s and r*. Rina Zviel-Girshin @ASC

Rina Zviel-Girshin @ASC Examples over ={a,b} , a, a+b, b*, (a+b)b, ab*, a*+b* To avoid using to many parentheses, we assume that the operations have the following priority hierarchy: * - highest (do it first)  + - lowest (do it last) So: (b+(a (b*)) = b + ab* Rina Zviel-Girshin @ASC

Rina Zviel-Girshin @ASC Examples over ={0,1} L1 = { w | w has a single 1} r1 = 0*10*   L2 = { w | w has at least one 1} r2 = (0+1)*1 (0+1)*= *1* L3 = { w | w contains the string 110} r3 = (0+1)*110(0+1)* = *110* Rina Zviel-Girshin @ASC

Rina Zviel-Girshin @ASC Examples over ={0,1} L4 = { w | |w| mod 2 =0} r4 = ((0+1) (0+1))* = ()*   L5 = { w | w starts with 1} r5 = 1(0+1)* = 1* L6 = { w | w ends with 00} r6 = (0+1)*00 = *00 Rina Zviel-Girshin @ASC

Rina Zviel-Girshin @ASC Examples over ={0,1} L7 = { w | w starts with 0 and ends with 10} r7 = 0(0+1)*10 = 0*10    L8 = { w | w contains the string 010 or the string 101 } r8 = (0+1)* 010 (0+1)* + (0+1)* 101 (0+1)*= (0+1)*(010+101)(0+1)* = *(010+101)*    L9 = { w | w starts and ends with the same letter } r9 = 0(0+1)*0 + 1(0+1)*1 + 0 +1 = 0*0 + 1*1 + 0 +1 Rina Zviel-Girshin @ASC

Regular languages and regular expressions We associate each regular expression r with a regular language L(r) as follows: L()=, L()={}, L()={} for each , L(r+s)=L(r)L(s), L(r  s)=L(r)  L(s), L(r*)=(L(r))*. Rina Zviel-Girshin @ASC

Properties of regular expressions 1 Some useful properties of regular expressions r+s=s+r r+=+r r+r=r r=r= rr*=r+ r=r=r Rina Zviel-Girshin @ASC

Properties of regular expressions 2 r(s+t)=rs+rt r+(s+t)=(r+s)+t r(st)=(rs)t r+r*=(r*)*=r*r*=r* r*+r+=r* Rina Zviel-Girshin @ASC

Equivalence of regular expressions To prove that two regular expressions r and s are equivalent we have to prove that L[r]L[s] and L[s]L[r]. To show that two regular expressions are not equivalent we have to find a word that belongs to one expression and does not belong to the other. Rina Zviel-Girshin @ASC

Rina Zviel-Girshin @ASC Example Are r and s equivalent? r=+(0+1)*1 s=(0*1)* Rina Zviel-Girshin @ASC

Rina Zviel-Girshin @ASC L[s]L[r] Let wL[s] =(0*1)*. w= or w=x1x2..xn , n0 such that xiL[0*1], i=0,..n. If w= then wL[r]. If w=x1x2..xn than we can represent w=w’1=x1x2..xn-100001 with zero or more 0.  But w’= x1x2..xn-10000L[(0+1)*].  So wL[r]. Rina Zviel-Girshin @ASC

Rina Zviel-Girshin @ASC L[r]L[s] Let wL[r]=+(0+1)*1. If w= then wL[s] (by definition of *). If w then can be represented as w=w’1 where w’L[(0+1)*]. Assume that in w’ contains k instances of the letter 1. That means that w’ can be represented as w’= x11x21.. 1xk+1 where xi0*  But then w=w’1= (x11)(x21).. 1)(xk+1 1)  So wL[(0*1)*]. Rina Zviel-Girshin @ASC

Rina Zviel-Girshin @ASC Another example Are r and s equivalent? r=(0+1)*1+0* s=(1+0)(0*1)* No. We choose a word w = . wL[r]=(0+1)*1+0*, because w0*. But wL[s] =(1+0)(0*1)*, as all words in L[s] have at least one letter. Rina Zviel-Girshin @ASC

Rina Zviel-Girshin @ASC Equivalence with FA Regular expressions and finite automata are equivalent in terms of the languages they describe. Theorem: A language is regular if”f some regular expression describes it.   This theorem has two directions. We prove each direction separately. Rina Zviel-Girshin @ASC

Rina Zviel-Girshin @ASC Converting RE into FA If a language is described by a regular expression, then it is regular.   Proof idea: Transformation of some regular expression r into a finite automaton N that accepts the same language L(r). Rina Zviel-Girshin @ASC

Rina Zviel-Girshin @ASC RE to FA Algorithm Given r we start the algorithm with N having a start state, a single accepting state and an edge labeled r: Rina Zviel-Girshin @ASC

RE to FA Algorithm (cont.) Now transform this machine into an NFA N by applying the following rules until all the edges are labeled with either a letter  from  or : 1.If an edge is labeled , then delete the edge. Rina Zviel-Girshin @ASC

RE to FA Algorithm (cont.) 2.Transform any diagram of the type   into the diagram   Rina Zviel-Girshin @ASC

RE to FA Algorithm (cont.) 3.Transform any diagram of the type   into the diagram   Rina Zviel-Girshin @ASC

RE to FA Algorithm (cont.) 4.Transform any diagram of the type   into the diagram   Rina Zviel-Girshin @ASC

Rina Zviel-Girshin @ASC Example Construct an NFA for the regular expression b*+ ab. We start by drawing the diagram: Rina Zviel-Girshin @ASC

Rina Zviel-Girshin @ASC Example (cont.) Next we apply rule 2 for b*+ab: Rina Zviel-Girshin @ASC

Rina Zviel-Girshin @ASC Example (cont.) Next we apply rule 3 for ab: Rina Zviel-Girshin @ASC

Rina Zviel-Girshin @ASC Example (cont.) Next we apply rule 4 for b*: Rina Zviel-Girshin @ASC

Transforming a FA into RE If a language is regular , then it is described by a regular expression.   Proof idea: transformation of some finite automaton N into a regular expression r that represents the regular language accepted by the finite automaton L(N). Rina Zviel-Girshin @ASC

Transforming a FA into RE The algorithm will perform a sequence of transformations into new machines with edges labeled with regular expressions. It stops when the machine has : two states: start finish one edge with regular expression on it. Rina Zviel-Girshin @ASC

Rina Zviel-Girshin @ASC Algorithm FA to RE Assume we have a DFA or an NFA N=(Q, , , q0, F). Perform the following steps. 1. Create a new start state s and draw a new edge labeled with  from s to the q0. (s,)= q0 . Rina Zviel-Girshin @ASC

Algorithm FA to RE (cont.) 2. Create a new accepting state f and draw new edges labeled with  from all the original accepting states to f. For each qF (q,)= f . Rina Zviel-Girshin @ASC

Algorithm FA to RE (cont.) 3. For each pair of states i and j that have more than one edge from i to j, replace all the edges from i to j by a single edge labeled with the regular expression formed by the sum of the labels of all edges from i to j. Rina Zviel-Girshin @ASC

Algorithm FA to RE (cont.) 4. Construct a sequence of new machines by eliminating one state at a time until the only two states remaining are s and f. As each state is eliminated a new machine is constructed in the following way: Rina Zviel-Girshin @ASC

Algorithm FA to RE (cont.) Eliminating state k Let old(i,j) denote the label on edge <i,j> of the current machine. If there is no an edge <i,j> then old(i,j)=. Now for each pair of edges <i,k> and <k,j>, where ik and jk, calculate a new edge labeled new(i,j) as follows: new(i,j)=old(i,j) + old(i,k)old(k,k)*old(k,j) Rina Zviel-Girshin @ASC

Algorithm FA to RE (cont.) new(i,j)=old(i,j) + old(i,k)old(k,k)*old(k,j) Rina Zviel-Girshin @ASC

Algorithm FA to RE (cont.) For all other edges <i,j> where ik and jk, new(i,j)=old(i,j). The states of the new machine are those of the current machine with state k eliminated. The edges of the new machine are those edges <i,j> for which new(i,j) has been calculated. Rina Zviel-Girshin @ASC

Algorithm FA to RE (cont.) Now s and f are two remaining states. Regular expression new(s,f) represents the language of the original automaton. Rina Zviel-Girshin @ASC

Rina Zviel-Girshin @ASC Example Transform into regular expression the following DFA Rina Zviel-Girshin @ASC

Rina Zviel-Girshin @ASC Example The result of first three steps of the algorithm: new start state new final state unify multiple edges Rina Zviel-Girshin @ASC

Example Eliminate state 2 No paths pass through 2. There are no states that connect through 2. So no need to change anything after deletion of state 2. new(i,j)=old(i,j) for all i,j. Rina Zviel-Girshin @ASC

Example Eliminate state 0 The only path through it is s  q1. We delete q0 and edges sq0 and q0q1. Instead we add an edge that is labeled by regular expression associated with the deleted edges. new(s,q1)=old(s,q1)+old(s,q0)old(q0,q0)*old(q0,q1)=+*a=a Rina Zviel-Girshin @ASC

Rina Zviel-Girshin @ASC Example Eliminate state q1 The only path through it is s  f. new(s,f)=old(s,f) + old(s,q1)old(q1,q1)*old(q1,f) =+a(a+b)* = a(a+b)* Rina Zviel-Girshin @ASC

Rina Zviel-Girshin @ASC Any Questions? Rina Zviel-Girshin @ASC