Regular Expressions Section 1.3 (also 1.1, 1.2) CSC 4170 Theory of Computation.

Slides:



Advertisements
Similar presentations
CSC 361NFA vs. DFA1. CSC 361NFA vs. DFA2 NFAs vs. DFAs NFAs can be constructed from DFAs using transitions: Called NFA- Suppose M 1 accepts L 1, M 2 accepts.
Advertisements

Finite Automata CPSC 388 Ellen Walker Hiram College.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
1 Introduction to Computability Theory Discussion1: Conversion of A DFA to a Regular Expression Prof. Amos Israeli.
Regular expressions Regular languages Sipser 1.3 (pages 63-76)
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Regular expressions Regular languages Sipser 1.3 (pages 63-76)
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 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY (For next time: Read Chapter 1.3 of the book)
1 Introduction to Computability Theory Lecture2: Non Deterministic Finite Automata (cont.) Prof. Amos Israeli.
CS 310 – Fall 2006 Pacific University CS310 Regular Expressions Sections:1.3 page 63 September 18, 2006 September 20, 2006.
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)
79 Regular Expression Regular expressions over an alphabet  are defined recursively as follows. (1) Ø, which denotes the empty set, is a regular expression.
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
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 Non-Deterministic Automata Regular Expressions.
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.
Fall 2004COMP 3351 Regular Expressions. Fall 2004COMP 3352 Regular Expressions Regular expressions describe regular languages Example: describes the language.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA to regular.
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.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to DFA.
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 Chapter 6 1. Regular Languages Regular Language Regular Expression Finite State Machine L Accepts 2.
CHAPTER 1 Regular Languages
January 9, 2015CS21 Lecture 31 CS21 Decidability and Tractability Lecture 3 January 9, 2015.
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.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
Conversions & Pumping Lemma CPSC 388 Fall 2001 Ellen Walker Hiram College.
Regular Expressions Chapter 6. Regular Languages Regular Language Regular Expression Finite State Machine L Accepts.
CSCI 2670 Introduction to Theory of Computing September 13.
Computability Regular expressions. Languages defined by regular expresses = Regular languages (languages recognized by FSM). Applications. Pumping lemma.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
CS 154 Formal Languages and Computability February 11 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
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.
CSCI 2670 Introduction to Theory of Computing September 11, 2007.
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
NFA’s with  Transitions We extend the class of NFAs by allowing instantaneous transitions: 1.The automaton may be allowed to change its state without.
What do we know? DFA = NFA =  -NFA We have seen algorithms to transform DFA to NFA (trival) NFA to  NFA (trivial) NFA to DFA (subset construction)
Theory of Computation Automata Theory Dr. Ayman Srour.
Lecture 09: Theory of Automata:2014 Asif NawazUIIT, PMAS-Arid Agriclture University Rawalpindi. Kleene’s Theorem and NFA.
Kleene’s Theorem and NFA
Regular Expressions Sections:1.3 page 63 September 17, 2008
Complexity and Computability Theory I
CSC 4170 Theory of Computation Nondeterminism Section 1.2.
REGULAR LANGUAGES AND REGULAR GRAMMARS
CS 154, Lecture 3: DFANFA, Regular Expressions.
CSCI 2670 Introduction to Theory of Computing
CSCI 2670 Introduction to Theory of Computing
CS21 Decidability and Tractability
CSC 4170 Theory of Computation Nondeterminism Section 1.2.
CSC312 Automata Theory Kleene’s Theorem Lecture # 12
CHAPTER 1 Regular Languages
CSCI 2670 Introduction to Theory of Computing
Intro to Theory of Computation
CSCI 2670 Introduction to Theory of Computing
Presentation transcript:

Regular Expressions Section 1.3 (also 1.1, 1.2) CSC 4170 Theory of Computation

Regular operations 1.3.a Union: L1  L2 = {x | x  L1 or x  L2} {Good,Bad}  {Boy,Girl} = {0,00,000,…}  {1,11,111,…} = L  = Concatenation: L1  L2 = {xy | x  L1 and y  L2} {Good,Bad}  {Boy,Girl} = {0,00,000,…}  {1,11,111,…} = L   = Star: L * = {x 1 …x k | k  0 and each x i  L} {Boy,Girl} * = {0,00,000,…} * =  * =

Regular expressions 1.3.b We say that R is a regular expression (RE) iff R is one of the following: 1. a, where a is a symbol of the alphabet 2.  3.  4. (R1)  (R2), where R1 and R2 are RE 5. (R1)  (R2), where R1 and R2 are RE 6. (R1)*, where R1 is a RE What language is represented by the expression: {a} {  }  The union of the languages represented by R1 and R2 The concatenation of the languages represented by R1 and R2 The star of the language represented by R1 Conventions:  The symbol  is often omitted in RE  Some parentheses can be omitted. The precedence order for the operators is: * (highest),  (medium),  (lowest)

Regular languages 1.3.c A language is said to be regular iff it can be represented by a regular expression. Language Expression {11} {Boy, Girl, Good, Bad} { ,0,00,000,0000,…} {0,00,000,0000,…} { ,01,0101,010101, ,…} {x | x = 0 k where k is a multiple of 2 or 3} {x | x is divisible by 8} {x | x MOD 4 = 3}

Exercising reading regular expressions 1.3.d Expression Language 0*10* (Good  Bad)(Boy  Girl) (Tom  Bob)_is_(good  bad) {Name_is_adjective | Name is an uppercase letter followed by zero or more lowercase letters, and adjective is a lowercase letter followed by zero or more lowercase letters} (0  1)*101(0  1)* ( (0  1)(0  1) ) *

Regular languages and DFA-recognizable languages are the same 1.3.e Theorem 1.54* A language is regular if and only if some NFA (DFA) recognizes it. In other words, a) [The “only if” part] For every regular expression there is an NFA that recognizes exactly the language represented by that expression. b) [The “if” part] For every NFA there is a regular expression that represents exactly the language recognized by that NFA.

Constructing an NFA from a regular expression: Base cases 1.3.f Case of a, where a is a symbol of the alphabet. Case of  Case of 

Constructing an NFA from a regular expression: Case of union 1.3.g Case of (R1)  (R2), where R1 and R2 are RE First, construct NFAs N1 and N2 from R1 and R2: s1 N1 N2 s2 Then, combine them in the following way: s1 N1 N2 s2

Constructing an NFA from a regular expression: Case of concatenation 1.3.h Case of (R1)  (R2), where R1 and R2 are RE First, construct NFAs N1 and N2 from R1 and R2: N1 s2 N2 Then, combine them in the following way: N1 s2 N2 s1

Constructing an NFA from a regular expression: Case of star 1.3.i Case of (R1) *, where R1 is a RE First, construct an NFA N1 from R1: s1 N1 Then, extend it in the following way: s1 N1

Constructing an NFA from a regular expression: An example 1.3.j #(0  1)* (0  1)* # 0       0 1 # #011

GNFA 1.3.k great (great)* grand mother  father grand  g r e a t g r e a t g r e a t g r a n d f a t h e r  

About  -transitions 1.3.l great (great)* grand mother  father grand  Adding or removing  -transitions does not change the recognized language 

The same GNFA simplified 1.3.m great grand mother  father  

Ripping a state out 1.3.n mother  father grand (great)* 

Eliminating parallel transitions 1.3.o mother  father   (great)*grand

Again ripping out 1.3.p (   (great)*grand) (mother  father)

How, exactly, to do ripping out 1.3.q1 Assume, we are ripping out the state r from a GNFA that has no parallel transitions. Let L be the label of the loop from r to r (if there is no loop, then L=  ). L T R S

How, exactly, to do ripping out 1.3.q2 Assume, we are ripping out the state r from a GNFA that has no parallel transitions. Let L be the label of the loop from r to r (if there is no loop, then L=  ). 1. For every pair s 1,s 2 of states such that there is an E 1 -labeled transition from s 1 to r and an E 2 -labeled transition from r to s 2, add an R 1 L*R 2 -labeled transition from s 1 to s 2 ; L T R S RL*T SL*T

How, exactly, to do ripping out 1.3.q3 Assume, we are ripping out the state r from a GNFA that has no parallel transitions. Let L be the label of the loop from r to r (if there is no loop, then L=  ). 1. For every pair s 1,s 2 of states such that there is an E 1 -labeled transition from s 1 to r and an E 2 -labeled transition from r to s 2, add an R 1 L*R 2 -labeled transition from s 1 to s 2 ; 2. Delete r together with all its incoming and outgoing transitions. RL*T SL*T

How, exactly, to eliminate parallel transitions 1.3.r Whenever you see parallel transitions labeled with R1 and R2, Replace them by a transition labeled with R1  R2. R1 R2 R1  R2 Repeat until there are no parallel transitions remaining.

From NFA to RE 1.3.s a b b b

From NFA to RE: Step t Step 1: If there are incoming arrows to the start state, or the start state is an accept state, then add a new start state and connect it with an  -arrow to the old start state. a b b b  a

From NFA to RE: Step u a b b b  Step 2: If there are more than one, or no, accept states, or there is an accept state that has outgoing arrows, then add a new accept state, make all the old accept states non-accept states and connect each of them with an  -arrow to the new accept state.   a

From NFA to RE: Step v a b b b    Step 3: Eliminate all parallel transitions. a

From NFA to RE: Step w1 b b   Step 4: While there are internal states (states that are neither the start nor the accept state), do the following: Step 4.1: Select an internal state and rip it out; Step 4.2: Eliminate all parallel transitions. a b aa ab

From NFA to RE: Step w2 b b  aa   Step 4: While there are internal states (states that are neither the start nor the accept state), do the following: Step 4.1: Select an internal state and rip it out; Step 4.2: Eliminate all parallel transitions. a b ab

From NFA to RE: Step w3  Step 4: While there are internal states (states that are neither the start nor the accept state), do the following: Step 4.1: Select an internal state and rip it out; Step 4.2: Eliminate all parallel transitions. b a(b  aa)* b(b  aa)* b(b  aa)*ab a(b  aa)*ab

From NFA to RE: Step w4 Step 4: While there are internal states (states that are neither the start nor the accept state), do the following: Step 4.1: Select an internal state and rip it out; Step 4.2: Eliminate all parallel transitions. a(b  aa)*   b(b  aa)* b(b  aa)*ab b  a(b  aa)*ab

From NFA to RE: Step w5 Step 4: While there are internal states (states that are neither the start nor the accept state), do the following: Step 4.1: Select an internal state and rip it out; Step 4.2: Eliminate all parallel transitions. a(b  aa)* ( b  a(b  aa)*ab ) ( b(b  aa)*ab ) * (   b(b  aa)* )

From NFA to RE: Step w6 Step 4: While there are internal states (states that are neither the start nor the accept state), do the following: Step 4.1: Select an internal state and rip it out; Step 4.2: Eliminate all parallel transitions. ( ( b  a(b  aa)*ab ) ( b(b  aa)*ab ) * (   b(b  aa)* )  ( a(b  aa)* )

From NFA to RE: Step x Step 5: Return the label of the only remaining arrow (if there is no arrow, return  ). Claim: The resulting RE represents exactly the language recognized by the original NFA. This completes the proof of Theorem ( ( b  a(b  aa)*ab ) ( b(b  aa)*ab ) * (   b(b  aa)* )  ( a(b  aa)* )