上下文无关语言的闭包性质以及与常规语言的交集

发布于 2024-11-29 11:37:25 字数 97 浏览 1 评论 0原文

上下文无关语言和常规语言的交集始终是上下文无关的,但上下文无关语言在集合交集下不会闭合。如果所有正则语言都是上下文无关的(相反并不总是正确的),谁能解释为什么这两个定理都是正确的?

The intersection of a context-free language and a regular language is always context-free but context-free languages are not closed under set intersection. Could anyone explain why both theorems are true if all regular languages are context-free (the opposite is not always true)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

国产ˉ祖宗 2024-12-06 11:37:25

为了证明上下文无关语言在交集下不是封闭的,我们提供了一个反例。

考虑 L = {a^ib^jc^k | i = j} 且 R = {a^ib^jc^k |我= k}。这两个集合的交集是 S = {a^ib^jc^k | i = j = k},即 a^nb^nc^n 形式的字符串。可以使用上下文无关语言的泵引理来证明该语言不是上下文无关的。其他两个定理的上下文无关语法很简单:

  L is given by
  S := AC
  A := aAb | lambda
  C := cC | lambda

  R is given by
  S := aSc | B | lambda
  B := bB | lambda

为了更具体地解决您的问题,这两个定理都成立的原因是常规语言是上下文无关语言的真子集;对于要在集合交集下封闭的上下文无关语言,任何任意上下文无关语言的交集也必须是上下文无关的(它不是;见上文)。然而,同时,任何常规语言和任何上下文无关语言的交集也是上下文无关的(没有理由不能使用 FA 和 FA 来制作笛卡尔积机) PDA;毕竟只有一台机器需要堆栈 - 尝试使用两个 PDA 的笛卡尔积机器时情况并非如此,因为在某些情况下需要两个堆栈,而两个堆栈 PDA 相当于图灵机)。

To prove that context-free languages are not closed under intersection, we provide a counterexample.

Consider L = {a^i b^j c^k | i = j} and R = {a^i b^j c^k | i = k}. The intersection of these two sets is S = {a^i b^j c^k | i = j = k}, i.e., strings of the form a^n b^n c^n. It can be shown using the pumping lemma for context free languages that this language is not context free. Context free grammars for the other two are easy:

  L is given by
  S := AC
  A := aAb | lambda
  C := cC | lambda

  R is given by
  S := aSc | B | lambda
  B := bB | lambda

To address your question more specifically, the reason both theorems can be true is that the regular languages are a proper subset of the context free languages; for the context free languages to be closed under set intersection, the intersection of any arbitrary context free languages must also be context free (it's not; see above). However, it is at the same time true that it happens to be the case that the intersection of any regular language and any context free language is also context free (there's no reason the Cartesian product machine can't be made using a FA and a PDA; only one machine needs a stack, after all - not the case when trying the Cartesian product machine with two PDAs, since two stacks are needed in some cases, and two stack PDAs are equivalent to Turing machines).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文