The halting problem cannot be solved for Turing complete languages and it can be solved trivially for some non-TC languages like regexes where it always halts.
图灵完整语言无法解决暂停问题,对于某些非TC语言(例如始终停止的正则表达式),可以解决这个问题。
I was wondering if there are any languages that has both the ability to halt and not halt but admits an algorithm that can determine whether it halts.
我想知道是否有任何语言都具有停止和不停止的能力,但允许一种算法可以确定它是否停止。
3 个解决方案
#1
Yes. One important class of this kind are primitive recursive functions. This class includes all of the basic things you expect to be able to do with numbers (addition, multiplication, etc.), as well as some complex classes like @adrian has mentioned (regular expressions/finite automata, context-free grammars/pushdown automata). There do, however, exist functions that are not primitive recursive, such as the Ackermann function.
是。这种类型的一个重要类是原始递归函数。这个类包括你期望能够用数字做的所有基本的东西(加法,乘法等),以及像@adrian所提到的一些复杂类(正则表达式/有限自动机,无上下文语法/下推)自动机)。但是,存在不是原始递归的函数,例如Ackermann函数。
It's actually pretty easy to understand primitive recursive functions. They're the functions that you could get in a programming language that had no true recursion (so a function f cannot call itself, whether directly or by calling another function g that then calls f, etc.) and has no while-loops, instead having bounded for-loops. A bounded for-loop is one like "for i from 1 to r" where r is a variable that has already been computed earlier in the program; also, i cannot be modified within the for-loop. The point of such a programming language is that every program halts.
实际上,理解原始递归函数非常容易。它们是你可以在没有真正递归的编程语言中获得的函数(因此函数f不能直接调用自身,或者通过调用另一个函数g然后调用f等)并且没有while循环,而是有限制的循环。有界for循环就像“for i from 1 to r”,其中r是一个已经在程序中早先计算过的变量;另外,我不能在for循环中修改。这种编程语言的意义在于每个程序都会停止。
Most programs we write are actually primitive recursive (I mean, can be translated into such a language).
我们编写的大多数程序实际上是原始的递归(我的意思是,可以翻译成这样的语言)。
#2
The halting problem does not act on languages. Rather, it acts on machines (i.e., programs): it asks whether a given program halts on a given input.
暂停问题不会对语言起作用。相反,它作用于机器(即程序):它询问给定程序是否在给定输入上停止。
Perhaps you meant to ask whether it can be solved for other models of computation (like regular expressions, which you mention, but also like push-down automata).
也许你想问一下它是否可以用于其他计算模型(比如正则表达式,你提到它,但也像下推自动机)。
Halting can, in general, be detected in models with finite resources (like regular expressions or, equivalently, finite automata, which have a fixed number of states and no external storage). This is easily accomplished by enumerating all possible configurations and checking whether the machine enters the same configuration twice (indicating an infinite loop); with finite resources, we can put an upper bound on the amount of time before we must see a repeated configuration if the machine does not halt.
通常,可以在具有有限资源的模型中检测停止(如正则表达式,或者等效地,有限自动机,其具有固定数量的状态且没有外部存储)。这可以通过枚举所有可能的配置并检查机器是否进入两次相同的配置(表示无限循环)来轻松完成;在资源有限的情况下,如果机器没有停止,我们可以在必须看到重复配置之前的时间量上限。
Usually, models with infinite resources (unbounded TMs and PDAs, for instance), cannot be halt-checked, but it would be best to investigate the models and their open problems individually.
通常,具有无限资源的模型(例如,无限制的TM和PDA)无法停止检查,但最好单独调查模型及其开放问题。
(Sorry for all the Wikipedia links, but it actually is a very good resource for this kind of question.)
(对不起所有的*链接,但它实际上是这类问题的一个非常好的资源。)
#3
The short answer is yes, and such languages can even be extremely useful.
简短的回答是肯定的,这些语言甚至可以非常有用。
There was a discussion about it a few months ago on LtU: http://lambda-the-ultimate.org/node/2846
几个月前在LtU上讨论过它:http://lambda-the-ultimate.org/node/2846
#1
Yes. One important class of this kind are primitive recursive functions. This class includes all of the basic things you expect to be able to do with numbers (addition, multiplication, etc.), as well as some complex classes like @adrian has mentioned (regular expressions/finite automata, context-free grammars/pushdown automata). There do, however, exist functions that are not primitive recursive, such as the Ackermann function.
是。这种类型的一个重要类是原始递归函数。这个类包括你期望能够用数字做的所有基本的东西(加法,乘法等),以及像@adrian所提到的一些复杂类(正则表达式/有限自动机,无上下文语法/下推)自动机)。但是,存在不是原始递归的函数,例如Ackermann函数。
It's actually pretty easy to understand primitive recursive functions. They're the functions that you could get in a programming language that had no true recursion (so a function f cannot call itself, whether directly or by calling another function g that then calls f, etc.) and has no while-loops, instead having bounded for-loops. A bounded for-loop is one like "for i from 1 to r" where r is a variable that has already been computed earlier in the program; also, i cannot be modified within the for-loop. The point of such a programming language is that every program halts.
实际上,理解原始递归函数非常容易。它们是你可以在没有真正递归的编程语言中获得的函数(因此函数f不能直接调用自身,或者通过调用另一个函数g然后调用f等)并且没有while循环,而是有限制的循环。有界for循环就像“for i from 1 to r”,其中r是一个已经在程序中早先计算过的变量;另外,我不能在for循环中修改。这种编程语言的意义在于每个程序都会停止。
Most programs we write are actually primitive recursive (I mean, can be translated into such a language).
我们编写的大多数程序实际上是原始的递归(我的意思是,可以翻译成这样的语言)。
#2
The halting problem does not act on languages. Rather, it acts on machines (i.e., programs): it asks whether a given program halts on a given input.
暂停问题不会对语言起作用。相反,它作用于机器(即程序):它询问给定程序是否在给定输入上停止。
Perhaps you meant to ask whether it can be solved for other models of computation (like regular expressions, which you mention, but also like push-down automata).
也许你想问一下它是否可以用于其他计算模型(比如正则表达式,你提到它,但也像下推自动机)。
Halting can, in general, be detected in models with finite resources (like regular expressions or, equivalently, finite automata, which have a fixed number of states and no external storage). This is easily accomplished by enumerating all possible configurations and checking whether the machine enters the same configuration twice (indicating an infinite loop); with finite resources, we can put an upper bound on the amount of time before we must see a repeated configuration if the machine does not halt.
通常,可以在具有有限资源的模型中检测停止(如正则表达式,或者等效地,有限自动机,其具有固定数量的状态且没有外部存储)。这可以通过枚举所有可能的配置并检查机器是否进入两次相同的配置(表示无限循环)来轻松完成;在资源有限的情况下,如果机器没有停止,我们可以在必须看到重复配置之前的时间量上限。
Usually, models with infinite resources (unbounded TMs and PDAs, for instance), cannot be halt-checked, but it would be best to investigate the models and their open problems individually.
通常,具有无限资源的模型(例如,无限制的TM和PDA)无法停止检查,但最好单独调查模型及其开放问题。
(Sorry for all the Wikipedia links, but it actually is a very good resource for this kind of question.)
(对不起所有的*链接,但它实际上是这类问题的一个非常好的资源。)
#3
The short answer is yes, and such languages can even be extremely useful.
简短的回答是肯定的,这些语言甚至可以非常有用。
There was a discussion about it a few months ago on LtU: http://lambda-the-ultimate.org/node/2846
几个月前在LtU上讨论过它:http://lambda-the-ultimate.org/node/2846