Chapter 8 Properties of CFLs Theorem 8.1: Let L be an infinite context-free language. Then a positive integer m such that any w L with |w| m can be decomposed as w = uvxyz with |vxy| m and |vy| 1 such that uvixyiz L for all i = 0, 1, 2, … Proof sketch: Finishing the Pumping Lemma Proof Using the pumping lemma Example 1 is in the online notes Example 1: Proof that L = {0i1i2i | i 0} is not a CFL Case 1: v and/or y contains two different symbols. Case 1a: Case 1b: Case 2: v 0*, y 0+ if i = 0, uxz = 0k1m2m, is not in L since k < m v 0*, y 1+ v 1*, y 1+ v 1*, y 2+ v 2*, y 2+ Example 2: L = {0i | i is prime} is not a CFL. (# 2 p. 212) Example 3: Prove that L = {anbnci | i n} is not context-free. Case 1: vy contains both a's and b's. Case 2: vy contains both b's and c's. Case 3: vy contains only a's. Case 4: vy contains only b's. Case 5: vy contains only c's. Example 4: L = {anbjck | k > n, k > j } See proof in the online notes Example 5: L = {aibjck | j = max{i, k} and i k } Read Example 8.2—L = {ww | w {a, b}*} is not context-free Section 8.2 Closure Properties and decision algorithms for CFL’s Theorem 8.3 The family of context-free languages is closed under union, concatenation and star-closure. Proof Let L1 and L2 be context-free languages generated by grammars, G1 = (V1, T1, S1, P1) and G2 = (V2, T2, S2, P2). Without loss of generality, assume V1 V2 = . Closure under concatenation: Star closure: Theorem: If L is a CFL, then so is LR. Theorem 8.4 The family of context-free languages is not closed under intersection and complementation. Nonclosure under complementation Assume that the CFLs are closed under complementation Other operations under which the context-free languages are closed: Theorem 8.5 Let L1 be a context-free language and L2 be a regular language. Then L1 L2 is context-free. Let M1 = (Q, , , 1, q0, z, F1) be an NPDA that accepts CFL L1 and let M2 = (P, , ,2, p0, F2) be a DFA that accepts L2. A natural question now arises, why won’t this work for two CFL’s? Examples of using closure properties Example 1: Prove or disprove L = {x {a, b, c}* | na(x) = nb(x) = nc(x)} is a CFL. Example 2: Show that L = {ww | w {a, b}+} is not a CFL. Example 3: Prove that if L1 and L2 are CFLs then L1 – L2 is not necessarily a CFL. Some Decidable Properties of Context-Free Languages Theorem 8.6 Given a context-free grammar G = (V, T, S, P) there exists an algorithm for deciding whether or not L(G) is empty. Theorem 8.7 Given a context-free grammar G = (V, T, S, P) there exists an algorithm for determining whether or not L(G) is infinite. Example: A BC, B DC, C DA. The CYK algorithm wij denotes Vij denotes How the algorithm works for i 1 to n Vii {A | A a is in P and the ith symbol of w is a} for j 2 to n for i 1 to n-j+1 Vij Ø for k i to i+j-1 Vij Vij {A | A BC is in P and B Vik and C Vk+1,j} CYK Algorithm Example S CB | FA | FB B FS | CE | b D AA Fb A CS | FD | a Ca E BB Some Undecidable CFL Questions Let G1 and G2 denote arbitrary CFG’s and let R be a regular language. 1. 2. 3. 4.