Transparency No. 4-1 Formal Language and Automata Theory Chapter 4 Patterns, Regular Expressions and Finite Automata (include lecture 7,8,9) Transparency.

Slides:



Advertisements
Similar presentations
Lecture 24 MAS 714 Hartmut Klauck
Advertisements

1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
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.
Introduction to Computability Theory
Transparency No. 2-1 Formal Language and Automata Theory Chapter 2 Deterministic Finite Automata (DFA) (include Lecture 3 and 4)
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
1 Introduction to Computability Theory Lecture2: Non Deterministic Finite Automata (cont.) Prof. Amos Israeli.
Transparency No Formal Language and Automata Theory Chapter 10 The Myhill-Nerode Theorem (lecture 15,16 and B)
Finite Automata Finite-state machine with no output. FA consists of States, Transitions between states FA is a 5-tuple Example! A string x is recognized.
Transparency No. 4-1 Formal Language and Automata Theory Chapter 4 Patterns, Regular Expressions and Finite Automata (include lecture 7,8,9) Transparency.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
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.
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.
1 NFAs accept the Regular Languages. 2 Equivalence of Machines Definition: Machine is equivalent to machine if.
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.
Transparency No. 3-1 Formal Language and Automata Theory Chapter 3 Nondeterministic Finite Automata (NFA) (include lecture 5 and 6)
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
Transparency No. P2C1-1 Formal Language and Automata Theory Part II Pushdown Automata and Context-Free Languages.
Transparency No. ?-0 Formal Language and Automata Theory Chapter 6 Homomorphisms (lecture 10) Transparency No. 6-1.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Fall 2004COMP 3351 Another NFA Example. Fall 2004COMP 3352 Language accepted (redundant state)
Lecture 4UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 4.
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.
Transparency No. 8-1 Formal Language and Automata Theory Chapter 8 DFA state minimization (lecture 13, 14)
Fall 2004COMP 3351 Regular Expressions. Fall 2004COMP 3352 Regular Expressions Regular expressions describe regular languages Example: describes the language.
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Formal Language Finite set of alphabets Σ: e.g., {0, 1}, {a, b, c}, { ‘{‘, ‘}’ } Language L is a subset of strings on Σ, e.g., {00, 110, 01} a finite language,
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
Transparency No. 3-1 Formal Language and Automata Theory Chapter 3 Nondeterministic Finite Automata (NFA)
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
Lecture 05: Theory of Automata:08 Kleene’s Theorem and NFA.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
CHAPTER 1 Regular Languages
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.
CMSC 330: Organization of Programming Languages Theory of Regular Expressions Finite Automata.
NFA defined. NFA A Non-deterministic Finite-state Automata (NFA) is a language recognizing system similar to a DFA. It supports a level of non-determinism.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
CS 203: Introduction to Formal Languages and Automata
Lecture Notes 
Chapter 5 Finite Automata Finite State Automata n Capable of recognizing numerous symbol patterns, the class of regular languages n Suitable for.
Finite Automata Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture 20Mar 30, 2010Carnegie Mellon.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Conversions Regular Expression to FA FA to Regular Expression.
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:
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
Complexity and Computability Theory I Lecture #5 Rina Zviel-Girshin Leah Epstein Winter
Finite Automata A simple model of computation. 2 Finite Automata2 Outline Deterministic finite automata (DFA) –How a DFA works.
Lecture 14: Theory of Automata:2014 Finite Automata with Output.
Lecture #4 Thinking of designing an abstract machine acts as finite automata. Advanced Computation Theory.
Lecture #5 Advanced Computation Theory Finite Automata.
Lecture 15: Theory of Automata:2014 Finite Automata with Output.
1 Chapter 2 Finite Automata (part a) Hokkaido, Japan.
Chapter 2 Regular Languages & Finite Automata. Regular Expressions A finitary denotation of a regular language over . ØL Ø = Ø aL a = {a} where a ∈ 
Non Deterministic Automata
PROPERTIES OF REGULAR LANGUAGES
Hierarchy of languages
CSE322 CONSTRUCTION OF FINITE AUTOMATA EQUIVALENT TO REGULAR EXPRESSION Lecture #9.
Non-Deterministic Finite Automata
CSE 2001: Introduction to Theory of Computation Fall 2009
CS21 Decidability and Tractability
CSC312 Automata Theory Lecture # 24 Chapter # 11 by Cohen Decidability.
COSC 3340: Introduction to Theory of Computation
Presentation transcript:

Transparency No. 4-1 Formal Language and Automata Theory Chapter 4 Patterns, Regular Expressions and Finite Automata (include lecture 7,8,9) Transparency No. 4-1

Patterns, regular expression & FAs Transparency No. 4-2 Patterns and their defined languages  : a finite alphabet A pattern is a string of symbols representing a set of strings in  *. The set of all patterns is defined inductively as follows: 1. atomic patterns: a  , , , 2. compound patterns: if  and  are patterns, then so are:  + ,  ,  *,  +, ~  and . For each pattern , L(  ) is the language represented by  and is defined inductively as follows: 1. L(a) = {a}, L(  ) = {  }, L(  )= {}, L(#) = , =  *. 2. If L(  ) and L(  ) have been defined, then L(  +  ) = L(  ) U L(  ), L(   ) = L(  )  L(  ). L(  + ) = L(  ) +, L(  *) = L(  )*, L(~  ) =  * - L(  ), L(  ) = L(  )  L(  ).

Patterns, regular expression & FAs Transparency No. 4-3 More on patterns We say that a string x matches a pattern  iff x  L(  ). Some examples:  * = = L(#*) 2. L(x) = {x} for any x   * 3. for any x 1,…,x n in  *, L(x 1 +x 2 +…+x n ) = {x 1,x 2,…,x n }. 4. {x | x contains at least 3 a’s} =  - {a} = #  ~a 6. {x | x does not contain a} = (#  ~a)* 7. {x | every ‘a’ in x is followed sometime later by a ‘b’ } = = {x | either no ‘a’ in x or  ‘b’ in x followed no ‘a’ } = (#  ~a)*  ~a)*

Patterns, regular expression & FAs Transparency No. 4-4 More on pattern matching Some interesting and important questions: 1. How hard is it to determine if a given input string x matches a given pattern a ? ==> efficient algorithm exists 2. Can every set be represented by a pattern ? ==> no! the set {a n b n | n > 0 } cannot be represented by any pattern. 3. How to determine if two given patterns  and  are equivalent ? (I.e., L(  ) = L(  )) --- an exercise ! 4. Which operations are redundant ?  = ~(# + =  * ;  + =   * # = a 1 + a 2 +…+ a n if  = {a 1,.., a n }  +  = ~(~   ~  ) ;    = ~ (~  + ~  ) It can be shown that ~ is redundant.

Patterns, regular expression & FAs Transparency No. 4-5 Equivalence of patterns, regular expr. & FAs Recall that regular expressions are those patterns that can be built from: a , , , +,  and *. Notational conventions:  +  means  + (  )  +  * means  + (  *)   * means  (  *) Theorem 8: Let A   *. Then the followings are equivalent: 1. A is regular (I.e., A = L(M) for some FA M ), 2. A = L(  ) for some pattern , 3. A = L(  ) for some regular expression . pf: Trivial part: (3) => (2). (2) => (1) to be proved now! (1)=> (3) later.

Patterns, regular expression & FAs Transparency No. 4-6 (2) => (1) : Every set represented by a pattern is regular Pf: By induction on the structure of pattern . Basis:  is atomic: (by construction!)  = a :  =  :  =  : 4.  = #:  = #* : a   a,b,c,…

Patterns, regular expression & FAs Transparency No. 4-7 Inductive cases: Let M 1 and M 2 be any FAs accepting L(  ) and L(  ), respectively.  =   : => L(  ) = L(M 1  M 2 )  =  * : => L(  ) = L(M 1 *)  =  +  = ~  or  =    : By ind. hyp.  and  are regular. Hence by closure properties of regular languages,  is regular, too.  =  + =   * : Similar to case 8.

Patterns, regular expression & FAs Transparency No. 4-8 Some examples patterns & their equivalent FAs 1. (aaa)* + (aaaaa)*

Patterns, regular expression & FAs Transparency No. 4-9 (1)=>(3): Regular languages can be represented by reg. expr. M = (Q, , , S, F) : a NFA; X  Q: a set of states;   Q : two states  X (  ) = def {y   * |  a path from  to labeled y and all intermediate states  X }. Note: L(M) = ?  X (  ) can be shown to be representable by a regular expr, by induction as follows: Let D( , ) = { a | (  –a    } = {a 1,…,a k } ( k  0) = the set of symbols by which we can reach from  to, then Basic case: X =  : 1.1 if   :   (  ) = {a 1, a 2,…,a k } = L(a 1 + a 2 +…+ a k ) if k > 0, = {} = L(  ) if k = if  = :   (  ) = {a 1, a 2,… a k,  }=L(a 1 + a 2 +…+ a k +  ) if k > 0, = {  } = L(  ) if k = 0.

Patterns, regular expression & FAs Transparency No For nonempty X, let q be any state in X, then :  X (  ) =  X-{q} (  ) U  X-{q} (  q) (  X-{q} (q  q))*  X-{q} (q  ). By Ind.hyp.(why?), there are regular expressions  with L( [  ) = [  X-{q} (  ),  X-{q} (  q), (  X-{q} (q  q)),  X-{q} (q  ) ] Hence  X (  ) = L(  ) U L(  ) L(  ) * L(  ), = L(    and can be represented as a reg. expr. Finally, L(M) = {x | s --x--> f, s  S, f  F } =  s  S, f  F  Q (s,f), is representable by a regular expression.

Patterns, regular expression & FAs Transparency No Example (9.3): M : L(M) = p {p,q,r} (p,p) = p {p,r} (p,p) + p {p,r} (p,q) ( p {p,r} (q,q))* p {p,r} (q,p) p {p,r} (p,p) = ? p {p,r} (p,q) = ? p {p,r} (q,q) = ? p {p,r} (q,p) = ? Some examples Hence L(M) = ? 

Patterns, regular expression & FAs Transparency No Another approach The previous method easy to prove, easy for computer implementation, but hard for human computation. The strategy of the new method: reduce the number of states in the target FA and encodes path information by regular expressions on the edges. until there is one or two states : one is the start state and one is the final state.

Patterns, regular expression & FAs Transparency No Steps 0. Assume the machine M has only one start state and one final state. Both may probably be identical. 1.While the exists a third state p that is neither start nor final: 1.1 (Merge edges) For each pair of states (q,r) that has more than 1 edges with labels t 1,t 2,…t n, respectively, than merge these edges by a new one with regular expression t = t 1 + t 2 … + t n. 1.2 (Replace state p by edges; remove state) Let (p 1,  1, p),… (p n,  n, p) where p j != p be the collection of all edges in M with p as the destination state, and (p  , q 1 ),…,(p,  m, q m ) where qj != p be the collection of all edges with p as the start state. Now the sate p together with all its connecting edges can be removed and replaced by a set of m x n new edges : { (p i,  i t*  j, q j ) | i in [1,n] and j in [1,m] }. The new machine is equivalent to the old one.

Patterns, regular expression & FAs Transparency No Merge Edges :     q1 q2 p1 p2 p3 p 22     q1 q2 p1 p2 p3                                Replace state by Edges Note: {p1,p2,p3} may intersect with {q1,q2}.

Patterns, regular expression & FAs Transparency No perform 1.1 once again (merge edges) // There are one or two states now 3 Two cases to consider: 3.1 The final machine has only one state, that is both start and final. Then if there is an edge labeled t on the sate, then t* is the result, other the result is . 3.2 The machine has one start state s and one final state f. Let (s, s  s, s), (f, f  f, f), (s,s  f, f) and (f, f  f, f) be the collection of all edges in the machine, where (s  f) means the regular expression or label on the edge from s to f. The result then is [ (s  s) + (s  f ) (f  f)* (f  s) ] * (s  f) (f  f)*

Patterns, regular expression & FAs Transparency No Example 1. another representation pqr p 0 10,1 q11 r0 1

Patterns, regular expression & FAs Transparency No pqr p 0 10,1 q11 r0 1 pqr p q11 r0 1 Merge edges

Patterns, regular expression & FAs Transparency No pqr p q11 r0 1 remove q pqr p 0, 11*1 10+1, 11* (0+1) q 11,0+1 r 0, (0+1) 1*1 0+11, (0+1)1*(0+1) q p p r 1 r 

Patterns, regular expression & FAs Transparency No pr >p 0+11* * (0+1) rF 0+ (0+1) 1*11+ (0+1)1*(0+1) Final result : = [ p  p + (p  r) (r  r)* (r  p) ]* (p  r) (r  r) * [ (0+11*1) +(0+1+11*(0+1)) (1+(0+1)1*(0+1))* (0+(0+1)1*1) ]*       Form the final result