∴Logic Wiki逻辑学知识库搜索概念、谬误与案例/EN

可计算性与停机问题

Computability and the halting problem

可计算性讨论是否存在满足要求的算法,而非当前机器跑得快不快。

概念与边界

图灵机、递归函数等模型刻画算法计算。丘奇–图灵论题把有效可计算这一非形式概念与形式模型联系起来,因此不能简单称为普通数学定理。

停机问题的不可判定性说,不存在对所有程序与输入都正确判断是否停机的一般算法。它不妨碍我们证明许多特定程序停机,也不表示所有程序行为都无法分析。

The concept and its limits

Turing machines and recursive functions formalize algorithmic computation. The Church–Turing thesis links an informal notion of effective calculation to formal models and is not simply an ordinary mathematical theorem.

Undecidability of halting excludes a general algorithm correctly deciding termination for every program and input. It does not prevent proofs of termination for many particular programs.

把概念用起来

一个固定执行十次后退出的循环很容易证明停机。一般不可判定的结论,不能用来否定这个具体证明。

Working through an example

A loop that runs exactly ten times and exits is easy to prove terminating. General undecidability does not invalidate this particular proof.

判定与识别的区别

判定算法需要对范围内的每个输入都在有限时间内给出正确的是或否。识别程序则可以在“是”的实例上最终确认,而在某些“否”的实例上一直运行。模拟一个程序,看到它结束,就确认了这次停机;一直没有结束,却不能仅凭等待宣布它永远不停。

复杂度继续追问可计算任务需要多少时间或空间。指数时间算法仍然是算法;换更快的硬件可能改善耗时,却不能仅凭提速消除一般不可判定性的证明。

本节依据:SEP《Computability and Complexity》§§2.1–2.4 ↗

Deciding versus recognizing

A decision algorithm must halt with the correct yes or no answer on every input in its domain. A recognizer may eventually confirm positive instances while running forever on some negative ones. Simulation confirms a particular halt when it occurs; waiting without termination does not establish nontermination.

Complexity asks how much time or space a computable task requires. An exponential-time algorithm is still an algorithm. Faster hardware may improve runtime but does not by itself overcome a proof of general undecidability.

Section sources: SEP, Computability and Complexity, §§2.1–2.4 ↗

停机问题的反证思路

假设存在 H,能对任何程序 p 和输入 x 总是停机,并正确回答 p(x) 会不会停机。构造程序 D(x):先问 H(x,x);若回答会停机,D 就永远循环;若回答不会停机,D 就立即停机。只要 H 真是总能正确回答的算法,这样的 D 就可以按规则构造。

现在把 D 的编码输入 D 自己。H 若预测会停机,D 按定义不停;H 若预测不停,D 按定义停机。两种回答都错,因此最初假设的 H 不存在。矛盾针对万能判定器的假设,不是所有程序或计算模型本身的矛盾。

The diagonal contradiction

Suppose H always halts and correctly decides whether any program p halts on input x. Construct D(x): query H(x,x); if it predicts halting, loop forever; otherwise halt immediately. If H really is a total correct algorithm, D can be constructed using it.

Now run D on its own code. If H predicts halting, D does not halt; if H predicts nontermination, D halts. Either answer is wrong, contradicting the assumed universal decider. The contradiction defeats that assumption, not the existence of programs or computation.

限制问题后仍可得到算法

若问题改为“这个程序是否会在前 1,000 步内停机”,就可以模拟至多 1,000 步并给出回答。这个有界问题不同于最终是否停机。报告中应清楚区分“在测试界限内未停机”与“证明永不停止”。

对特定程序,也可通过循环不变量或严格下降的自然数量证明终止。例如每次循环把非负整数 n 减少 1,且 n=0 时退出;只要这些条件始终成立,就至多执行初始 n 次。一般不可判定性不取消这种局部证明。

Restricted problems can remain decidable

The question “Does this program halt within 1,000 steps?” can be decided by simulating at most 1,000 steps. This bounded problem differs from eventual halting. A report must distinguish failure to halt within a test limit from a proof of nontermination.

Specific programs may admit termination arguments using invariants or a strictly decreasing natural-number measure. If each iteration reduces a nonnegative n by one and exits at zero, the loop executes at most the initial n times, provided those conditions hold. General undecidability does not invalidate such local proofs.

确认算法承诺了什么

先检查算法是否要求每次都结束,再检查它回答的具体问题。

独立练习 1

分析器运行一分钟后输出“未知”。这是否与停机问题不可判定矛盾?

查看答案与推理过程

不矛盾。它没有承诺对所有程序给出正确的是或否。允许未知可以换取终止或实用分析范围,但不能再称作解决一般停机问题的判定器。

独立练习 2

程序反复执行 n←n−1,但在 n=0 时把 n 改回 10。还能用 n 严格下降证明停机吗?

查看答案与推理过程

不能用这个论证,因为重置一步破坏了严格下降条件。若循环没有其他退出条件,它会反复重置。应检查每个循环步骤,而不是只检查多数步骤都在减小。

Check the algorithm’s promise

Check whether termination is promised on every input and which question is answered.

Independent exercise 1

An analyzer returns unknown after one minute. Does this contradict undecidability of halting?

Show answer and reasoning

No. It does not promise a correct yes or no for every program. Allowing unknown may make analysis terminate or remain practical, but it is not a decider for the general halting problem.

Independent exercise 2

A program repeatedly sets n to n−1, but resets n to 10 at zero. Can strict decrease of n prove termination?

Show answer and reasoning

That argument fails because the reset violates strict decrease. Without another exit, the cycle repeats. A termination measure must meet its required condition at every relevant iteration, not merely most of them.

检查你的理解

问:速度很慢是否就是不可计算?答:不是;可计算性与复杂度是不同问题。

Check your understanding

Question: Does being very slow mean uncomputable? Answer: No. Computability and complexity are different questions.

参考文献

  1. Computability and Complexity ↗
    Stanford Encyclopedia of Philosophy · 相关章节
    §§1–2: computation and the halting problem
    版本、许可与查阅范围