6.2 Closure Properties of CFL's

Slides:



Advertisements
Similar presentations
CS2303-THEORY OF COMPUTATION Closure Properties of Regular Languages
Advertisements

Lecture 11 Context-Free Grammar. Definition A context-free grammar (CFG) G is a quadruple (V, Σ, R, S) where V: a set of non-terminal symbols Σ: a set.
The Pumping Lemma for CFL’s
Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer.
Chapter 5 Pushdown Automata
Properties of Regular Languages
1 Lecture 32 Closure Properties for CFL’s –Kleene Closure construction examples proof of correctness –Others covered less thoroughly in lecture union,
Closure Properties of CFL's
1 Introduction to Computability Theory Lecture12: Decidable Languages Prof. Amos Israeli.
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
Prof. Busch - LSU1 Properties of Context-Free languages.
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.
1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
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 Languages and Finite Automata or how to talk to machines...
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.
Fall 2006Costas Busch - RPI1 Properties of Regular Languages.
Today Chapter 2: (Pushdown automata) Non-CF languages CFL pumping lemma Closure properties of CFL.
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 A Non Context-Free Language (We will prove it at the next class)
Properties of Context-Free Languages
Fall 2004COMP 3351 Regular Expressions. Fall 2004COMP 3352 Regular Expressions Regular expressions describe regular languages Example: describes the language.
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.
1 Module 31 Closure Properties for CFL’s –Kleene Closure –Union –Concatenation CFL’s versus regular languages –regular languages subset of CFL.
Lecture 10UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 10.
1 L= { w c w R : w  {a, b}* } is accepted by the PDA below. Use a construction like the one for intersection for regular languages to design a PDA that.
Context-Free and Noncontext-Free Languages Chapter 13 1.
Non-CF Languages The language L = { a n b n c n | n  0 } does not appear to be context-free. Informal: A PDA can compare #a’s with #b’s. But by the time.
Costas Busch - LSU1 Properties of Context-Free languages.
Pumping Lemma for CFLs. Theorem 7.17: Let G be a CFG in CNF and w a string in L(G). Suppose we have a parse tree for w. If the length of the longest path.
1 Closure Properties of Regular Languages Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University 2006.
Critique this PDA for L= { u u R v v R : u ∈ {0,1}* and v ∈ {0,1}+ } u0εu0 u1εu1 uεεvε v00vε v11vε vεεfε sεεtε t0εt0 t1εt1 t00tε t11tε tεεuε After you.
Chapter 8 Properties of Context-free Languages These class notes are based on material from our textbook, An Introduction to Formal Languages and Automata,
CFL Big Picture. Context Free Languages Conclusion We have studied the class of context free languages (CFL) We saw two different ways to express a CFL.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 2 Context-Free Languages Some slides are in courtesy.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
P Symbol Q E(Q) a b a b a b Convert to a DFA: Start state: Final States:
 2005 SDU Lecture11 Decidability.  2005 SDU 2 Topics Discuss the power of algorithms to solve problems. Demonstrate that some problems can be solved.
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.
Properties of Context-Free Languages
Closure Properties of Regular Languages
Properties of Regular Languages
Deterministic FA/ PDA Sequential Machine Theory Prof. K. J. Hintz
PDAs Accept Context-Free Languages
Closure Properties of Regular Languages
NPDAs Accept Context-Free Languages
Single Final State for NFA
Decision Properties of Regular Languages
CSE322 PROPERTIES OF REGULAR LANGUAGES
Properties of Regular Languages
COSC 3340: Introduction to Theory of Computation
4. Properties of Regular Languages
Definition: Let G = (V, T, P, S) be a CFL
Deterministic PDAs - DPDAs
Closure Properties of Context-Free languages
Properties of Context-Free Languages
Closure Properties of Regular Languages
The Pumping Lemma for CFL’s
Properties of Context-Free languages
Closure Properties of 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.
Chapter 1 Regular Language
Decidability continued….
CFL Big Picture.
Presentation transcript:

6.2 Closure Properties of CFL's Theorem 1 Context-free languages are closed under union, concatenation and Kleene closure. Proof Let L1= L(G1) and L2 = L(G2) be CFL’s, where G1 = (V1, T1, P1, S1) and G2 = (V2, T2, P2, S2) For union, L1L2, Construct G = (V, T, P, S), where P = P1P2 {SS1, SS2}, V = V1 V2 {S}

For concatenation, L1.L2, Construct G = (V, T, P, S), where P = P1P2 {SS1S2}, V = V1 V2 {S} For Kleene closure, L1*, Construct G = (V, T, P, S), where P = P1{SS1S, S}, V = V1 {S}

Theorem 2 Context-free languages are closed under substitution. Proof Let L be a CFL, L  *, and for each a in  let La be a CFL. Let L = L(G), G = (V, T, P, S), and for each a in  let La = L(Ga), where Ga=(Va, Ta, Pa, Sa). Assume that VVa = , for all a in . And Va Vb = , for all a≠ b in . Construct G’=(V’, T’, P’, S), where V’ = a in  Va  V, T’ = a in  Ta , P’ = a in  Pa {Af() | A  is in P, and f(a) = Sa for each a in }

Example 6 L = {0n1m | n ≠m } is a CFL. Let L = L(G), G = ({S, A, B}, {0, 1}, P, S), where P contains the following production rules: S  0S1 | 0A | 1B, A  0A | , B  1B | . Let L0 = L(G0), G = ({S0}, { (, ), [, ]}, P, S0), where P contains the following production rules: S0  S0S0 | [S0] | (S0) | [] | () L0 can be defined recursively as follows: () and [] are in L0. If R and S are in L0, then (R), [R], and RS are in L0. And L0 contains only the strings described in 1 and 2.

Let L1 = L(G1), G = ({S1, C, D}, {c, d}, P, S1), where P contains the following production rules: S1  dC | cD C  dCC | cS | c D  cDD | dS | d Let L1 consists of strings over {c, d} with the property that the number of c’s is equal to the number of d’s in the strings. If f is the substitution f(0) = L0 and f(1) = L1, then f(L) is generated by the grammar S  S0SS1 | S0A | S1B, A  S0A | , B  S1B | . S0  S0S0 | [S0] | (S0) | [] | () S1  dC | cD C  dCC | cS | c D  cDD | dS | d

Corollary Context-free languages are closed under homomorphism. Proof homomorphism is a special case of substitution.

Theorem 3 Context-free languages are closed under inverse homomorphism. Proof Let h : Δ* be a homomorphism and L be a CFL.. Let L = L(M), PDA M = (Q, Δ, Γ, , q0, Z0, F). An idea of constructing a PDA M’ to accept h-1(L) is as follows: What M’ does is the following: On reading an input symbol a, M’ generates the string h(a) and stores h(a) in a buffer, then simulates M on h(a). Only when the buffer is empty, M’ is allowed to read in next input. And the buffer holds only a suffix of h(a) for some input a at all time. M’ accepts an input w if the buffer is empty and M enters a final state.

Construct a PDA M’ = (Q’, , Γ, ’, [q0, ], Z0, F{}) to accept h-1(L) as follows: Q’ = { [q, x] | q Q and x is a suffix of some h(a) for a  .} ’ is defined as follows: ’ ([q, x], , Y) contains all ([p, x], γ) if (q, , Y) contains (p, γ). The move M’ simulates -move of M ignoring the buffer. ’ ([q, ax], , Y) contains all ([p, x], γ) if (q, a, Y) contains (p, γ). M’ simulates moves of M on reading a Δ, then removes a from the front of the buffer. ’ ([q, ], a, Y) contains all ([q, h(a)], γ) for all a   and Y  Γ. When the buffer is empty, M’ reads an input a and loads the buffer with h(a).

(q, h(a), ) (p, , )  ([q, ,], a, ) (q, h(a), ) ([p, ], , ). If M accepts h(w), i.e., (q0, h(w), Z0) (p, , ) for some p in F and  in Γ*, then ([q0,  ], w, Z0) ([p, ], , ). So M’ accepts w. We have that h-1(L(M))  L(M’)

If M’ accepts w = a1a2 … an. ([q0, ], a1a2 … an, Z0) ([p1, ], a2 … an, 1), ([p1, h(a1)], a2a3 … an, 1), ([p2, ], a2a3 … an, 2), ([p2, h(a2)], a3 … an, 2), ([pn, ], , n+1), . where pn is a final state.

For all i, we have (pi, h(ai), i) (pi+1, , i+1). So, for these moves altogether we have (q0, h(a1a2 …an), Z0) (pn, , n+1). Hence, h(a1a2…an) is in L(M). And L(M’)  h-1(L(M)}. End of Theorem 3.

Theorem 4 Context-free languages are not closed under intersection. Proof L1 = {0n1n0m | n, m = 0, 1, 2, …} and L2 = {0n1m0m | n, m = 0, 1, 2, …} are CFL’s. L1L2 = {0n1n0n | n = 0, 1, 2, …} is not CFL.

Corollary Context-free languages are not closed under complementation. L1  L2 = (L1cL2c)c , where c stands for complement. If CFL’s are closed under complement, then CFL’s are closed under intersection.

Theorem 5 The intersection of a context-free language and a regular language is context-free. Proof Let L be a CFL, and let R be a regular language. L = L(ML) for PDA ML = (QL, , Γ, L, q0, Z0, FL), and R = L(MR) for DFA MR = (QR, , R, p0, FR). Construct a PDA M’ for L  R by simulating ML and MR in parallel. M = (QLQR, , Γ, , [p0, q0], Z0, FLFR), where  ([p, q], a, X) contains ([p’, q’], ) if and only if R(p, a) = p’, L(q, a, X) contains (q’, ).