HackerTube English?
程序的表达能力 →

一种语言能算什么,又能保证什么?

阶乘可以不用名字写出来。这个技巧提出了一个更难的问题:如果每个程序都必须停下来,还能允许任意递归吗?沿着这个分歧,再看幻灯片、库与语言扩展。

本文的问题 · 12
  1. 递归的表达能力与终止保证之间的取舍
  2. 极简解释器与幻灯片都能承载通用计算
  3. 让用户库承担语言增长
  4. 数组表达力强,不等于语言扩展无缝
  5. 写了自调用,运行时到底留下了什么?
  6. 一个关于规则的论证,什么时候变成物理猜想?
  7. 知道生成规则,能直接算出第一百万步吗?
  8. 没选中的分支,为什么已经递归了?
  9. 证明一个程序,和写出万能检查器,相差哪个量词?
  10. 两根枝条掉下去,为什么只用计算一次?
  11. 形式证明与算法判定的边界在哪里?
  12. 哪些无效状态能用结构排除,哪些要到查找时才知道?

递归的表达能力与终止保证之间的取舍

Weirich用不动点组合子让匿名函数获得递归能力;Wadler明确简单类型演算的终止保证排除了无限制不动点算子。同一递归机制在前者是表达能力来源,在后者是保证边界。

对照原文与时间戳 · 2
the function y calculates the fixpoint of an improver function.
Ruby Conf 12 - Y Not- Adventures in Functional Programming by Jim Weirich · ▶ 46:27–47:02
not using What's called the fixo operator that is unlimited General recursion
"Propositions as Types" by Philip Wadler · ▶ 21:59–22:07

比较的是演算与类型约束,不是宣称所有静态类型语言都不能递归。

极简解释器与幻灯片都能承载通用计算

Byrd说明变量查找、Lambda与应用的极小核心已能表达通用计算;PowerPoint演示以动画磁带和可修改转移表模拟图灵机。两者揭示通用计算不依赖熟悉的表面语法或庞大语言。

对照原文与时间戳 · 2
you only need these three lines that's turn complete actually
William Byrd on "The Most Beautiful Program Ever Written" [PWL NYC] · ▶ 44:35–44:43
essentially imitate any transition function of any other touring machine
On The Turing Completeness of PowerPoint (SIGBOVIK) · ▶ 4:07–4:17

PowerPoint仍需人工点击推进;可计算性等价不意味着速度、内存或工程可用性等价。

让用户库承担语言增长

Steele要求用户定义构造像语言原语一样自然,以少数增长机制容纳多种领域需求;Unison的分布式能力与解释器让用户自行实现执行策略,把分布式编程抽象交给库作者。

对照原文与时间戳 · 2
the new words defined by a library should look just like the primitives
Growing a Language, by Guy Steele · ▶ 23:25–23:32
the idea is that distributed programming should just be a library
"Unison: a new distributed programming language" by Paul Chiusano · ▶ 36:04–36:12

Unison未被证明直接源自该演讲;远端批计算示例不等于完整解决状态型分布式服务。

数组表达力强,不等于语言扩展无缝

生命游戏展示 APL 原语组合如何省去显式循环;Steele 则指出历史 APL 的用户定义与内建原语外观不一致,使社区难以无缝扩展语言。前者的表达能力并不自动解决后者的扩展接口问题。

对照原文与时间戳 · 2
you'll notice that it contains no explicit loops and no temporary variables
Conway's Game Of Life in APL · ▶ 3:11–3:29
new words defined by the user do not look like language primitives at all.
Growing a Language, by Guy Steele · ▶ 20:13–20:18

Steele 评价的是其演讲时期的 APL;不能据此断言现代 Dyalog 缺少用户函数或算子。

写了自调用,运行时到底留下了什么?

在纸上算 3+2。一种写法先记下「回来后再加一」,另一种每次把一边减一、另一边加一。两者的定义都可以调用自身,但只有前者积压尚未执行的工作。斐波那契又多出一件事:几个分支可能反复求同一个 F(k)。记忆化能让以后的调用查表,却没有消去第一次求值的依赖。读到递归程序时,不妨另画两张图:哪些结果还在等,哪些子问题已经算过?

原文与时间戳 · 2
There's nothing special about the fact that the definition is recursive that leads to a recursive process.
Lecture 1B | MIT 6.001 Structure and Interpretation, 1986 · ▶ 30:37–30:46
So I count how many different subproblems do I need to do?
Lecture 19: Dynamic Programming I: Fibonacci, Shortest Paths · ▶ 22:42–22:45

一个关于规则的论证,什么时候变成物理猜想?

Penrose 说,懂得一套规则为何给出真命题,与机械地按规则走并不是同一回事。后来他谈到引力可能改变对量子力学的描述。即使接受前一段作为数学上的动机,后一段也还需要独立的物理检验。把这两处时间戳并排,是为了标出论证换了对象;它们不能合起来证明程序不可能具有意识。

原文与时间戳 · 2
understanding why the rules give you truths enables you to transcend the rules.
Roger Penrose: Physics of Consciousness and the Infinite Universe | Lex Fridman Podcast #85 · ▶ 23:38–23:45
gravity affects the structure of quantum mechanics too.
Roger Penrose: Physics of Consciousness and the Infinite Universe | Lex Fridman Podcast #85 · ▶ 53:21–53:24

知道生成规则,能直接算出第一百万步吗?

规则 30 的生成规则很短。Wolfram 回忆,自己是把它跑起来,才看到简单初态长出了意料之外的图案。另一次访谈把问题问得更精确:指定百万步后的一个输出,是否有办法省去大部分中间计算?直接运行给出答案,图案的复杂程度却既不能构造捷径,也不能证明捷径不存在。若声称找到规律,先写清它能预测哪一列、哪些初态,再到没有参与猜测的位置上检验。

原文与时间戳 · 4
from very simple initial conditions, it makes really complicated behavior
Stephen Wolfram: Cellular Automata, Computation, and Physics | Lex Fridman Podcast #89 · ▶ 94:00–94:06
no intuition, just experimental science
Stephen Wolfram: Cellular Automata, Computation, and Physics | Lex Fridman Podcast #89 · ▶ 95:23–95:26
you can run it for a million steps
Stephen Wolfram: Complexity and the Fabric of Reality | Lex Fridman Podcast #234 · ▶ 8:15–8:17
I don't have to go through anything like that computational effort
Stephen Wolfram: Complexity and the Fabric of Reality | Lex Fridman Podcast #234 · ▶ 8:26–8:29

没选中的分支,为什么已经递归了?

把 if 写成普通选择函数,左边放已经结束时的答案,右边放“再算一步”。Beazley 的 Python 示范卡在调用约定上:进入选择函数以前,两个实参都要先求值,右边已经开始递归。把两边的计算各装进一个可稍后调用的函数,选择之后再执行,顺序才对。试着只在每个分支开头打印一次,就能观察到表示相同决定的两段写法,在运行时做了不同的工作。

原文与时间戳 · 2
it goes down both paths. And it turns out that the second path just explodes in infinite recursion
David Beazley - Lambda Calculus from the Ground Up - PyCon 2019 · ▶ 158:20–158:30
you're basically delaying the calculation to some later point in time
David Beazley - Lambda Calculus from the Ground Up - PyCon 2019 · ▶ 159:35–159:45

证明一个程序,和写出万能检查器,相差哪个量词?

Bernstein 举了一个能做成的验证任务:拿到实际编译出的排序机器码,对它检查规定的性质。这样连编译器是否忠实都少假设了一层。停机问题把范围推到任意程序与输入。现在假设有这样一个总能作答的检查器,造一个反着做的程序,让它读自己的描述。如果预测会停,它就一直转;如果预测不停,它就停。问清要证明的是哪个程序、哪些输入上的哪条性质,就不会把两场演讲听成互相矛盾。

原文与时间戳 · 3
verification isn't going to rely on some compiler being correct.
35C3 - The year in post-quantum crypto · ▶ 60:38–60:43
I make it loop forever without ever stopping
Turing & The Halting Problem - Computerphile · ▶ 4:16–4:19
Either way we get a contradiction
Turing & The Halting Problem - Computerphile · ▶ 5:17–5:22

两根枝条掉下去,为什么只用计算一次?

在 Hackenbush 的例子里,两步外观不同的走法可能留下等价局面。按后继局面递归求值时,可以复用先前的结果。这里要守住的条件是轮到哪一方、双方各自有哪些后继;只因两幅图形长得像就把它们合并,也许会删掉决定胜负的一步。

原文与时间戳 · 2
these two one positions are essentially identical
HACKENBUSH: a window to a new world of math · ▶ 29:23–29:26
another huge perk of our recursive definitions
HACKENBUSH: a window to a new world of math · ▶ 33:10–33:14

形式证明与算法判定的边界在哪里?

Gödel 不完备性与停机问题给出两种相关但不相同的边界。本站对 Veritasium《数学的根本缺陷》的导读,将不完备性结论限定在一致、可有效公理化且能表达足够算术的系统:有些命题无法在系统内证明或反驳;它随后转向图灵的结论,不存在能对任意程序和输入总是判定停机的算法。Computerphile 的《图灵与停机问题》讲解用程序构造导出“Either way we get a contradiction”,让停机判定假设本身成为检查对象。并读时要分别追踪前提:一个谈形式系统的可证性,另一个谈算法的普遍判定能力;二者相关,不是同一句定理,也不意味着程序都不能分析。

原文与时间戳 · 4
truth and provability are not at all the same thing
Math's Fundamental Flaw · ▶ 21:22–21:34
if a program will halt or not on a particular input
Math's Fundamental Flaw · ▶ 24:10–24:22
I make it loop forever without ever stopping
Turing & The Halting Problem - Computerphile · ▶ 4:16–4:19
Either way we get a contradiction
Turing & The Halting Problem - Computerphile · ▶ 5:17–5:22

哪些无效状态能用结构排除,哪些要到查找时才知道?

Richard Feldman 把 Elm 问卷里的题目和对应答复放进同一条记录。这样,表示本身就放不下一条没有题目的答复。Catherine West 的游戏实体还有一项随时间变化的约束。槽位会回收再用,她给索引加上世代编号,查找时再核对编号是否仍然匹配,在世代编号尚未回绕时,避免旧句柄命中新实体。两个例子都先把核对所需的信息放进表示,再分别指出检查在哪一步发生。问卷的配对关系来自记录的形状,实体的存活关系则还需要在访问时核对。

原文与时间戳 · 2
you cannot have a response without a corresponding prompt
"Making Impossible States Impossible" by Richard Feldman · ▶ 11:11–11:15
one extra field which is called a generation
RustConf 2018 - Closing Keynote - Using Rust For Game Development by Catherine West · ▶ 31:27–31:39

读完再想一步

给语言加一种表达能力前,先写下一个从此可能失去的保证。