Regular Languages ภาษาปกติ. Jaruloj Chongstitvatana 2301379 2 Outline Regular expressions Regular languages Equivalence between languages accepted by.

Slides:



Advertisements
Similar presentations
3.2 Pumping Lemma for Regular Languages Given a language L, how do we know whether it is regular or not? If we can construct an FA to accept the language.
Advertisements

FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
1 Regular Expressions Highlights: –A regular expression is used to specify a language, and it does so precisely. –Regular expressions are very intuitive.
1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY (For next time: Read Chapter 1.3 of the book)
Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state.
Fall 2006Costas Busch - RPI1 Regular Expressions.
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.
Lecture 7 Sept 22, 2011 Goals: closure properties regular expressions.
1 NFAs accept the Regular Languages. 2 Equivalence of Machines Definition: Machine is equivalent to machine if.
Courtesy Costas Busch - RPI1 Non-regular languages.
Homework 4 Solutions.
1 Regular Languages Finite Automata eg. Supermarket automatic door: exit or entrance.
Today Chapter 1: RE = Regular Languages, nonregular languages RL pumping lemma Chapter 2: Context-Free Languages (CFLs)
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.
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
1 Let L= { w= u v : u  {a, b}*, v  {c, d}* and |u|= |v|} 1.Design a context-free grammar that generates L. 2.Use your grammar and the construction from.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Closure.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to DFA.
1 State SymbolRead- Q E(Q) a b a b a b Convert to a DFA: Start state: Final States:
Prof. Busch - LSU1 NFAs accept the Regular Languages.
CSCI 2670 Introduction to Theory of Computing September 1, 2005.
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.
CHAPTER 1 Regular Languages
Chapter 4 Pumping Lemma Properties of Regular Languages Decidable questions on Regular Languages.
Class Discussion Can you draw a DFA that accepts the language {a k b k | k = 0,1,2,…} over the alphabet  ={a,b}?
Regular Expressions Costas Busch - LSU.
Chapter 3 Regular Expressions, Nondeterminism, and Kleene’s Theorem Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction.
Lecture 5: Finite Automata 虞台文 大同大學資工所 智慧型多媒體研究室.
1 Language Recognition (11.4) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch
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.
CSCI 2670 Introduction to Theory of Computing September 11, 2007.
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.
P Symbol Q E(Q) a b a b a b Convert to a DFA: Start state: Final States:
1 Closure E.g., we understand number systems partly by understanding closure properties: Naturals are closed under +, , but not -, . Integers are closed.
1 Use the pumping theorem for context-free languages to prove that L= { a n b a n b a p : n, p ≥ 0, p ≥ n } is not context-free. Hint: For the pumping.
Foundations of Computing Science
Closure Properties of Regular Languages
PROPERTIES OF REGULAR LANGUAGES
Regular Expressions.
FORMAL LANGUAGES AND AUTOMATA THEORY
CSE 105 theory of computation
Single Final State for NFA
CS 154, Lecture 3: DFANFA, Regular Expressions.
CSE 2001: Introduction to Theory of Computation Fall 2009
Closure Properties of Regular Languages
Chapter 4 Properties of Regular Languages
Closure Properties of Regular Languages
Regular Languages ภาษาปกติ.
Convert to a DFA: Start state: Final States: State Symbol Read- Q E(Q)
Convert to a DFA: Start state: Final States: P Symbol Q E(Q) a b.
CSE 105 theory of computation
CSCI 2670 Introduction to Theory of Computing
NFAs accept the Regular Languages
CSE 105 theory of computation
Presentation transcript:

Regular Languages ภาษาปกติ

Jaruloj Chongstitvatana Outline Regular expressions Regular languages Equivalence between languages accepted by FA and regular languages Closure Properties

Jaruloj Chongstitvatana Regular Expressions Regular expression over alphabet   is a regular expression.  is a regular expression. For any a , a is a regular expression. If r 1 and r 2 are regular expressions, then –(r 1 + r 2 ) is a regular expression. –(r 1  r 2 ) is a regular expression. –(r 1 * ) is a regular expression. Nothing else is a regular expression.

Jaruloj Chongstitvatana RegularLanguages  is a regular language corresponding to the regular expression . {  } is a regular language corresponding to the regular expression . For any symbol a , { a } is a regular language corresponding to the regular expression a. If L 1 and L 2 are regular languages corresponding to the regular expression r 1 and r 2, then –L 1  L 2, L 1  L 2, and L 1 * are regular languages corresponding to (r 1 + r 2 ), (r 1  r 2 ), and (r 1 * ).

Jaruloj Chongstitvatana Simple examples Let  = {0,1}. {  * |  does not contain 1’s} –(0 * ) {  * |  contains 1’s only} –(1  (1 * )) (which can can be denoted by (1 + ))  * –((0+1) * ) {  * |  contains only 0’s or only 1’s} –((00 * )+(11 * )) 0* + 1*  (0+1)*

Jaruloj Chongstitvatana Some more notations Let  = {0,1}. Parentheses in regular expressions can be omitted when the order of evaluation is clear. –((0+1) * )  0+1 * –((0 * )+(1 * )) = 0 * + 1 * For concatenation,  can be omitted. r  r  r… r is denoted by r n. n times

Jaruloj Chongstitvatana More complex examples Let  = {0,1}. {  *|  contains odd number of 1 ’ s} –0*(10*10*)*10* {  *| any two 0 ’ s in  are separated by three 1 ’ s} –1*(0111)*01* + 1* {  * |  is a binary number divisible by 4 } –(0+1)*00 {  *|  does not contain 11 } –0*(10 + )* (1+  ) or (0+10)* (1+  )

Jaruloj Chongstitvatana Notation Let r be a regular expression. The regular language corresponding to the regular expression r is denoted by L( r ).

Jaruloj Chongstitvatana Some rules for language operations Let r, s and t be languages over {0,1} r +  =  + r = r r + s = s + r r  =  r = r r  =  r =  r  (s + t) = r  s + r  t r + = r r *

Jaruloj Chongstitvatana Rewrite rules for regular expressions Let r, s and t be regular expressions over {0,1}.  * =   * =  (r +  ) + = r* r* = r*(r +  ) = r* r* = (r*)* (r*s*)* = (r + s)*

Jaruloj Chongstitvatana Closure properties of the class of regular languages (Part 1) Theorem: The class of regular languages is closed under union, concatenation, and Kleene’s star. Proof: Let L 1 and L 2 be regular languages over . Then, there are regular expressions r 1 and r 2 corresponding to L 1 and L 2. By the definition of regular expression and regular languages, r 1 +r 2,r 1  r 2, and r 1 * are regular expressions corresponding to L 1  L 2, L 1  L 2, and L 1 *. Thus, the class of regular languages is closed under union, concatenation, and Kleene’s star.

Jaruloj Chongstitvatana Equivalence of language accepted by FA and regular languages To show that the languages accepted by FA and regular languages are equivalent, we need to prove: For any regular language L, there exists an FA M such that L = L( M ). For any FA M, L( M ) is a regular language.

Jaruloj Chongstitvatana For any regular language L, there exists an FA M such that L = L( M ) Proof: Let L be a regular language. Then,  a regular expression r corresponding to L. We construct an NFA M, from the regular expression r, such that L= L (M). Basis: If r = , M is If r = , M is If r = { a } for some a  , M is s f s a s f 

Jaruloj Chongstitvatana Proof (cont’d) Induction hypotheses: Let r 1 and r 2 be regular expressions with less than n operations. And, there are NFA’s M 1 and M 2 accepting regular languages corresponding to L( r 1 ) and L( r 2 ). Induction step: Let r be a regular expression with n operations. We construct an NFA accepting L( r ). r can be in the form of either r 1 +r 2, r 1  r 2, or r 1 *, for regular expressions r 1 and r 2 with less than n operations.

Jaruloj Chongstitvatana Proof (cont’d) If r = r 1 +r 2, then M is If r = r 1  r 2, then M is If r = r 1 *, then M is Therefore, there is an NFA accepting L( r ) for any regular expression r. f2f2 f1f1 s s1s1 s2s2   f2f2 s2s2 s1s1 f1f1    s1s1 f1f1 s f  

Jaruloj Chongstitvatana Constructing NFA for regular expressions 0 * (10 + ) * (1+  ) 10 0    0    1 0*0* 10 + (10 + ) * 1  1+  s     

Jaruloj Chongstitvatana Some Observations Can these two states be merged? NO Be careful when you decide to merge some states    0    1 s     

Jaruloj Chongstitvatana For any FA M, L( M ) is a regular language Proof: Let M = (Q, , , q 1, F) be an FA, where Q={q i | 1  i  n} for some positive integer n. Let R(i, j, k) be the set of all strings in that drive M from state q i to state q j while passing through any state q l, for l  k. ( i and j can be any states) qiqi qjqj qlql q l'

Jaruloj Chongstitvatana Proof (cont’d) R(i, j, 0) = + qj  (qi, a) a if i  j R(i, j, 0) = + qj  (qi, a) a +  if i= 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) qiqi qjqj a qiqi a qiqi qjqj qkqk q1q1 q2q2 q k-1 R(i, j, k-1) R(i, k, k-1) R(k, k, k-1)* R(k, j, k-1)

Jaruloj Chongstitvatana Proof (cont’d) Then, L(M) = + R(1, f, n) for all q f in F. R(i, j, 0) = + qj  (qi, a) a if i  j R(i, j, 1) = {a  | (q i, a) = q j } +  if i= 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)

Jaruloj Chongstitvatana Proof (cont’d) We prove that L(M) is a regular language by showing that there is a regular expression corresponding to L(M ), by induction. Basis: R(i, j, 0) corresponds to a regular expression a if i  j and a +  if i= j for some a . Induction hypotheses: Let R(i, j,k-1) correspond to a regular expression, for any i, j, k  n.

Jaruloj Chongstitvatana Proof (cont’d) Induction step: R(i, j, k) = R(i, j, k-1)  R(i, k, k-1) R(k, k, k-1) * R(k, j, k-1) also corresponds to a regular expression because R(i, j, k-1), R(i, k, k-1), R(k, k, k- 1) and R(k, j, k-1) correspond to some regular expressions and union, concatenation, and Kleene’s star are allowed in regular expressions. Therefore, L(M) is also a regular language because L(M) = + R(1, f, n) for all q f in F.

Jaruloj Chongstitvatana Find a regular expression for a DFA q4q4 q2q2 q1q1 q3q3 q5q5 b b b a aa   a*ba*b ba * b a * ba * b a * ba * ba * ba * ba * b a*ba* + a*ba*b (ba*ba*b+a)* ba*ba* a*ba* (  +b(ba*ba*b+a)* ba*ba*)

Jaruloj Chongstitvatana Pumping Lemma Let L be a regular language. Then, there exists an integer n  0 such that for every string x in L that |x|  n, there are strings u, v, and w such that –x = u v w, –v  , –|u v|  n, and –for all k  0, u v k w is also in L. Any language L is not a regular language if for any integer n  0, there is a string x in L such that |x|  n, for any strings u, v, and w, –x  u v w, or –v = , or –Not (|u v|  n), or –there is k  0, u v k w is not in L

Jaruloj Chongstitvatana Pumping Lemma Any language L is not a regular language if for any integer n  0, there is a string x in L such that |x|  n, for any strings u, v and w, such that x = u v w, v  , and |u v|  n, –there is k  0, u v k w is not in L

Jaruloj Chongstitvatana Using Pumping Lemma Given a language L. Let n be any integer  0. Choose a string x in L that |x|  n. Consider all possible ways to chop x into u, v and w such that v  , and |uv|  n. For all possible u, v, and w, show that there is k  0 such that u v k w is not in L. Then, we can conclude that L is not regular. If you pick a wrong x, your proof will fail ! It does not mean that L is regular !!!!!

Jaruloj Chongstitvatana Prove {0 i 1 i | i  0} is not regular Let L = {0 i 1 i | i  0}. Let n be any integer  0. Let x = 0 n 1 n. Make sure that x is in L and | x |  n. The only possible way to chop x into u, v, and w such that v , and | u v|  n is: u = 0 p, v = 0 q, w = 0 n-p-q 1 n, where 0  p < n and 0< q  n Show that there is k  0, u v k w is not in L. u v k w = 0 p 0 qk 0 n-p-q 1 n = 0 p+qk+(n-p-q) 1 n = 0 n+q(k-1 ) 1 n If k  1, then n+q(k -1)  n and u v k w is not in L. Then, L is not regular.

Jaruloj Chongstitvatana Prove {0 i 1 i | i  0} is not regular Let L = { 0 i 1 i | i  0}. Let n be any integer  0, and m =  n /2 . Let x = 0 m 1 m. Make sure that x is in L and |x|  n. Possible ways to chop x into u, v, and w such that v  , and |u v|  n are: –u = 0 p, v = 0 q, w = 0 m-p-q 1 m, where 0  p<m and 0<q  m –u = 0 p, v = 0 m-p 1 q, w = 1 m-q, where 0  p<m and 0<q  m –u = 0 m 1 p, v = 1 q, w = 1 m-p-q, where 0  p<m and 0<q  m

Jaruloj Chongstitvatana Prove {0 i 1 i | i  0} is not regular Show that there is k  0, u v k w is not in L. –u=0 p, v=0 q, w= 0 m-p-q 1 m, where where 0  p<m and 0<q  m u v k w = 0 p 0 qk 0 m-p-q 1 m = 0 m+q(k-1) 1 m is not in L if k  1. –u=0 p, v=0 m-p 1 q, w=1 m-q, where where 0  p<m and 0<q  m u v k w = 0 p (0 m-p 1 q ) k 1 m-q is not in L if k  1. –u=0 m 1 p, v=1 q, w=1 m-p-q, where where 0  p<m and 0<q  m u v k w = 0 m 1 p 1 qk 1 m-p-q = 0 m 1 m+q(k-1) is not in L if k  1. Then, L is not regular.

Jaruloj Chongstitvatana Prove {1 i | i is prime} is not regular Let L = { 1 i | i is prime}. Let n be any integer  0. Let p be a prime  n, and w = 1 p. Only one possible way to chop w into x, y, and z such that y  , and | x y |  n is: x = 1 q, y = 1 r, z = 1 p-q-r, where 0  q<n and 0< r<n Show that there is k  0, x y k z is not in L. x y k z = 1 q 1 rk 1 p-q-r = 1 q+rk+(p-q-r) = 1 p+r(k-1) If k=p+1, then p+r(k-1) = p(r+1), which is not a prime. Then, x y k z is not in L. Then, L is not regular.

Jaruloj Chongstitvatana Using closure property Let  be a binary operation on languages and the class of regular languages is closed under . (  can be , , or -) If L 1 and L 2 are regular, then L 1  L 2 is regular. If L 1  L 2 is not regular, then L 1 or L 2 are not regular. If L 1  L 2 is not regular but L 2 is regular, then L 1 is not regular.

Jaruloj Chongstitvatana Prove that {w  {0,1} * | the number of 0’s and 1’s in w are equal} is not regular Let L={w  {0,1} * | the number of 0’s and 1’s in w are equal}. Let R= {0 i 1 i | i  0}. R = 0 * 1 *  L We already prove that R is not regular. But 0*1* is regular. Then, L is not regular.

Jaruloj Chongstitvatana Using closure property Let  be a unary operation on a language and the class of regular languages is closed under . (  can be complement or * ) If L is regular, then  L is regular. If  L is not regular, then L is not regular.

Jaruloj Chongstitvatana Prove that {w  {0,1} * | the number of 0’s and 1’s in w are not equal} is not regular Let L = {w  {0,1} * | the number of 0’s and 1’s in w are not equal}. Let R =  L = {w  {0,1} * | the number of 0’s and 1’s in w are equal}. We already prove that R is not regular. Then, L is not regular.

Jaruloj Chongstitvatana Check list  Find the language described by a regular exp.  Construct regular exp. describing a given language  Convert a regular exp. into an FA  Convert an FA into a regular exp.  Prove a language is regular –By constructing a regular exp. –By constructing an FA –By using closure properties  Construct an FA or a regular exp. for the intersection, union, concatenation, complementation, and Kleene’s star of regular languages  Prove other closure properties of the class of regular languages  Surprise!