数学史

图灵与停机问题

图灵问是否存在一个通用程序,能判断任意程序是否会停机。对角线构造表明这样的判定器会自我矛盾。

7 分钟难度 3/3交互演示区域不展示广告。
Step1 / 4StatusAssume H existsDecider HAssumedHalting problemUndecidable
1. Assume H existsH always decides2. Build DD calls H(D)3. Run DD does the opposite4. ContradictionH must be wrong
Decider H (assumed)
H(P):
  if P(P) halts:
    return "halts"
  else:
    return "loops"
Program D (diagonal)
D():
  if H(D) == "halts":
    loop forever
  else:
    halt
Assume H exists

Assume a program H(P) always halts and correctly reports whether any program P halts.

The diagonal trick is the same idea as Cantor’s argument. H is assumed to work for every program. D is then designed specifically to disagree with H’s answer about D. That single self-reference breaks the assumption, so no general halting algorithm exists.

你看到的是什么

1

假设程序 H(P) 总能停机,并对任意程序 P 输出“停机”或“循环”。

2

构造 D,让它调用 H 判断自身:如果 H 说 D 会停机,D 就循环;如果 H 说 D 会循环,D 就停机。

3

运行 D 会得到与 H 预测相反的结果,因此 H 不可能对所有程序都正确。

为什么重要

不可判定性为软件验证、静态分析和人工智能设定了根本限制。有些问题无法由任何通用算法回答。

复杂度与细节

这个证明是对角线论证,而不是算法。它排除了任何总能停机的判定器,与运行时间无关。

常见问题

能判断某些程序是否停机吗?+

可以。许多受限程序可以分析。定理说的是不存在一个算法能正确判断所有程序。

这和 P 与 NP 有关吗?+

两者不同。P 与 NP 讨论高效计算;不可判定性说的是即使时间无限,算法也不存在。