简体   繁体   English

使用零语言的CFG是否可以确定?

[英]Is a CFG using a nil language decidable?

If I have a Context-Free Grammar G such that the language of G is nil, is G decidable? 如果我有一个上下文无关的语法G,使得G的语言为零,那么G是否可判定?

I know the answer is yes, but I am having trouble proving this. 我知道答案是肯定的,但是我很难证明这一点。 My first thought is to say there is only one state, q1, which is the start state and accept state for a Turing Machine that is the equivalent of G. This machine will accept no input and immediately halt and accept because it has reached an accept state. 我的第一个想法是说,只有一个状态q1,它是图灵机的开始状态和接受状态,它等效于G。该机器将不接受任何输入,因为已达到接受状态,所以立即停止并接受州。 Is this an acceptable answer, or am I way off here? 这是可以接受的答案,还是我离开这里?

EDIT: 编辑:

As Joel said below, the language I described accepts all strings. 就像乔尔(Joel)在下面说的那样,我描述的语言接受所有字符串。 To counter this, I propose a second machine, G'. 为了解决这个问题,我建议使用第二台机器G'。 G' has 3 states, the start state q1, an accept state q2, and a reject state q3. G'具有3种状态,即开始状态q1,接受状态q2和拒绝状态q3。 q1 transitions to q3 on all symbols in the alphabet of G', and so does q2. 在G'字母中的所有符号上,q1都转换为q3,q2也是如此。 q1 has an epsilon transition to q2. q1具有到q2的ε过渡。 Therefore, if any symbols exist in the string being fed to G', G' will reject. 因此,如果在送入G'的字符串中存在任何符号,则G'将拒绝。 If there are no symbols, the only option is to take the epsilon transition into the accept state. 如果没有符号,则唯一的选择是使epsilon转换进入接受状态。 How does that sound? 听起来怎么样?

EDIT: 编辑:

The above solution was proven to accept the language L(G') = {""}. 事实证明上述解决方案可以接受语言L(G')= {“”}。

As you said, the answer is yes. 正如您所说,答案是肯定的。 A general proof is the fact that given a CFG G you can easily (well sort of) construct a TM simulates derivations using that grammar. 一个一般的证明是,对于给定的CFG G,您可以轻松地(很好地)构造一个TM使用该语法模拟派生的事实。 However, you are looking for a short proof for the empty language. 但是,您正在寻找空语言的简短证明。 (The fact that you have a CFG in this case is irrelevant.) (在这种情况下,您拥有CFG的事实是无关紧要的。)

You are on the right track in that if you can construct a TM that always halts for a given language L, then L is decidable. 如果您可以构建始终针对给定语言L停止运行的TM,那么您就走上了正确的道路,那么L是可以确定的。 However, the machine that you describe will actually accept every string, ie the language consisting of every possible string over the alphabet. 但是,您描述的机器实际上将接受每个字符串,即由字母上每个可能的字符串组成的语言。 That's because if the start state is also an accept state, then the Turing machine will accept immediately when it starts. 这是因为,如果开始状态也是接受状态,那么图灵机将在启动时立即接受。 It does not have to read the entire input string (or any part of it) to accept. 它不必读取整个输入字符串(或其中的任何部分)即可接受。

To define a TM that accepts nothing, let the set of accepting states be empty. 要定义不接受任何内容的TM,请使接受状态集为空。 To guarantee that your machine always halts, your transition function can be empty as well. 为了确保您的机器始终停止,转换功能也可以为空。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM