Cpt S 317: Spring 2009 Reading: Chapter 3

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

1 Midterm I review Reading: Chapters Test Details In class, Wednesday, Feb. 25, :10pm-4pm Comprehensive Closed book, closed notes.
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Regular.
Lecture 7 Sept 22, 2011 Goals: closure properties regular expressions.
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
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 Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Regular Expressions. Notation to specify a language –Declarative –Sort of like a programming language. Fundamental in some languages like perl and applications.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
Automata, Computability, & Complexity by Elaine Rich ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Slides provided by author Slides edited for.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to DFA.
CSCI 2670 Introduction to Theory of Computing September 1, 2005.
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.
Formal Definition of Computation Let M = (Q, ∑, δ, q 0, F) be a finite automaton and let w = w 1 w w n be a string where each wi is a member of the.
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.
1 Regular Expressions Definitions Equivalence to Finite Automata.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 1 Regular Languages Some slides are in courtesy.
Recap: Transformation NFA  DFA  s s1s1... snsn p1p1 p2p2... pmpm >...  p1p1  p2p2  pipi s e s1s1 e s2s2 e sisi >
Finite Automata Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture 20Mar 30, 2010Carnegie Mellon.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
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.
A new Computation System DFAs, NFs, Λ-NFAs all describe a language in an operational manner. They describe a machine that one can execute in order to recognize.
MA/CSSE 474 Theory of Computation Regular Expressions Intro.
Lecture 15: Theory of Automata:2014 Finite Automata with Output.
Advanced Theory of Computation Lecture # 1-2 Muhammad Ahmad Jan 1.
3. Regular Expressions and Languages
Foundations of Computing Science
PROPERTIES OF REGULAR LANGUAGES
Regular Expressions.
FORMAL LANGUAGES AND AUTOMATA THEORY
CSE 105 theory of computation
Formal Language & Automata Theory
Lecture 9 Theory of AUTOMATA
Closure Properties of Regular Languages
Lecture 10 Closure Properties of Regular Languages
Single Final State for NFA
Jaya Krishna, M.Tech, Assistant Professor
REGULAR LANGUAGES AND REGULAR GRAMMARS
Chapter Seven: Regular Expressions
Cpt S 317: Spring 2009 Reading: Chapters 1-4
Non-Deterministic Finite Automata
CS 154, Lecture 3: DFANFA, Regular Expressions.
Non-Deterministic Finite Automata
Definitions Equivalence to Finite Automata
Definitions Equivalence to Finite Automata
CSE 2001: Introduction to Theory of Computation Fall 2009
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Closure Properties of Regular Languages
Chapter 4 Properties of Regular Languages
Instructor: Aaron Roth
Convert to a DFA: Start state: Final States: State Symbol Read- Q E(Q)
Definitions Equivalence to Finite Automata
Convert to a DFA: Start state: Final States: P Symbol Q E(Q) a b.
CSE 105 theory of computation
Chapter 1 Regular Language
Recap Lecture 15 Examples of Kleene’s theorem part III (method 3), NFA, examples, avoiding loop using NFA, example, converting FA to NFA, examples, applying.
Cpt S 317: Spring 2009 Reading: Chapter 8 & 9
Cpt S 317: Spring 2009 Reading: Chapters 1-4
CSC312 Automata Theory Kleene’s Theorem Lecture # 12
Kleene’s Theorem (Part-3)
NFAs accept the Regular Languages
CSE 105 theory of computation
Presentation transcript:

Cpt S 317: Spring 2009 Reading: Chapter 3 Regular Expressions Reading: Chapter 3 School of EECS, WSU

Regular Expressions vs. Finite Automata Cpt S 317: Spring 2009 Regular Expressions vs. Finite Automata Offers a declarative way to express the pattern of any string we want to accept E.g., 01*+ 10* Automata => more machine-like < input: string , output: [accept/reject] > Regular expressions => more program syntax-like Unix environments heavily use regular expressions E.g., bash shell, grep, vi & other editors, sed Perl scripting – good for string processing Lexical analyzers such as Lex or Flex School of EECS, WSU

Finite Automata (DFA, NFA, -NFA) Cpt S 317: Spring 2009 Regular Expressions = Regular expressions Finite Automata (DFA, NFA, -NFA) Syntactical expressions Automata/machines Regular Languages Formal language classes School of EECS, WSU

Language Operators Union of two languages: Cpt S 317: Spring 2009 Language Operators Union of two languages: L U M = all strings that are either in L or M Note: A union of two languages produces a third language Concatenation of two languages: L . M = all strings that are of the form xy s.t., x  L and y  M The dot operator is usually omitted i.e., LM is same as L.M School of EECS, WSU

Kleene Closure (the * operator) Cpt S 317: Spring 2009 “i” here refers to how many strings to concatenate from the parent language L to produce strings in the language Li Kleene Closure (the * operator) Kleene Closure of a given language L: L0= {} L1= {w | for some w  L} L2= { w1w2 | w1  L, w2  L (duplicates allowed)} Li= { w1w2…wi | all w’s chosen are  L (duplicates allowed)} (Note: the choice of each wi is independent) L* = Ui≥0 Li (arbitrary number of concatenations) Example: Let L = { 1, 00} L1= {1,00} L2= {11,100,001,0000} L3= {111,1100,1001,10000,000000,00001,00100,0011} L* = L0 U L1 U L2 U … School of EECS, WSU

Kleene Closure (special notes) Cpt S 317: Spring 2009 Kleene Closure (special notes) L* is an infinite set iff |L|≥1 and L≠{} If L={}, then L* = {} If L = Φ, then L* = {} Σ* denotes the set of all words over an alphabet Σ Therefore, an abbreviated way of saying there is an arbitrary language L over an alphabet Σ is: L  Σ* Why? Why? Why? School of EECS, WSU

Building Regular Expressions Cpt S 317: Spring 2009 Building Regular Expressions Let E be a regular expression and the language represented by E is L(E) Then: (E) = E L(E + F) = L(E) U L(F) L(E F) = L(E) L(F) L(E*) = (L(E))* School of EECS, WSU

Cpt S 317: Spring 2009 Example: how to use these regular expression properties and language operators? L = { w | w is a binary string which does not contain two consecutive 0s or two consecutive 1s anywhere) E.g., w = 01010101 is in L, while w = 10010 is not in L Goal: Build a regular expression for L Four cases for w: Case A: w starts with 0 and |w| is even Case B: w starts with 1 and |w| is even Case C: w starts with 0 and |w| is odd Case D: w starts with 1 and |w| is odd Regular expression for the four cases: Case A: (01)* Case B: (10)* Case C: 0(10)* Case D: 1(01)* Since L is the union of all 4 cases: Reg Exp for L = (01)* + (10)* + 0(10)* + 1(01)* If we introduce  then the regular expression can be simplified to: Reg Exp for L = ( +1)(01)*( +0) School of EECS, WSU

Precedence of Operators Cpt S 317: Spring 2009 Precedence of Operators Highest to lowest * operator (star) . (concatenation) + operator Example: 01* + 1 = ( 0 . ((1)*) ) + 1 School of EECS, WSU

Finite Automata (FA) & Regular Expressions (Reg Ex) Cpt S 317: Spring 2009 Finite Automata (FA) & Regular Expressions (Reg Ex) To show that they are interchangeable, consider the following theorems: Theorem 1: For every DFA A there exists a regular expression R such that L(R)=L(A) Theorem 2: For every regular expression R there exists an  -NFA E such that L(E)=L(R) Proofs in the book  -NFA NFA Kleene Theorem Theorem 2 Reg Ex DFA Theorem 1 School of EECS, WSU

DFA to RE construction Reg Ex DFA Theorem 1 Cpt S 317: Spring 2009 Reg Ex DFA DFA to RE construction Theorem 1 Informally, trace all distinct paths (traversing cycles only once) from the start state to each of the final states and enumerate all the expressions along the way Example: 0,1 1 1 q0 q1 q2 (1*) (0*) 1 (0 + 1)* 00* 1* 1 (0+1)* Q) What is the language? 1*00*1(0+1)* School of EECS, WSU

RE to -NFA construction Cpt S 317: Spring 2009  -NFA Reg Ex RE to -NFA construction Theorem 2 Example: (0+1)*01(0+1)* (0+1)* 01 (0+1)*  1  1    1  School of EECS, WSU

Algebraic Laws of Regular Expressions Cpt S 317: Spring 2009 Algebraic Laws of Regular Expressions Commutative: E+F = F+E Associative: (E+F)+G = E+(F+G) (EF)G = E(FG) Identity: E+Φ = E  E = E  = E Annihilator: ΦE = EΦ = Φ School of EECS, WSU

Algebraic Laws… Distributive: Idempotent: E + E = E Cpt S 317: Spring 2009 Algebraic Laws… Distributive: E(F+G) = EF + EG (F+G)E = FE+GE Idempotent: E + E = E Involving Kleene closures: (E*)* = E* Φ* =  * =  E+ =EE* E? =  +E School of EECS, WSU

True or False? Let R and S be two regular expressions. Then: Cpt S 317: Spring 2009 True or False? Let R and S be two regular expressions. Then: ((R*)*)* = R* ? (R+S)* = R* + S* ? (RS + R)* RS = (RR*S)* ? School of EECS, WSU

Summary Regular expressions Equivalence to finite automata Cpt S 317: Spring 2009 Summary Regular expressions Equivalence to finite automata DFA to regular expression conversion Regular expression to -NFA conversion Algebraic laws of regular expressions Unix regular expressions and Lexical Analyzer School of EECS, WSU