以下 CFL 和非 CFL 的并集是 CFL 本身吗?
我是一名助教,一位学生问我以下问题。尴尬的是,我无法想出答案,所以我向你们求助。
我们知道 L_1 = {a^nb^nc^n} 是非 CFL。 我们还知道 L_2 = {a^ib^kc^j : i != k } 上下文无关。
那些人的联合又如何呢? (这显然是不规则的) 它是上下文无关的吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们选择语言 U = {a^ib^jc^k | N 中的 i、j、k}。
那么 L_1^C = {a^ib^jc^k | i!=j 或 j!=k} = {a^ib^jc^k | i!=j} 并集 {a^ib^jc^k | j != k} = L_A 并集 L_B。请注意,L_A = L_2。
根据 DeMorgan,L_1 union L_2 = (L_1^C intersect L_2^C)^C = ((L_A union L_B) intersect L_2^C)^C,根据分配律是 ((L_A intersect L_2^C) union (L_B与 L_2^C))^C 相交。
回想一下,由于 L_A = L_2,我们得到 (L_B 与 L_2^C)^C 相交。根据 DeMorgan,我们可以将其呈现为 L_B^C 并集 L_2。我们已经承认 L_2 是上下文无关的。我们宇宙中 L_B 的补码是 {a^ib^jc^k | j=k},这也是上下文无关的。两种上下文无关语言的并集也是上下文无关的,所以是的,L_1 并集 L_2 是上下文无关的。
完成手续后,直觉就很明显了:L_1 union L_2 相当于说 i != j(a 和 b 的数量不同)或者 b 和 c 的数量相同。如果你仔细想想,这完美地捕捉了语言的要求:如果 i != j,我们就可以完成第二部分;我们无法进入 L_2 的唯一方法是,如果我们已经知道 i = j,并且我们只需担心保证 j = k。
在布尔逻辑中:(a and b) or (not a) 等价于(b or (not a))。
该语言的 CFG 如下:
您可以通过自上而下或自下而上的解析器构造获得 PDA。
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:
You can get a PDA via top-down or bottom-up parser constructions.