MA/CSSE 474 Theory of Computation Regular Expressions Intro.

Slides:



Advertisements
Similar presentations
Regular Languages and Regular Grammars Chapter 3.
Advertisements

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.
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
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)
MA/CSSE 474 Theory of Computation
1 Regular Expressions/Languages Regular languages –Inductive definitions –Regular expressions syntax semantics Not covered in lecture.
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.
Dept. of Computer Science & IT, FUUAST Automata Theory 2 Automata Theory III Languages And Regular Expressions Construction of FA’s for given languages.
Chapter 2 Languages.
Finite-State Machines with No Output
1 Proof of the Day: Let P= {(b, acbb), (aac, a), (b, ca)}. 1.Prove that P has a match. 2. Find Q which is P encoded in binary. 3.What match of Q corresponds.
Finite State Machines Chapter 5. Languages and Machines.
CSC312 Automata Theory Lecture # 2 Languages.
TM Design Universal TM MA/CSSE 474 Theory of Computation.
1 Language Definitions Lecture # 2. Defining Languages The languages can be defined in different ways, such as Descriptive definition, Recursive definition,
MA/CSSE 474 Theory of Computation DFSM Canonical Form Proof of NDFSM  DFSM ALGORITHM (as much as we have time for) This version includes the "answers"
1 INFO 2950 Prof. Carla Gomes Module Modeling Computation: Language Recognition Rosen, Chapter 12.4.
Automata, Computability, & Complexity by Elaine Rich ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Slides provided by author Slides edited for.
Grammars CPSC 5135.
1 State SymbolRead- Q E(Q) a b a b a b Convert to a DFA: Start state: Final States:
1 Module 14 Regular languages –Inductive definitions –Regular expressions syntax semantics.
MA/CSSE 474 Theory of Computation Kleene's Theorem Practical Regular Expressions.
MA/CSSE 474 Theory of Computation Decision Problems DFSMs.
1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture of a compiler PART II:
MA/CSSE 474 Theory of Computation Regular Expressions Intro.
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.
Regular Expressions Chapter 6 1. Regular Languages Regular Language Regular Expression Finite State Machine L Accepts 2.
1 String v is a prefix of w if w= v y for some string y. String v is a suffix of w if w= x v for some string x. String v is a substring of w if there are.
Regular Expressions Chapter 6.
Regular Expressions Chapter 6. Regular Languages Regular Language Regular Expression Finite State Machine Recognizes or Accepts Generates.
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.
CS355 - Theory of Computation Regular Expressions.
Regular Expressions Chapter 6. Regular Languages Regular Language Regular Expression Finite State Machine L Accepts.
Recursive Definations Regular Expressions Ch # 4 by Cohen
MA/CSSE 474 Theory of Computation Minimizing DFSMs.
Modeling Computation: Finite State Machines without Output
Theory of computation Introduction theory of computation: It comprises the fundamental mathematical properties of computer hardware, software,
Transparency No. 2-1 Formal Language and Automata Theory Homework 2.
Conversions Regular Expression to FA FA to Regular Expression.
1 Introduction to the Theory of Computation Regular Expressions.
1 Some Properties of Regular Languages. 2 Properties Concatenation:Star: Union: Are regular Languages For regular languages and.
Finite State Machines Chapter 5. Languages and Machines.
P Symbol Q E(Q) a b a b a b Convert to a DFA: Start state: Final States:
1 Let S = { π : π is a permutation of {1, 2, 3, …, n} for some integer n ≥ 1 }. (a) List the elements of S for n= 1, 2, and 3. (b) Prove that the set S.
MA/CSSE 474 Theory of Computation How many regular/non-regular languages are there? Closure properties of Regular Languages (if there is time) Pumping.
MA/CSSE 474 Theory of Computation Decision Problems, Continued DFSMs.
Cpt S 317: Spring 2009 Reading: Chapter 3
Practical Regular Expressions
Formal Language & Automata Theory
Properties of Regular Languages
REGULAR LANGUAGES AND REGULAR GRAMMARS
Closure Properties for Regular Languages
Recap lecture 29 Example of prefixes of a language, Theorem: pref(Q in R) is regular, proof, example, Decidablity, deciding whether two languages are equivalent.
MA/CSSE 474 Theory of Computation Minimizing DFSMs.
MA/CSSE 474 Theory of Computation
MA/CSSE 474 Theory of Computation Nondeterminism NFSMs.
Convert to a DFA: Start state: Final States: State Symbol Read- Q E(Q)
More on showing L non-regular
MA/CSSE 474 Theory of Computation
MA/CSSE 474 DFSM to RE Theory of Computation
Convert to a DFA: Start state: Final States: P Symbol Q E(Q) a b.
Minimize # states in a DFSM
CSC312 Automata Theory Kleene’s Theorem Lecture # 12
Kleene’s Theorem (Part-3)
CSC312 Automata Theory Lecture # 2 Languages.
Presentation transcript:

MA/CSSE 474 Theory of Computation Regular Expressions Intro

Your Questions? Monday's class material Reading Assignments HW5 problems Anything else Still more language ambiguity!

Regular Languages Regular Language Regular Expression Finite State Machine Describes Accepts

Regular Expressions The regular expressions over an alphabet  are the strings that can be obtained as follows: 1.  is a regular expression. 2.  is a regular expression. 3. Every element of  is a regular expression. 4. If ,  are regular expressions, then so is . 5. If ,  are regular expressions, then so is . 6. If  is a regular expression, then so is  *. 7.  is a regular expression, then so is  If  is a regular expression, then so is (  )..

Regular Expression Examples If  = { a, b }, the following are regular expressions:   a (a  b)* (abba   ) + (a  bab) 1.  is a regular expression. 2.  is a regular expression. 3. Every element of  is a regular expression. 4. If ,  are regular expressions, then so is . 5. If ,  are regular expressions, then so is . 6. If  is a regular expression, then so is  *. 7.  is a regular expression, then so is  If  is a regular expression, then so is (  ).

Regular Expressions Define Languages Define L, a semantic interpretation function for regular expressions (Let  and  be arbitrary regular expressions over alphabet  ). 1. L(  ) = . 2. L(  ) = {  }. 3. If c  , L(c) = {c}. 4. L(  ) = L(  ) L(  ). 5. L(    ) = L(  )  L(  ). 6. L(  *) = (L(  ))*. 7. L(  + ) = L(  *) = L(  ) (L(  ))*. If L(  ) is equal to , then L(  + ) is also equal to . Otherwise L(  + ) is the language that is formed by concatenating together one or more strings drawn from L(  ). 8. L((  )) = L(  ).

The Roles of the Rules Rules 1, 3, 4, 5, and 6 give the regular expression. language its power to define sets. Rule 8 has grouping other operators as its only role. Rules 2 and 7 appear to add functionality to the regular expression language, but they don’t. 1.  is a regular expression. 2.  is a regular expression. 3. Every element of  is a regular expression. 4. If ,  are regular expressions, then so is . 5. If ,  are regular expressions, then so is . 6. If  is a regular expression, then so is  *. 7.  is a regular expression, then so is  If  is a regular expression, then so is (  ).

Operator Precedence in Regular Expressions RegularArithmeticExpressions HighestKleene * and +exponentiation concatenationmultiplication Lowestunionaddition a b *  c d *x y 2 + y x 2

Analyzing a Regular Expression L(( a  b )* b ) = L(( a  b )*) L( b ) = (L( a  b ))* L( b ) = (L( a )  L( b ))* L( b ) = ({ a }  { b })* { b } = { a, b }* { b }.

From English to reg exps L = {w  { a, b }*: |w| is even} L = {w  { 0, 1 }*: w is a binary representation of a positive multiple of 4} L = {w  { a, b }*: w contains an odd number of a ’s}

Hidden: From English to reg. exprs. L = {w  { a, b }*: |w| is even} ( a  b ) ( a  b ))* ( aa  ab  ba  bb )* L = {w  { 0, 1 }*: w is a binary representation of a positive multiple of 4} 1(0  1)*00 (1  0)* 1000* L = {w  { a, b }*: w contains an odd number of a ’s} b * ( ab * ab *)* a b * b * a b * ( ab * ab *)*

The Details Matter L(a *  b *)  L(( a  b )*) L(( ab )*)  L( a * b *)

More Regular Expression Examples ( aa *)   is equivalent to ( a   )* is equivalent to L = {w  { a, b }*: there is no more than one b in w} L = {w  { a, b }* : no two consecutive letters in w are the same}

The Details Matter L 1 = {w  { a, b }* : every a is immediately followed by b } A regular expression for L 1 : A FSM for L 1 : L 2 = {w  { a, b }* : every a has a matching b somewhere} A regular expression for L 2 : A FSM for L 2 :

Simplifying Regular Expressions Regex’s describe sets: ● Union is commutative:    =   . ● Union is associative: (    )   =   (    ). ●  is the identity for union:    =    = . ● Union is idempotent:    = . Concatenation: ● Concatenation is associative: (  )  =  (  ). ●  is the identity for concatenation:   =   = . ●  is a zero for concatenation:   =   = . Concatenation distributes over union: ● (    )  = (   )  (   ). ●  (    ) = (   )  (   ). Kleene star: ●  * = . ●  * = . ●(  *)* =  *. ●  *  * =  *. ●(    )* = (  *  *)*.

Kleene’s Theorem Finite state machines and regular expressions define the same class of languages. To prove this, we must show: Theorem: Any language that can be defined by a regular expression can be accepted by some FSM and so is regular. We do reg. exp.  NDFSM because it is easiest, and this is sufficient becausewe already know NDFSM  DFSM) Theorem: Every regular language (i.e., every language that can be accepted by some DFSM) can be defined with a regular expression.

For Every Regular Expression There is a Corresponding FSM We’ll show this by construction. An FSM for:  : A single element c of  :  :

Union If  is the regular expression    and if both L(  ) and L(  ) are regular:

Concatenation If  is the regular expression  and if both L(  ) and L(  ) are regular:

Kleene Star If  is the regular expression  * and if L(  ) is regular:

An Example (b  ab )* An FSM for b An FSM for a An FSM for b An FSM for ab :

An Example ( b  ab )* An FSM for ( b  ab ):

An Example ( b  ab )* An FSM for ( b  ab )*: