2

I'm a TA, and was asked the following by a student. Embarrassingly, I couldn't come up with an answer, so I turn to you guys.

We know that L_1 = {a^n b^n c^n} is non-CFL. We also know that L_2 = {a^i b^k c^j : i != k } is context free.

What about the union of those? (it is obviously non-regular) Is it context free?

Shir
  • 267
  • 1
  • 3
  • 10
  • Better asked on http://cstheory.stackexchange.com – Fred Foo Feb 22 '12 at 13:46
  • That one is a research level forum. This is not a research level question. – Shir Feb 22 '12 at 13:55
  • @larsmans This question would be closed on cstheory because it is not a research-level question. Many questions like this are transferred there, where they are eventually closed and deleted. What we need is to get the last little bit of support for the general CS stackexchange beta site. This question would be perfect for there. – Patrick87 Feb 22 '12 at 17:47
  • @Shir When you get a chance, check out my answer. I think it pretty much lays this one to rest. That being said, this question would have been perfect for the upcoming general CS stackexchange site. Check it out: http://area51.stackexchange.com/proposals/35636/computer-science . Show your support by committing, and tell your friends, family, and students to commit, too. I'm getting pretty stoked about that site. – Patrick87 Feb 22 '12 at 17:49

1 Answers1

3

We select as our universe the language U = {a^i b^j c^k | i, j, k in N}.

Then L_1^C = {a^i b^j c^k | i!=j or j != k} = {a^i b^j c^k | i!=j} union {a^i b^j c^k | j != k} = L_A union L_B. Notice that L_A = L_2.

By DeMorgan, L_1 union L_2 = (L_1^C intersect L_2^C)^C = ((L_A union L_B) intersect L_2^C)^C, which by the distributive law is ((L_A intersect L_2^C) union (L_B intersect L_2^C))^C.

Recall that since L_A = L_2, we get (L_B intersect L_2^C)^C. By DeMorgan, we can render this as L_B^C union L_2. We have already admitted that L_2 is context-free. The complement of L_B in our universe is {a^i b^j c^k | j=k}, which is also context free. The union of two context free languages is also context free, so yes, L_1 union L_2 is context free.

Having gone through the formalities, the intuition is obvious: L_1 union L_2 is equivalent to saying that either i != j (the number of a's and b's is different) OR the number of b's and c's is the same. If you think about it, this perfectly captures the requirements of the languages: if i != j, we're OK by the second part; the only way we can fail to be in L_2 is if we already know for a fact that i = j, and we only have to worry about guaranteeing j = k.

In boolean logic: (a and b) or (not a) is equivalent to (b or (not a)).

A CFG for the language is the following:

S := A | C
A := aA | B
B := lambda | bBc
C := Cc | D | E
D := a | aD | aDb
E := b | Eb | aEb

You can get a PDA via top-down or bottom-up parser constructions.

sdcvvc
  • 25,343
  • 4
  • 66
  • 102
Patrick87
  • 27,682
  • 3
  • 38
  • 73