0,1 上的双字补码的上下文无关语法是什么?

发布于 2024-10-26 13:44:15 字数 1455 浏览 6 评论 0原文

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

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

发布评论

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

评论(2

蓝眸 2024-11-02 13:44:15

首先,请注意以下事实:任何奇怪的单词都是语言的一部分。让我们定义以下语言:

L1={w1w|w{0,1}*}, L0={w0w|w{0,1}*}

这些语言可以使用以下 CFG 来定义:

S0/1 -> |0S0|1S1|0S1|1S0

现在看看 L3:

L3=(L1)U(L2)U(L1L2)U(L2L1)

它是上下文无关的,从闭包到并集和串联。

让我们证明 L3 是我们正在寻找的语言。首先,正如我们所见,它处理所有可能的奇数长度单词。对于偶数长度的单词,如果在语言中,至少有一对终结符,并且单词的两侧不同。称这对为 a 和 b。每个偶数词都可以这样划分:

(x_1^m)(a)(x_2^m)(y_1^n)(b)(y_2^n)

这正是

(L1L2)U(L2L1)

这意味着 CFG 语言在补码下不是封闭的。

First of all observe the fact that any odd word is part of the language. Let's define the following languages:

L1={w1w|w{0,1}*}, L0={w0w|w{0,1}*}

These languages can be defined with the following CFG:

S0/1 -> |0S0|1S1|0S1|1S0

Now look at L3:

L3=(L1)U(L2)U(L1L2)U(L2L1)

It is context free from closure to union and concatenation.

Let's prove that L3 is the language we're looking for. First of all as we have seen it deals with all possible odd length words. As for the even length words, if they are in the language, there is one pair of terminals, at least, which is different on both sides of the word. Call this pair a and b. Every even word can be divided like this:

(x_1^m)(a)(x_2^m)(y_1^n)(b)(y_2^n)

and this is exactly

(L1L2)U(L2L1)

This implies that CFG languages are not closed under complement.

可可 2024-11-02 13:44:15

之前提供的答案是不正确的,因为它没有涵盖 L 的补码中存在的所有字符串,例如 011,110,11001 等。(之前的答案导致我失去了一些宝贵的分数,所以更新:))
下面的语法可以用来证明 L 补码是 CFL。

S→A|B|AB|BA

A→a|aAa|aAb|bAb|bAa

B→b|aBa|aBb|bBb|bBa

A 生成以 a 为中心的奇数长度的单词。 B 和 b 相同。

此处提供了更清晰的解释。

The previously provided answer is incorrect as it doesn't cover all strings present in complement of L for example 011,110,11001, etc. (Previous answer caused me lose some precious marks, so updating :) )
The following grammar can instead be used to prove that L complement is CFL.

S→A|B|AB|BA

A→a|aAa|aAb|bAb|bAa

B→b|aBa|aBb|bBb|bBa

A generates words of odd length with a in the centre. Same for B and b.

More clear explanation is present here.

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