1 Introduction to the Theory of Computation Regular Expressions.

Slides:



Advertisements
Similar presentations
Complexity and Computability Theory I Lecture #4 Rina Zviel-Girshin Leah Epstein Winter
Advertisements

Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
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 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY (For next time: Read Chapter 1.3 of the book)
CS 310 – Fall 2006 Pacific University CS310 Regular Expressions Sections:1.3 page 63 September 18, 2006 September 20, 2006.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
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.
Fall 2004COMP 3351 Single Final State for NFA. Fall 2004COMP 3352 Any NFA can be converted to an equivalent NFA with a single final state.
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)
FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such.
1 Regular Languages Finite Automata eg. Supermarket automatic door: exit or entrance.
CS 310 – Fall 2006 Pacific University CS310 Homework 2 & JFLAP September 22, 2006.
Lecture 5UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 5.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
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.
1 Regular Expressions Definitions Equivalence to Finite Automata.
Regular Expressions (RE) Empty set Φ A RE denotes the empty set Empty string λ A RE denotes the set {λ} Symbol a A RE denotes the set {a} Alternation M.
Regular Expressions. Notation to specify a language –Declarative –Sort of like a programming language. Fundamental in some languages like perl and applications.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Theory of Languages and Automata
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.
MA/CSSE 474 Theory of Computation Regular Expressions Intro.
Lecture 5 Sept 06, 2012 Regular expressions – examples Converting DFA to regular expression. (same works for NFA to r.e. conversion.) Converting R.E. to.
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
CMSC 330: Organization of Programming Languages Theory of Regular Expressions Finite Automata.
1 Regular Expressions Reading: Chapter 3. 2 Regular Expressions vs. Finite Automata Offers a declarative way to express the pattern of any string we want.
CSCI 2670 Introduction to Theory of Computing September 13.
Lecture Notes 
CS 154 Formal Languages and Computability February 11 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
Regular Expressions CS 130: Theory of Computation HMU textbook, Chapter 3.
 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.
CSCI 2670 Introduction to Theory of Computing September 7, 2004.
CSCI 2670 Introduction to Theory of Computing September 11, 2007.
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
Complexity and Computability Theory I Lecture #5 Rina Zviel-Girshin Leah Epstein Winter
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.
MA/CSSE 474 Theory of Computation Regular Expressions Intro.
1/29/02CSE460 - MSU1 Nondeterminism-NFA Section 4.1 of Martin Textbook CSE460 – Computability & Formal Language Theory Comp. Science & Engineering Michigan.
Theory of Languages and Automata By: Mojtaba Khezrian.
Regular Expressions.
Formal Language & Automata Theory
Regular Expressions Sections:1.3 page 63 September 17, 2008
Complexity and Computability Theory I
REGULAR LANGUAGES AND REGULAR GRAMMARS
COT 4210 Lecture Notes - 3 By Njegos and Monika.
CS 154, Lecture 3: DFANFA, Regular Expressions.
Definitions Equivalence to Finite Automata
Definitions Equivalence to Finite Automata
Regular Expressions.
CSCI 2670 Introduction to Theory of Computing
CSCI 2670 Introduction to Theory of Computing
CS21 Decidability and Tractability
CS21 Decidability and Tractability
Definitions Equivalence to Finite Automata
Chapter 1 Regular Language
Finite-State Machines with No Output
CSCI 2670 Introduction to Theory of Computing
COSC 3340: Introduction to Theory of Computation
COSC 3340: Introduction to Theory of Computation
Presentation transcript:

1 Introduction to the Theory of Computation Regular Expressions

2 1.1 Finite Automata  Deterministic FA  Non-Deterministic FA  NFA = DFA  -NFA  -NFA = NFA

3 1.2 Regular Expressions  Regular Expression  RE  -NFA  DFA  RE

4 Regular Expressions  we can use some regular operations to build up expressions describing languages, which are called regular expressions.  Example: 01*+10*

5 Inductive Definition of RE  R is a regular expression if R is 1.Ø, the empty set 2., the empty string 3.a, for some a  Σ 4.R 1 +R 2, where R 1 and R 2 are reg. exp. 5.R 1 R 2, where R 1 and R 2 are reg. exp. 6.R 1 *, where R 1 is a regular expression What are the differences between empty set Ø and empty string ? Basis Induction

6 Language of a RE  A regular expression R describes the language L(R) L( Ø ) = Ø L() = {} L(a) = {a} L(R 1 +R 2 ) = L(R 1 )L(R 2 ) L(R 1 R 2 ) = L(R 1 )L(R 2 ) L(R 1 *) = (L(R 1 ))* union concatenation closure

7 Concatenation of Languages  If L 1 and L 2 are languages, we can define the concatenation L 1 L 2 = {w | w=xy, xL 1, yL 2 }  Examples: {ab, ba}{cd, dc} =? {abcd, abdc, bacd, badc} Ø {ab} =? Ø

8 Exponentiation of a Language  L i is the language L concatenated with itself i times.  Recursive definition: Base: L 0 = {} Induction: L i+1 = LL i  Example: {ab, ba} 2 =? {abab, abba, baab, baba} Ø 0 =? {} Ø 2 =? {}

9 Kleene Closure  L* =   i=0 L i = L 0  L 1  L 2  …  Examples: {ab, ba}* =? {, ab, ba, abab, abba, … } Ø * =? {} {}* =? {}  L + = L 1  L 2  …

10 Example  Order of precedence for operators: ( ) > Closure > Concatenation > Union  L = {w | 0 and 1 alternate in w}, Σ={0, 1}, how to describe L in a regular expression? (01)*+(10)*+0(10)*+1(01)* Or ?

Regular Expressions  Regular Expression  RE  -NFA  DFA  RE

12 Regular Language  A language is regular if and only if some nondeterministic finite automaton recognizes it.  Main Theorem: A language is regular (i.e.,recognized by a finite automaton) if and only if some regular expression describes it.

13 Lemma  Lemma: If a language is described by a regular expression, then it is regular.  Say that we have a regular expression R describing some language A. We show how to convert R into an NFA recognizing A. If an NFA recognizes A then A is regular.

14 From RE to -NFA  For every regular expression R, we can construct an -NFA A, s.t. L(A) = L(R).  Proof by structural induction: Ø: : a: a

15 From RE to -NFA R+S: RS: R*: R S     R S  R     This is a proof by structural induction!

16 Example: (0+1)*1(0+1)     0 1     0 1        0 1  1      0 1   

17 Example 1.31: (a+b)*aba     a b     a  b  a

Regular Expressions  Regular Expression  RE  -NFA  DFA  RE

19 Lemma  Lemma: If a language is regular, then it is described by a regular expression.  Idea: If a language is regular, it is accepted by a DFA. We need to describe a procedure for converting DFAs into equivalent regular expressions.

20 From DFA to RE  For every DFA A=(Q, Σ, , q 0, F), there is a regular expression R, s.t. L(R) = L(A).  Proof Let Q = {1, 2, … n} and q 0 = 1; Let R[i, j] k be a RE describing the set of all label paths in A from state i to state j going through the states {1, … k} only. Then the union of all R[1, j] n (jF) will be the final RE describing the language of A

21 From DFA to RE We computes the R[i, j] k inductively  Initially (k=0): R[i, i] = +a+b+ …, whenever (i, a)=(i, b)=i, etc. R[i, j] = a+b+ …, if ij and (i, a)=(i, b)=j, etc. R[i, j] = Ø, if ij and there are no direct transitions from state i to state j.

22 From DFA to RE R[i, j] k is computed as:  A path that goes through the states {1, … k} only either never goes through state k, in which case the path's label is in the language of R[i, j] k-1 or goes through k one or more times. In this case:  R[i, k] k-1 contains the portion of the path that goes from i to k for the first time.  (R[k, k] k-1 )* contains the portion of the path (possibly empty) from the first k visit to the last.  R[k, j] k-1 contains the portion of the path from the last k visit to state j.  R[i, j] k = R[i, j] k-1 + R[i, k] k-1 (R[k, k] k-1 )* R[k, j] k-1

23 Example  L(A) = {x0y | x{1}*, y{0, 1}*} 1 0, R[1, 1] 0 +1 R[1, 2] 0 0 R[2, 1] 0 Ø R[2, 2] 0 +0+1 k = 0

24 Example Cont ’ d  We need the following simplification rules: (+R)* = R* R+RS* = RS* Ø R = R Ø = Ø (Annihilation) Ø +R = R+ Ø = R (Identity)

25 Example Cont ’ d R[1, 1] 0 +1 R[1, 2] 0 0 R[2, 1] 0 Ø R[2, 2] 0 +0+1 R[1, 1] 1 +1+(+1)(+1)*(+1) = 1* R[1, 2] 1 0+(+1)(+1)*0 = 1*0 R[2, 1] 1 Ø + Ø (+1)*(+1) = Ø R[2, 2] 1 +0+1+ Ø (+1)*0 = +0+1 k = 1

26 Example Cont ’ d R[1, 1] 1 1* R[1, 2] 1 1*0 R[2, 1] 1 Ø R[2, 2] 1 +0+1 R[1, 1] 2 1*+ 1*0(+0+1)* Ø = 1* R[1, 2] 2 1*0+1*0(+0+1)*(+0+1) = 1*0(0+1)* R[2, 1] 2 Ø +(+0+1)(+0+1)* Ø = Ø R[2, 2] 2 +0+1+(+0+1)(+0+1)*(+0+1) = 0+1 k = 2

27 Example Cont ’ d  The final regular expression for A is R[1, 2] 2 = 1*0(0+1)*

28 Generalized nondeterministic FAs  A generalized nondeterministic FA is a nondeterministic FA wherein the transition arrows may have any regular expressions as labels. Further we require GNFA satisfy the following three conditions:  The start state has transition arrows going to every other state but no arrows coming in from any other state.  There is only a single accept state, and it has arrows coming in from every other state but no arrows going to any other state. Furthermore, the accept state is not the same as the start state.  Except for the start and accept states, one arrow goes from every state to every other state and also from each state to itself.

29 Example: GNFA q start q accept ab*  bab (aa)*a* aa

30 GNFA  Label the edges of the FA with regular expressions instead of symbols.  Add a new start state, q start, with an  edge to the old start state and a new accept state, q accept, with  arrows from the old accept states.  Idea: eliminate the states step by step except q start and q accept, the regular expression on the label is the answer.

31 DFA -> RE

32 Crucial step  We do so by selecting a state, ripping it out of the machine, and repairing the remainder so that the same language is still recognized. Any state will do, provided that it is not the start or accept state.  Let's call the removed state qrip.

33 Crucial step qi qj q0 qiqj R4 R1 R3 R2 R1(R2)*R3+R4 What if qi = qj?

34 Crucial step qi q0 qi R4 R1 R3 R2 R1(R2)*R3+R4 if qi = qj?

35 Example 1: two states DFA

36 Example 2: three states DFA

37 Example 2: three states DFA

38 Algebraic Laws for RE  Regexs E and F are equivalent: L(E) = L(F).  (E + F) + G = E + (F + G) Union is associative  E + F = F + E Union is commutative  Ø + E = E + Ø = E Ø is identity for union  E + E = E Union is idempotent

39 Algebraic Laws for RE  (E F) G = E (F G) Concatenation is associative   E = E  = E  is right and left identity for concatenation  Ø E = E Ø = Ø Ø is right and left annihilator for concatenation  E (F + G) = E F + E G Concatenation is left distributive over union  (F + G) E = F E + G E Concatenation is right distributive over union

40 Algebraic Laws for RE  Ø * =   * =   (E*)* = E* Closure is idempotent  E* = EE* + 

41 Assignment 2 1. Convert 0*(100*)* to an -NFA 2. Eliminate the  arcs in your answer 3. Convert the following FA into RE: s t q p