Languages Tha re and re No Conex-Free Read K & S 3.5, 3.6, 3.7. Read Supplemenary Maerials: Conex-Free Languages and Pushdown uomaa: Closure Properies of Conex-Free Languages Read Supplemenary Maerials: Conex-Free Languages and Pushdown uomaa: The Conex-Free Pumping Lemma. Do Homework 16. Deciding Wheher a Language is Conex-Free Theorem: There exis languages ha are no conex-free. Proof: (1) There are a counably infinie number of conex-free languages. This rue because every descripion of a conex-free language is of finie lengh, so here are a counably infinie number of such descripions. (2) There are an uncounable number of languages. Thus here are more languages han here are conex-free languages. So here mus exis some languages ha are no conex-free. Example: {a n b n c n } Showing ha a Language is Conex-Free Techniques for showing ha a language L is conex-free: 1. Exhibi a conex-free grammar for L. 2. Exhibi a PD for L. 3. Use he closure properies of conex-free languages. Unforunaely, hese are weaker han hey are for regular languages. Le G 1 = (V 1, Σ 1, R 1, S 1 ) and G 2 = (V 2, Σ 2, R 2, S 2 ) The Conex-Free Languages are Closed Under Union ssume ha G 1 and G 2 have disjoin ses of nonerminals, no including S. Le L = L(G 1 ) L(G 2 ) We can show ha L is conex-free by exhibiing a CFG for i: Le G 1 = (V 1, Σ 1, R 1, S 1 ) and G 2 = (V 2, Σ 2, R 2, S 2 ) The Conex-Free Languages are Closed Under Concaenaion ssume ha G 1 and G 2 have disjoin ses of nonerminals, no including S. Le L = L(G 1 ) L(G 2 ) We can show ha L is conex-free by exhibiing a CFG for i: Lecure Noes 19 Languages Tha re and re No Conex Free 1
The Conex-Free Languages are Closed Under Kleene Sar Le G 1 = (V 1, Σ 1, R 1, S 1 ) ssume ha G 1 does no have he nonerminal S. Le L = L(G 1 )* We can show ha L is conex-free by exhibiing a CFG for i: We know ha hey share a fae, since Wha bou Inersecion and Complemen? Bu wha fae? L 1 L 2 = L 1 L 2 We proved closure for regular languages wo differen ways. Can we use eiher of hem here: 1. Given a deerminisic auomaon for L, consruc an auomaon for is complemen. rgue ha, if closed under complemen and union, mus be closed under inersecion. 2. Given auomaa for L 1 and L 2, consruc a new auomaon for L 1 L 2 by simulaing he parallel operaion of he wo original machines, using saes ha are he Caresian produc of he ses of saes of he wo original machines. More on his laer. The Inersecion of a Conex-Free Language and a Regular Language is Conex-Free L = L(M 1 ), a PD = (K 1, Σ, Γ 1, 1, s 1, F 1 ) R = L(M 2 ), a deerminisic FS = (K 2, Σ, δ, s 2, F 2 ) We consruc a new PD, M 3, ha acceps L R by simulaing he parallel execuion of M 1 and M 2. M = (K 1 K 2, Σ, Γ 1,, (s 1, s 2 ), F 1 F 2 ) Inser ino : For each rule ((q 1, a, β), (p 1, γ)) in 1, and each rule (q 2, a, p 2 ) in δ, (((q 1, q 2 ), a, β), ((p 1, p 2 ), γ)) For each rule ((q 1, ε, β), (p 1, γ) in 1, and each sae q 2 in K 2, (((q 1, q 2 ), ε, β), ((p 1, q 2 ), γ)) This works because: we can ge away wih only one sack. Lecure Noes 19 Languages Tha re and re No Conex Free 2
Example L = a n b n (aa)*(bb)* b/a/ a B 1 2 a//a b/a/ a b b 3 4 b ((, a, ε), (, a)) (1, a, 2) ((, b, a), (B, ε)) (1, b, 3) ((B, b, a), (B, ε)) (2, a, 1) (3, b, 4) (4, b, 3) PD for L: Don Try o Use Closure Backwards One Closure Theorem: If L 1 and L 2 are conex free, hen so is L 3 = L 1 L 2. Bu wha if L 3 and L 1 are conex free? Wha can we say abou L 2? L 3 = L 1 L 2. Example: a n b n c* = a n b n c* a n b n c n The Conex-Free Pumping Lemma This ime we use parse rees, no auomaa as he basis for our argumen. S If L is a conex-free language, and if w is a sring in L where w > K, for some value of K, hen w can be rewrien as uvxyz, where vy > 0 and vxy M, for some value of M. uxz, uvxyz, uvvxyyz, uvvvxyyyz, ec. (i.e., uv n xy n z, for n 0) are all in L. Lecure Noes 19 Languages Tha re and re No Conex Free 3
Some Tree Basics roo nodes heigh leaves yield Theorem: The lengh of he yield of any ree T wih heigh H and branching facor (fanou) B is B H. Proof: By inducion on H. If H is 1, hen jus a single rule applies. By definiion of fanou, he longes yield is B. ssume rue for H = n. Consider a ree wih H = n + 1. I consiss of a roo, and some number of subrees, each of which is of heigh n (so inducion hypohesis holds) and yield B n. The number of subrees B. So he yield mus be B(B n ) or B n+1. S Wha Is K? Le T be he number of nonerminals in G. If here is a ree of heigh > T, hen some nonerminal occurs more han once on some pah. If i does, we can pump is yield. Since a ree of heigh = T can produce only srings of lengh B T, any sring of lengh > B T mus have a repeaed nonerminal and hus be pumpable. So K = B T, where T is he number of nonerminals in G and B is he branching facor (fanou). S Wha is M? ssume ha we are considering he boom mos wo occurrences of some nonerminal. Then he yield of he upper one is a mos B T+1 (since only one nonerminal repeas). So M = B T+1. Lecure Noes 19 Languages Tha re and re No Conex Free 4
The Conex-Free Pumping Lemma Theorem: Le G = (V, Σ, R, S) be a conex-free grammar wih T nonerminal symbols and fanou B. Then any sring w L(G) where w > K (B T ) can be rewrien as w = uvxyz in such a way ha: vy > 0, vxy M (B T+1 ), (making his he "srong" form), for every n 0, uv n xy n z is in L(G). Proof: Le w be such a sring and le T be he parse ree wih roo labeled S and wih yield w ha has he smalles number of leaves among all parse rees wih he same roo and yield. T has a pah of lengh a leas T+1, wih a boommos repeaed nonerminal, which we'll call. Clearly v and y can be repeaed any number of imes (including 0). If vy = 0, hen here would be a ree wih roo S and yield w wih fewer leaves han T. Finally, vxy B T+1. L = {a n b n c n : n 0} Choose w = a i b i c i where i > K/3 (making w > K) S n Example of Pumping Unforunaely, we don' know where v and y fall. Bu here are wo possibiliies: 1. If vy conains all hree symbols, hen a leas one of v or y mus conain wo of hem. Bu hen uvvxyyz conains a leas one ou of order symbol. 2. If vy conains only one or wo of he symbols, hen uvvxyyz mus conain unequal numbers of he symbols. Using he Srong Pumping Lemma for Conex Free Languages If L is conex free, hen There exis K and M (wih M K) such ha For all srings w, where w > K, (Since rue for all such w, i mus be rue for any paricular one, so you pick w) (Hin: describe w in erms of K or M) here exis u, v, x, y, z such ha w = uvxyz and vy > 0, and vxy M, and for all n 0, uv n xy n z is in L. We need o pick w, hen show ha here are no values for uvxyz ha saisfy all he above crieria. To do ha, we jus need o focus on possible values for v and y, he pumpable pars. So we show ha all possible picks for v and y violae a leas one of he crieria. Wrie ou a single sring, w (in erms of K or M) Divide w ino regions. For each possibiliy for v and y (described in erms of he regions defined above), find some value n such ha uv n xy n z is no in L. lmos always, he easies values are 0 (pumping ou) or 2 (pumping in). Your value for n may differ for differen cases. Lecure Noes 19 Languages Tha re and re No Conex Free 5
v y n why he resuling sring is no in L [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] Convince he reader ha here are no oher cases. Q. E. D. Proof ha L = {a n b n c n : n 0} is no conex free. Pumping Lemma Proof in Full Deail Suppose L is conex free. The conex free pumping lemma applies o L. Le M be he number from he pumping lemma. Choose w = a M b M c M. Now w L and w > M K. From he pumping lemma, for all srings w, where w > K, here exis u, v, x, y, z such ha w = uvxyz and vy > 0, and vxy M, and for all n 0, uv n xy n z is in L. There are wo main cases: 1. Eiher v or y conains wo or more differen ypes of symbols ( a, b or c ). In his case, uv 2 xy 2 z is no of he form a*b*c* and hence uv 2 xy 2 z L. 2. Neiher v nor y conains wo or more differen ypes of symbols. In his case, vy may conain a mos wo ypes of symbols. The sring uv 0 xy 0 z will decrease he coun of one or wo ypes of symbols, bu no he hird, so uv 0 xy 0 z L Cases 1 and 2 cover all he possibiliies. Therefore, regardless of how w is pariioned, here is some uv n xy n z ha is no in L. Conradicion. Therefore L is no conex free. Noe: he underlined pars of he above proof is boilerplae ha can be reused. complee proof should have his ex or somehing equivalen. Conex-Free Languages Over a Single-Leer lphabe Theorem: ny conex-free language over a single-leer alphabe is regular. Examples: L = {a n b n } L = {a n a n } = {a 2n } = {w {a}* : w is even} L = {ww R : w {a, b}*} L = {ww R : w {a}*} = {ww: w {a}*} = {w {a}* : w is even} L = {a n b m : n, m 0 and n m} L = {a n a m : n, m 0 and n m} = Proof: See Parikh's Theorem Lecure Noes 19 Languages Tha re and re No Conex Free 6
L = {a n : n 1 is prime} noher Language Tha Is No Conex Free Two ways o prove ha L is no conex free: 1. Use he pumping lemma: Choose a sring w = a n such ha n is prime and n > K. w = aaaaaaaaaaaaaaaaaaaaaaa Le vy = a p and uxz = a r. Then r + kp mus be prime for all values of k. This can' be rue, as we argued o show ha L was no regular. 2. Σ L = 1. So if L were conex free, i would also be regular. Bu we know ha i is no. So i is no conex free eiher. L = {w {a, b, c}* : w has an equal number of a's, b's, and c's} L is no conex free. Try pumping: Le w = a K b K c K Using Pumping and Closure Now wha? L = { : {a, b}* } Using Inersecion wih a Regular Language o Make Pumping Tracable Le's ry pumping: w > K Wha if u is ε, v is w, x is ε, y is w, and z is ε Then all pumping ells us is ha n n is in L. Lecure Noes 19 Languages Tha re and re No Conex Free 7
L = { : {a, b}* } Wha if we le w > M, i.e. choose o pump he sring a M ba M b: Now v and y can' be, since vxy M: Suppose v = y. Now we have o show ha repeaing hem makes he wo copies of differen. Bu we can. L = { : {a, b}* } Bu le's consider L' = L a*b*a*b* This ime, we le w > 2M, and he number of boh a's and b's in w >M: 1 2 3 4 aaaaaaaaaabbbbbbbbbbaaaaaaaaaabbbbbbbbbb Now we use pumping o show ha L' is no conex free. Firs, noice ha if eiher v or y conains boh a's and b's, hen we immediaely violae he rules for L' when we pump. So now we know ha v and y mus each fall compleely in one of he four marked regions. L' = { : {a, b}* } a*b*a*b* w > 2M, and he number of boh a's and b's in w >M: 1 2 3 4 aaaaaaaaaabbbbbbbbbbaaaaaaaaaabbbbbbbbbb Consider he combinaions of (v, y): (1,1) (2,2) (3,3) (4,4) (1,2) (2,3) (3,4) (1,3) (2,4) (1,4) Lecure Noes 19 Languages Tha re and re No Conex Free 8
The Conex-Free Languages re No Closed Under Inersecion Proof: (by counerexample) Consider L = {a n b n c n : n 0} L is no conex-free. Le L 1 = {a n b n c m : n, m 0} /* equal a's and b's L 2 = {a m b n c n : n, m 0} /* equal b's and c's Boh L 1 and L 2 are conex-free. Bu L = L 1 L 2. So, if he conex-free languages were closed under inersecion, L would have o be conex-free. Bu i isn'. The Conex-Free Languages re No Closed Under Complemenaion Proof: (by conradicion) By definiion: L 1 L 2 = L 1 L 2 Since he conex-free languages are closed under union, if hey were also closed under complemenaion, hey would necessarily be closed under inersecion. Bu we jus showed ha hey are no. Thus hey are no closed under complemenaion. Proof: The Deerminisic Conex-Free Languages re Closed Under Complemen Le L be a language such ha L$ is acceped by he deerminisic PD M. We consruc a deerminisic PD M' o accep (he complemen of L)$, jus as we did for FSMs: 1. Iniially, le M' = M. 2. M' is already deerminisic. 3. Make M' simple. Why? 4. Complee M' by adding a dead sae, if necessary, and adding all required ransiions ino i, including: Transiions ha are required o assure ha for all inpu, sack combinaions some ransiion can be followed. If some sae q has a ransiion on (ε, ε) and if i does no laer lead o a sae ha does consume somehing hen make a ransion on (ε, ε) o he dead sae. 5. Swap final and nonfinal saes. 6. Noice ha M is sill deerminisic. Lecure Noes 19 Languages Tha re and re No Conex Free 9
n Example of he Consrucion L = a n b n M acceps L$ (and is deerminisic): a//a b/a/ b/a/ $/ε/ 1 2 3 $/ε/ Se M = M'. Make M simple. a/a/aa a/z/az b/a/ ε/ε/z b/a/ $/Z/ 0 1 2 3 $/Z/ dd dead sae(s) and swap final and nonfinal saes: a/a/aa a/z/az b/a/ ε/ε/z b/a/ $/Z/ 0 1 2 3 The Consrucion, Coninued $/Z/ b/z/, $/a/ 4 a//, $/a/, b/z/ a//, b//, $//, ε/a/, ε/z/ Issues: 1) Never having he machine die 2) (L$) ( L)$ 3) Keeping he machine deerminisic Deerminisic vs. Nondeerminisic Conex-Free Languages Theorem: The class of deerminisic conex-free languages is a proper subse of he class of conex-free languages. Proof: Consider L = {a n b m c p : m n or m p} L is conex free (we have shown a grammar for i). Bu L is no deerminisic. If i were, hen is complemen L 1 would be deerminisic conex free, and hus cerainly conex free. Bu hen L 2 = L 1 a*b*c* (a regular language) would be conex free. Bu L 2 = {a n b n c n : n 0}, which we know is no conex free. Thus here exiss a leas one conex-free language ha is no deerminisic conex free. Noe ha deerminisic conex-free languages are no closed under union, inersecion, or difference. Lecure Noes 19 Languages Tha re and re No Conex Free 10
There are decision procedures for he following (G is a CFG): Deciding wheher w L(G). Deciding wheher L(G) =. Deciding wheher L(G) is finie/infinie. Decision Procedures for CFLs & PDs Decision Procedures for CFLs Such decision procedures usually involve conversions o Chomsky Normal Form or Greibach Normal Form. Why? Theorem: For any conex free grammar G, here exiss a number n such ha: 1. If L(G), hen here exiss a w L(G) such ha w < n. 2. If L(G) is infinie, hen here exiss w L(G) such ha n w < 2n. There are no decision procedures for he following: Deciding wheher L(G) = Σ*. Deciding wheher L(G 1 ) = L(G 2 ). If we could decide hese problems, we could decide he haling problem. (More laer.) There are decision procedures for he following (M is a PD): Deciding wheher w L(M). Deciding wheher L(M) =. Deciding wheher L(M) is finie/infinie. Decision Procedures for PD s Conver M o is equivalen PD and use he corresponding CFG decision procedure. Why avoid using PD s direcly? There are no decision procedures for he following: Deciding wheher L(M) = Σ*. Deciding wheher L(M 1 ) = L(M 2 ). If we could decide hese problems, we could decide he haling problem. (More laer.) Lecure Noes 19 Languages Tha re and re No Conex Free 11
Comparing Regular and Conex-Free Languages Regular Languages regular exprs. or regular grammars recognize = DFSs recognize minimize FSs closed under: concaenaion union Kleene sar complemen inersecion pumping lemma deerminisic = nondeerminisic Conex-Free Languages conex-free grammars parse = NDPDs parse find deerminisic grammars find efficien parsers closed under: concaenaion union Kleene sar inersecion w/ reg. langs pumping lemma deerminisic nondeerminisic Languages and Machines Recursively Enumerable Languages Recursive Languages Conex-Free Languages Regular Languages FSMs PDs D ND Lecure Noes 19 Languages Tha re and re No Conex Free 12