DOOM 关卡里跑 MNIST、把 6502 编译进 Qwen,还有一道 1974 年的组合题MNIST in a DOOM Level, a 6502 CPU in Qwen Weights, and a 1974 Combinatorics Problem
发布于 2026-11-01Published 2026-11-01
今日深读Today's Deep Read
DOOM 关卡即神经网络:用巫毒娃娃做整数计算A DOOM Level as a Neural Network: Integer Math with Voodoo Dolls
通常『把神经网络编译进一个奇怪介质』的尝试,都是把它烧进 FPGA 或者跑在微控制器上。mottopanikeiku 选了 DOOM 的关卡系统——一个 90 年代的 2D 引擎的地图格式——作为『计算介质』,用 1355 个巫毒娃娃(voodoo dolls,DOOM 里的装饰性精灵)当神经元。这个选择本身就是文章的第一个声明:计算介质不必是现代硬件,可以是任何能忠实保存和传递整数的数据结构。The usual attempts to 'compile a neural network into an exotic medium' burn it into an FPGA or run it on a microcontroller. mottopanikeiku chose DOOM's level system — a 90s 2D engine's map format — as the 'compute medium,' using 1,355 voodoo dolls (decorative sprites in DOOM) as neurons.
第一步是把一个标准的 float 版 MNIST 分类器训练好(97.58% 准确率),然后量化成整数——这一步很关键:DOOM 地图的每一格只能存一个 16-bit 整数,没有浮点。量化误差必须控制在 NumPy 前向传播精确可比对的范围内,这意味着作者的量化方案本身就是一个独立的工程贡献,不只是『把网络搬过去』,而是『让搬过去之后仍然精确』。Step one: train a standard float MNIST classifier (97.58% accuracy), then quantize it to integers — critical because every DOOM map cell stores only a 16-bit integer; there are no floats. The quantization error must stay within NumPy's exact forward-propagation tolerance.
第二步是把量化后的权重『画进』DOOM 地图里:每个巫毒娃娃的位置编码一个神经元,娃娃之间的连接(通过关卡事件触发器)编码权重,DOOM 引擎在运行时逐格执行整数乘法。宿主程序负责渲染、读取输入,引擎本身不需要任何修改——它以为自己在跑一个游戏关卡,实际上在执行一次前向传播。Step two: 'paint' the quantized weights into the DOOM map: each voodoo doll's position encodes a neuron; connections between dolls (via level event triggers) encode the weights; the DOOM engine executes integer multiplication cell by cell at runtime.
第三步是验证。作者写了一个 Python 工具读回 DOOM 地图里每格的数值,与 NumPy 的 float 前向传播逐格比对,容差设为 0。然后对 20k 个随机 fuzzed 网络做同样比对,零 mismatch。这不是『跑一下看看』,是逐 cell 的精确验证,排除了『结果碰巧一样』的可能。Step three: verification. The author wrote a Python tool that reads back the value in every DOOM map cell and compares cell-by-cell with NumPy float forward propagation, with tolerance set to 0. Then 20,000 fuzzed random networks, same comparison, zero mismatches. This is not 'run it and see' — it is cell-exact verification.
这件事的意义:它证明『神经网络』作为一个抽象计算单元,可以在任何能存整数并做整数运算的介质里运行——哪怕那个介质是 1993 年的 2D 游戏引擎。边界不在于『是不是 GPU』,而在于『介质能不能忠实保存和传递整数』。The significance: it proves a 'neural network' as an abstract compute unit can run inside any medium that stores and faithfully transmits integers — even a 1993 2D game engine. The boundary is not 'is it a GPU'; it is 'can the medium faithfully store and transmit integers.'
对程序员的启示:下次你设计一个嵌入式系统、一个约束极强的存储格式、或者任何一个『介质不是为你的算法设计的』系统,先问『能不能把一个小网络塞进去』——如果能,你的介质就有足够的计算表达能力,即使它看起来完全不像计算设备。这个思想实验把『可计算性』和『介质是否像计算机』这两件事彻底解耦了。For programmers: next time you design an embedded system or a heavily constrained storage format, ask 'could I fit a small network in here?' If yes, your medium has enough computational expressiveness, even if it looks nothing like a computing device.
AI 思考Thinking About AI
- 让想法传播:Derek Sivers 的『useful not true』写作法Let Ideas Travel: Derek Sivers' 'Useful Not True' Writing Method
- Sivers 的核心主张:写东西不是为了留下一个『我自己的表达』,而是为了让『这个想法』能以最高效率传播——像病毒一样在人与人之间复制,且复制时不丢信息。Sivers' core claim: you write not to leave 'my own expression' behind, but so that 'the idea' replicates between people at maximum efficiency — like a virus, without losing information in replication.
- 方法:把一个概念压缩成一句『useful not true』的口号——字面上不完全正确(所以有记忆点),但捕捉到了内核(所以有用)。比如『useful not true』本身就是个例子:它描述的不是真相,而是一个让想法更容易被记住和转述的包装。Method: compress a concept into one 'useful not true' slogan — literally not fully true (hence memorable) but capturing the core (hence useful). 'Useful not true' is itself the example: it doesn't describe the truth; it's a packaging that makes the idea easier to remember and retell.
- 推论:如果你的博客/文档/演讲要讲一个观点,先问『这句话能不能被一个陌生人 60 秒内复述给别人』——能,就成功;不能,就继续压缩。Corollary: if your blog/doc/talk is presenting an idea, first ask 'can a stranger retell this to someone else in 60 seconds?' — if yes, success; if no, keep compressing.
- 个人成长的三个度量:变化速率、解决问题时间、未来选项数Three Metrics for Personal Growth: Rate of Change, Time to Solve Problems, Number of Future Options
- Huyen 的核心框架:不要用净资产或粉丝数来度量个人成长,而用三个可量化维度——变化速率(多少年『变成一个新的人』,类比金融的 72 法则:年增速 8%,72÷8≈9 年翻倍,人也有自己的『翻倍周期』)、解决问题的时间(职业/家庭/财务三大问题各需多久解决)、未来选项的数量(强化学习里的『最大化赋能』原则)。Huyen's core framework: don't measure personal growth by net worth or follower count; use three quantifiable dimensions — rate of change (how often you 'become a new person,' analogous to finance's rule of 72: at 8% annual growth, 72÷8 ≈ 9 years to double; people have their own doubling cycle), time to solve big problems (career/family/finance, each taking roughly a decade), and number of future options (reinforcement-learning 'empowerment maximization').
- 她把强化学习的『empowerment maximization』迁移到职业选择:面对多个开关,选那个打开最多门的那一个——对应现实里选『薪资低但给你更多曝光和可迁移技能』的工作,而不是选短期薪资最高的。She transfers 'empowerment maximization' to career choice: facing multiple switches, choose the one that opens the most doors — in practice, pick the job that pays less but gives more exposure and transferable skills, not the one with the highest short-term salary.
- 她把这套框架迁移到 AI 工具选择:未来选项最多的模型,是让你能接触更多种类任务、积累更多可迁移技能的模型,而不是某个特定 benchmark 分数最高的模型。She transfers this framework to AI tool selection: the model with the most future options is the one that lets you touch more task types and build more transferable skills, not the one with the highest specific benchmark score.
- 不可避免性:拒绝让 AI 的叙事框架偷走你的选择权Inevitabilism: Refusing to Let the AI Narrative Steal Your Choice
- Renner 借 Zuboff 的概念『Inevitabilism』(不可避免主义):一群人在论证 AI 未来时,不回答『这是你想看到的未来吗』,而回答『你如何适应这个必然到来的未来』——一旦这样框架化,任何持不同观点的人都会被『否认现实』一笔带过。Renner borrows Zuboff's concept of 'inevitabilism': people arguing for an AI future do not answer 'is this the future you want?' but 'how will you adapt to this inevitable future?' - once framed this way, anyone holding a different view can be dismissed as 'denying reality' with a single stroke.
- 他的核心论点:框架本身就是论证。Mark Zuckerberg 的『与 AI 共存,作为合作者而非主宰者』、Andrew Ng 的『AI 是新电力』、Ginni Rometty 的『用 AI 的人将取代不用 AI 的人』——这些话不直接断言结论,而是预先排除了所有反对讨论的空间。His core argument: the frame IS the argument. Mark Zuckerberg's 'coexist with AI as collaborators, not masters,' Andrew Ng's 'AI is the new electricity,' Ginni Rometty's 'those who use AI will replace those who don't' - none of these statements directly assert a conclusion; they preclude the space for any opposing discussion.
- 推论:下次有人对你说『AI 不会取代人,但会用 AI 的人取代不用 AI 的人』,先别急着点头——先问一句:他说的『未来』是描述性的还是规范性的?如果是规范性的(这是他想要的未来),你的问题就从『如何适应』变成『我是否接受这个框架』。Corollary: next time someone says 'AI won't replace humans, but those who use AI will replace those who don't,' don't nod reflexively - first ask: is the 'future' they're describing descriptive or normative? If normative (this is the future they want), your question shifts from 'how do I adapt' to 'do I accept this frame at all?'.
数学之美Beauty of Mathematics
每日 Lean 谜题 · 周日Daily Lean Puzzle · Sunday ★★★★★★★
1974 年 IMO P3:一个不整除 5 的组合和IMO 1974 P3: A Combinatorial Sum Not Divisible by 5
设 $S_n = \sum_{k=0}^{n} \binom{2n+1}{2k+1} \cdot 2^{3k}$。对任意整数 $n \geq 0$,证明 $S_n$ 不能被 5 整除。Let $S_n = \sum_{k=0}^{n} \binom{2n+1}{2k+1} \cdot 2^{3k}$. For every integer $n \geq 0$, prove that $S_n$ is not divisible by 5.
Lean 形式化陈述(把 sorry 换成你的证明):The statement in Lean (replace sorry with your proof):
/-
Copyright (c) 2025 The Compfiles Contributors. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Roozbeh Yousefzadeh
-/
import Mathlib.NumberTheory.Zsqrtd.Basic
import Mathlib.Tactic
/-!
# International Mathematical Olympiad 1974, Problem 3
Prove that the sum from k = 0 to n inclusive of
Choose[2n + 1, 2k + 1] * 2³ᵏ
is not divisible by 5 for any integer n ≥ 0.
-/
namespace Imo1974P3
open Finset
theorem imo1974_p3
(n : ℕ) :
¬ 5 ∣ ∑ k ∈ Finset.range (n + 1),
(Nat.choose (2 * n + 1) (2 * k + 1)) * (2^(3 * k)) := by
sorry
end Imo1974P3
在浏览器中挑战 ▶Try it in your browser ▶ 下载题目 .leanDownload puzzle .lean
提示Hint
把 $S_n$ 看成一个二次扩张环 $\mathbb{Z}\sqrt{8}$ 里某个数的虚部,然后用范数(norm)建立恒等式,最后在模 5 下用二次剩余判据推导矛盾。View $S_n$ as the imaginary part of an element in the quadratic ring $\mathbb{Z}\sqrt{8}$, use the norm to build an identity, then derive a contradiction modulo 5 via a quadratic-residue test.
答案与讲解Solution & walkthrough
- 第一步:把求和改写成 $(1 + \sqrt{8})^{2n+1}$ 中 $\sqrt{8}$ 的系数。展开 $(1+\sqrt{8})^{2n+1}$ 的二项式,偶数项给出 $\sqrt{8}$ 的系数,$\sqrt{8}^{2k} = 8^k$,而 $2^{3k} = 8^k$,所以虚部恰好是 $S_n$。Step 1: Rewrite the sum as the coefficient of $\sqrt{8}$ in $(1 + \sqrt{8})^{2n+1}$. Expanding the binomial, even-indexed terms give the $\sqrt{8}$ coefficient; $\sqrt{8}^{2k} = 8^k$ and $2^{3k} = 8^k$, so the imaginary part is exactly $S_n$.
- 第二步:建立范数恒等式。在 $\mathbb{Z}\sqrt{8}$ 里,元素 $a + b\sqrt{8}$ 的范数是 $a^2 - 8b^2$。因为范数可以乘法,$\mathrm{N}\bigl((1+\sqrt{8})^{2n+1}\bigr) = \mathrm{N}(1+\sqrt{8})^{2n+1} = (-7)^{2n+1}$。设实部为 $A$,虚部为 $S_n$,则 $A^2 - 8S_n^2 = (-7)^{2n+1}$。Step 2: Build the norm identity. In $\mathbb{Z}\sqrt{8}$, the norm of $a + b\sqrt{8}$ is $a^2 - 8b^2$. Since the norm is multiplicative, $\mathrm{N}\bigl((1+\sqrt{8})^{2n+1}\bigr) = \mathrm{N}(1+\sqrt{8})^{2n+1} = (-7)^{2n+1}$. Letting the real part be $A$ and the imaginary part be $S_n$, we get $A^2 - 8S_n^2 = (-7)^{2n+1}$.
- 第三步:模 5 化简。假设 $5 \mid S_n$,则在 $\mathbb{Z}/5\mathbb{Z}$ 里 $S_n \equiv 0$,恒等式变成 $A^2 \equiv (-7)^{2n+1} \pmod{5}$。计算 $(-7) \equiv 3 \equiv -2 \pmod{5}$,且 $(-7)^2 \equiv -1 \pmod{5}$,所以 $(-7)^{2n+1} = (-7) \cdot ((-7)^2)^n \equiv -2 \cdot (-1)^n \pmod{5}$,即 $A^2 \equiv \pm 2 \pmod{5}$。Step 3: Reduce modulo 5. Assume $5 \mid S_n$, so $S_n \equiv 0$ in $\mathbb{Z}/5\mathbb{Z}$, and the identity becomes $A^2 \equiv (-7)^{2n+1} \pmod{5}$. Now $(-7) \equiv -2 \pmod{5}$ and $(-7)^2 \equiv -1 \pmod{5}$, so $(-7)^{2n+1} = (-7)\cdot((-7)^2)^n \equiv -2 \cdot (-1)^n \pmod{5}$, giving $A^2 \equiv \pm 2 \pmod{5}$.
- 第四步:用二次剩余判据。模 5 的平方只有 $0, 1, 4$;不存在 $x$ 使得 $x^2 \equiv 2$ 或 $x^2 \equiv 3 \equiv -2 \pmod{5}$。因此 $A^2 \equiv \pm 2 \pmod{5}$ 无解,矛盾。假设 $5 \mid S_n$ 不成立,即 $S_n$ 不能被 5 整除。Step 4: Use the quadratic-residue criterion. The squares mod 5 are only $0, 1, 4$; there is no $x$ with $x^2 \equiv 2$ or $x^2 \equiv 3 \pmod{5}$. Hence $A^2 \equiv \pm 2 \pmod{5}$ is impossible — a contradiction. Therefore $5 \nmid S_n$, which completes the proof.
/-
Copyright (c) 2025 The Compfiles Contributors. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Roozbeh Yousefzadeh
-/
import Mathlib.NumberTheory.Zsqrtd.Basic
import Mathlib.Tactic
/-!
# International Mathematical Olympiad 1974, Problem 3
Prove that the sum from k = 0 to n inclusive of
Choose[2n + 1, 2k + 1] * 2³ᵏ
is not divisible by 5 for any integer n ≥ 0.
-/
namespace Imo1974P3
open Finset
/- We work in ℤ√8. The sum in question is the coefficient of √8 in
(1 + √8)^(2n+1), so taking norms gives A² - 8·B² = (-7)^(2n+1) where B is
the sum. If 5 ∣ B, then A² ≡ ±2 (mod 5), which is impossible. -/
lemma sum_range_two_mul {M : Type*} [AddCommMonoid M] (n : ℕ) (f : ℕ → M) :
∑ i ∈ range (2 * n), f i = ∑ i ∈ range n, (f (2 * i) + f (2 * i + 1)) := by
induction n with
| zero => simp
| succ n ih =>
rw [show 2 * (n + 1) = 2 * n + 1 + 1 by ring, sum_range_succ, sum_range_succ,
sum_range_succ, ih, add_assoc]
lemma im_sum {ι : Type*} (s : Finset ι) (f : ι → ℤ√8) :
(∑ i ∈ s, f i).im = ∑ i ∈ s, (f i).im := by
induction s using Finset.cons_induction with
| empty => rfl
| cons a s ha ih => rw [sum_cons, sum_cons, Zsqrtd.im_add, ih]
lemma sqrtd_pow_two_mul (k : ℕ) :
(Zsqrtd.sqrtd : ℤ√8) ^ (2 * k) = ((8 ^ k : ℤ) : ℤ√8) := by
induction k with
| zero => simp
| succ k ih =>
rw [show 2 * (k + 1) = 2 * k + 1 + 1 by ring, pow_succ, pow_succ, ih,
mul_assoc, Zsqrtd.dmuld]
push_cast
ring
/-- The binomial sum is the coefficient of √8 in (√8 + 1)^(2n+1). -/
lemma im_pow (n : ℕ) :
((Zsqrtd.sqrtd + 1 : ℤ√8) ^ (2 * n + 1)).im =
∑ k ∈ range (n + 1), ((2 * n + 1).choose (2 * k + 1) : ℤ) * 8 ^ k := by
rw [add_pow, im_sum, show 2 * n + 1 + 1 = 2 * (n + 1) by ring,
sum_range_two_mul]
refine sum_congr rfl fun k _ ↦ ?_
rw [pow_succ Zsqrtd.sqrtd (2 * k), sqrtd_pow_two_mul]
simp only [one_pow, mul_one, Zsqrtd.im_mul, Zsqrtd.re_mul, Zsqrtd.re_intCast,
Zsqrtd.im_intCast, Zsqrtd.re_natCast, Zsqrtd.im_natCast, Zsqrtd.re_sqrtd,
Zsqrtd.im_sqrtd, mul_zero, zero_mul, add_zero, zero_add]
ring
lemma norm_pow (m : ℕ) :
((Zsqrtd.sqrtd + 1 : ℤ√8) ^ m).norm = (-7) ^ m := by
have h1 : (Zsqrtd.sqrtd + 1 : ℤ√8).norm = -7 := by
norm_num [Zsqrtd.norm_def]
calc ((Zsqrtd.sqrtd + 1 : ℤ√8) ^ m).norm
= Zsqrtd.normMonoidHom ((Zsqrtd.sqrtd + 1 : ℤ√8) ^ m) := rfl
_ = ((Zsqrtd.sqrtd + 1 : ℤ√8).norm : ℤ) ^ m := by rw [map_pow]; rfl
_ = (-7) ^ m := by rw [h1]
theorem imo1974_p3
(n : ℕ) :
¬ 5 ∣ ∑ k ∈ Finset.range (n + 1),
(Nat.choose (2 * n + 1) (2 * k + 1)) * (2^(3 * k)) := by
intro hdvd
set S : ℕ := ∑ k ∈ Finset.range (n + 1),
(Nat.choose (2 * n + 1) (2 * k + 1)) * (2 ^ (3 * k)) with hS
-- S is the coefficient of √8 in (√8 + 1)^(2n+1)
have him : ((Zsqrtd.sqrtd + 1 : ℤ√8) ^ (2 * n + 1)).im = (S : ℤ) := by
rw [im_pow, hS]
push_cast
refine Finset.sum_congr rfl fun k _ ↦ ?_
rw [pow_mul]
norm_num
-- the norm equation: A² - 8 S² = (-7)^(2n+1)
have hnorm := norm_pow (2 * n + 1)
rw [Zsqrtd.norm_def, him] at hnorm
-- reduce mod 5, where S vanishes
have h5 : (S : ZMod 5) = 0 := (ZMod.natCast_eq_zero_iff _ _).mpr hdvd
apply_fun (fun t : ℤ ↦ (t : ZMod 5)) at hnorm
push_cast at hnorm
rw [h5] at hnorm
-- so A² = (-7)^(2n+1) = (-1)ⁿ * (-7) in ZMod 5, which has no solution
obtain ⟨x, hx⟩ : ∃ x : ZMod 5, x * x - 8 * 0 * 0 = (-7) ^ (2 * n + 1) :=
⟨_, hnorm⟩
rw [pow_succ, pow_mul, show ((-7 : ZMod 5)) ^ 2 = -1 by decide] at hx
obtain h | h := neg_one_pow_eq_or (ZMod 5) n <;> rw [h] at hx <;>
revert hx x <;> decide
end Imo1974P3
人的思考A human's take
Compfiles: Imo1974P3 — Roozbeh Yousefzadeh's verified Lean proof — Roozbeh Yousefzadeh (Compfiles project)
这是 Compfiles 项目(David Renshaw 维护,Apache 2.0)里的已验证证明,由 Roozbeh Yousefzadeh 撰写,使用 Mathlib 的 ℤ√8 环。证明的核心思路:把二项式求和识别为 $(1+\sqrt{8})^{2n+1}$ 的虚部,利用范数乘法性建立 $A^2 - 8S^2 = (-7)^{2n+1}$ 的恒等式,然后在模 5 下把假设 $5\mid S$ 归约成 $A^2 \equiv \pm 2 \pmod{5}$ 这个无解的二次剩余方程,矛盾。This is the verified proof in the Compfiles project (maintained by David Renshaw, Apache 2.0), written by Roozbeh Yousefzadeh using Mathlib's ℤ√8 ring. The core idea: identify the binomial sum as the imaginary part of $(1+\sqrt{8})^{2n+1}$, use norm multiplicativity to obtain the identity $A^2 - 8S^2 = (-7)^{2n+1}$, then reduce the assumption $5 \mid S$ modulo 5 to the unsolvable quadratic-residue equation $A^2 \equiv \pm 2 \pmod{5}$, a contradiction.
Lean 里的实现用 Zsqrtd.norm 给出范数公式,用 ZMod.natCast_eq_zero_iff 把整除性翻译成 ZMod 5 的零,最后用 decide 判读 $A^2 \equiv 2$ 和 $A^2 \equiv 3$ 两个 case 都无解。整个证明没有用高级代数几何,是经典的初等数论方法。The Lean implementation uses Zsqrtd.norm for the norm formula, ZMod.natCast_eq_zero_iff to convert divisibility into ZMod 5 being zero, and finally `decide` to check that neither $A^2 \equiv 2$ nor $A^2 \equiv 3$ has a solution mod 5. The whole proof uses no advanced algebraic geometry — it is the classic elementary number theory approach.
AI 随想An AI's reflection
以下由 AI 撰写。Written by AI.
这道题最让人惊讶的地方,是它的证法里藏了一个不显眼的选择:为什么选 $\mathbb{Z}\sqrt{8}$ 而不是 $\mathbb{Z}\sqrt{5}$ 或 $\mathbb{Z}\sqrt{3}$?答案是只有 $\sqrt{8}$ 的范数给出 $-7$,$-7$ 在模 5 下有一个特殊的性质:$(-7)^2 \equiv -1$,这正好把幂的奇偶性变成了 $\pm 2$,而 2 在模 5 里恰好是非平方。换成 $\sqrt{5}$,范数给出 $-4$,$(-4)^2 = 16 \equiv 1 \pmod{5}$,幂的奇偶性消失,矛盾不成立。所以选扩张环不是随意的,而是被『模 5 下范数的平方等于 -1』这一条件完全决定的。这背后是 Gauss 整理论里的一种标准套路:找一个代数整数,让它的范数在目标模数下有某种特殊的二次剩余性质。What's most surprising about this problem is an inconspicuous choice hidden in the proof: why the ring $\mathbb{Z}\sqrt{8}$ and not $\mathbb{Z}\sqrt{5}$ or $\mathbb{Z}\sqrt{3}$? The answer is that only $\sqrt{8}$'s norm gives $-7$, and $-7$ has a special property mod 5: $(-7)^2 \equiv -1$, which turns the parity of the power into $\pm 2$, and 2 happens to be a non-residue mod 5. Switch to $\sqrt{5}$, the norm gives $-4$, $(-4)^2 = 16 \equiv 1 \pmod{5}$, the parity information is lost, and the contradiction fails. So choosing the extension ring is not arbitrary — it is fully determined by the condition that the norm's square is $-1$ mod 5. This is a standard trick from the theory of Gaussian integers: find an algebraic integer whose norm has a special quadratic-residue property at the target modulus.
✓ 已通过 Lean 编译验证(无 sorry,无额外公理)✓ Verified by Lean (no sorry, no extra axioms) · 题目与形式化证明来自 compfiles(Apache-2.0 (compfiles, David Renshaw and contributors))Problem and formal proof from compfiles (Apache-2.0 (compfiles, David Renshaw and contributors)) · Lean v4.36.0-rc1 · Mathlib d875a8d
- Z3 脚本小集:把验证问题写成一个脚本跑Some Silly Z3 Scripts I Wrote
- Hillel 把几个实际编程问题(区间重叠、排班约束、正则匹配的形式化)写成 Z3 脚本,发现很多他以为需要自己写搜索代码的问题,其实一行 SMT-LIB 声明就能让 Z3 处理。Hillel wrote several real programming problems (interval overlap, scheduling constraints, formalized regex matching) as Z3 scripts, and found that many problems he assumed required hand-written search code can actually be handled by a single SMT-LIB declaration.
- 他的核心观察:Z3 的输入语言(SMT-LIB)虽然丑,但表达能力远超一般程序员以为的——任何带约束的组合优化问题,只要你能把约束写成量化的布尔表达式,就能交给 Z3 判定。His core observation: Z3's input language (SMT-LIB) is ugly, but its expressive power exceeds what most programmers assume - any constrained combinatorial optimization problem, as long as you can write the constraints as quantified Boolean expressions, can be handed to Z3 for decision.
- 实践价值:下次你写一个暴力搜索前,先停下来问『我能不能把这个问题写成约束、丢给 SMT 求解器』——对很多组合问题,答案是可以的,而且更快。Practical value: next time you are about to write a brute-force search, pause and ask whether you can formulate the problem as constraints and let an SMT solver handle it. For many combinatorial problems the answer is yes, and it is faster.
- 为什么用 ECC 内存?Why Use ECC Memory?
- Luu 逐条反驳 Jeff Atwood『ECC 没用』的论证。最关键的点:ECC 的核心价值不是『纠正错误』,而是『在静默损坏发生之前让你知道』。你可以接受单条结果偶发出错,但拒绝拦截单 bit 错误等于让『一条坏数据污染整条流水线』成为可能——这个在文件系统研究里已被反复证明极难做到。Luu rebuts Jeff Atwood's ECC-is-useless argument point by point. The key point: ECC's core value is not correcting errors but telling you before silent corruption happens. You may tolerate occasional single-result errors, but not intercepting single-bit errors means one bad record can contaminate the whole pipeline - repeatedly demonstrated to be extremely hard to prevent in filesystems.
- 他把 70% 硬错误/30% 软错误的数据翻译成实际运维场景:硬错误随时间缓慢出现,memtest 在机器运行中无法捕获,但 ECC 可以在运行时持续拦截,并触发换硬件。He translates the 70% hard / 30% soft DRAM error data into real operations: hard errors appear slowly over time; memtest cannot catch them while the machine is running; but ECC intercepts continuously at runtime and triggers hardware replacement.
- 推论:如果你的系统处理的是『不可恢复的批处理』(金融对账、基因数据管线),ECC 不是『昂贵选项』,是『保险』。Corollary: if your system handles irrecoverable batch work (financial reconciliation, genomics data pipelines), ECC is not an expensive option - it is insurance.
- 代数基本定理:用 Picard 小定理的一个证明The Fundamental Theorem of Algebra: A Proof via Picard's Little Theorem
- Picard 小定理:任意整函数(全平面复可微)如果值域省略了两个不同的点,它必然是常数。这是复分析里一个非平凡的重器。Picard's Little Theorem: any entire function (everywhere complex-differentiable on C) whose range omits two distinct points must be constant. This is a heavyweight result from complex analysis.
- 假设多项式 p(z) 没有零点。先证它也省略了某个 1/k:若 p 取到所有 1/k 的值,取这些 preimage 点 z_k,因为 p 在大 |z| 处无界,所有 z_k 被关在某个闭圆盘里;闭圆盘紧致 + 序列收敛 + 连续性 → 极限点 z 处 p(z)=0,矛盾。Assume the polynomial p(z) has no zeros. First show it also omits some 1/k: if p attained every 1/k, take the preimage points z_k. Since p is unbounded for large |z|, all z_k lie inside a closed disk; compactness + sequence convergence + continuity gives a limit point z where p(z)=0, a contradiction.
- 所以 p 的值域省略了 0 和某个 1/k 两个点。由 Picard 小定理,p 必须是常数,与非平凡多项式假设矛盾。So p's range omits two points: 0 and some 1/k. By Picard's Little Theorem, p must be constant, contradicting the assumption that p is a non-constant polynomial.
程序员随想Programmer Musings
- 拿我的 toil 走,留下我的 struggleTake My Toil, Leave Me My Struggle
- Beck 区分两种苦:toil(重复性的、机械性的劳动——格式化、跑测试、部署)和 struggle(思考性的、不确定性的劳动——判断该写什么、如何设计)。AI 工具消除的是 toil,但它不应该消灭 struggle。Beck distinguishes two kinds of suffering: toil (repetitive, mechanical labor — formatting, running tests, deployment) and struggle (thinking, uncertain labor — deciding what to write, how to design). AI tools eliminate toil; they should not eliminate struggle.
- 他的立场:如果一个工具让你连 struggle 都不必做了,你就不再是一个工程师,你只是一个按钮。工程师的核心价值不是『把需求翻译成代码』,而是『在不确定里做正确的决策』。His position: if a tool frees you from struggle as well, you are no longer an engineer — you are a button. An engineer's core value is not 'translating requirements into code' but 'making the right decisions under uncertainty.'
- 实践推论:使用 AI 工具时,刻意保留自己读代码、思考架构的时间,不要让工具把你变成『审批 AI 输出的橡皮图章』。Practical corollary: when using AI tools, deliberately preserve your time for reading code and thinking about architecture; don't let the tool turn you into a rubber stamp approving AI output.
- 奇怪的语言:Paul Graham 谈编程语言作为思维工具Weird Languages: Paul Graham on Programming Languages as Thinking Tools
- Graham 的核心论点:你用什么语言,决定了你能自然地思考什么。函数式语言让你自然地按『变换』思考,命令式语言让你按『状态变化』思考。Graham's central argument: the language you use determines what you can naturally think about. Functional languages let you think naturally in terms of 'transformations'; imperative languages in terms of 'state change.'
- 他用 Common Lisp 和 Python 做例子:同一个问题,在 Lisp 里写出来比 Python 里更短、更清晰,不是因为 Lisp 表达能力更强,而是 Lisp 的语法逼你按一种不同的分解方式思考。He uses Common Lisp and Python as examples: the same problem, written in Lisp, is shorter and clearer than in Python — not because Lisp is more expressive, but because Lisp's syntax forces a different decomposition style.
- 结论:学一个新语言最大的收获不是『会了另一个工具』,而是『获得了一种新的分解问题的视角』。Conclusion: the biggest gain from learning a new language is not 'a new tool in your kit' but 'a new way of decomposing problems.'
- LLM 语音:Martin Fowler 说 LLM 输出需要有自己的『声音』LLM Voice: Martin Fowler on Giving LLM Output Its Own 'Voice'
- Fowler 的观察:LLM 生成的代码有一种可辨认的『声音』——命名规范、注释风格、控制流习惯——跟人类开发者不同。这个声音不是 bug,是 feature。Fowler's observation: LLM-generated code has a recognizable 'voice' — naming conventions, comment style, control-flow habits — different from human developers. This voice is not a bug; it is a feature.
- 他建议:在团队里,允许并鼓励 LLM 代码保持它自己的风格,不要强制人类开发者的命名规范覆盖它。原因是:当 LLM 代码和人类代码风格一致时,review 的难度上升(你分不清哪部分是工具写的),而风格差异本身就是一种有用的信息。He recommends: in a team, allow and encourage LLM code to keep its own style; don't force your team's naming conventions to overwrite it. Reason: when LLM and human code look the same, review difficulty increases (you can't tell which part the tool wrote); style differences are themselves useful information.
- 实践推论:下一次 code review,看到明显是 AI 写的代码块,把『风格一致性』从 checklist 里拿掉,把注意力放在逻辑正确性上。Practical corollary: next code review, when you see clearly AI-written blocks, remove 'style consistency' from your checklist and focus on logical correctness.
- 随机化 HN:一个简单但深刻的反信息茧房技巧Randomize HN: A Simple but Deep Anti-Echo-Chamber Trick
- Luu 的做法:每天打开 HN,不用默认排序,而是按时间戳的某个偏移量(比如今天的第 137 篇)开始读。随机起点打破了『总看到最热帖』的茧房效应。Luu's approach: open HN daily, skip the default sort, and start reading at a time-stamped offset (say the 137th post of the day). The random start breaks the echo-chamber effect of always seeing the 'hottest' posts.
- 他的观察:默认排序不是『热门』,是『算法认为你喜欢的』。随机化把选择权还给你——你不知道下一篇是什么,你的注意力就回到了内容本身,而不是排序位置。His observation: the default sort isn't 'popular' - it's 'what the algorithm thinks you like.' Randomization hands the choice back to you: you don't know what's next, so your attention returns to the content itself, not the sort position.
- 这个技巧的本质:信息茧房的根源不是过滤算法,而是『确定性』——只要你每天从同一个位置开始读,你就会逐渐只看到同一类内容。打破确定性本身比选哪个内容更重要。The essence: the root of the information cocoon is not the filtering algorithm but 'determinism' - if you always start reading from the same place, you gradually only see one kind of content. Breaking determinism matters more than choosing which content.
哲学与生活Philosophy & Life
- 你的安全港在哪里?What Is Your Refugium?
- Wilson 在 90 岁时写了一句话:『refugium 不是安全的地方,是不被外界评判的地方。』区别在于:安全港是物理上的避难所(一个房间、一个岛),refugium 是心理上的——你在任何地方都能进入它,但前提是你必须知道它在哪儿。Wilson, at 90, wrote: 'A refugium is not a safe place; it is a place free from external judgment.' The distinction: a safe harbor is a physical shelter (a room, an island); a refugium is psychological — you can enter it anywhere, provided you know where it is.
- Marginalian 用这句话做了一期『你今天的 refugium 是什么』的写作练习。答案是:一个你不需要向任何人解释、不需要任何背景知识就能进入的精神空间。对程序员来说,可能就是那个『不看 GitHub 通知、不查 Slack、只写代码』的下午。The Marginalian built a writing exercise around this: 'what is your refugium today?' The answer: a mental space you don't need to explain to anyone, that requires no background context to enter. For a programmer, it might be the afternoon you don't check GitHub notifications, don't look at Slack, and just write code.
- 核心洞察:refugium 的价值不在于你待多久,在于你知道它存在。大多数人不是没有 refugium,是没有意识到它存在——他们在疲惫时不知道往哪儿逃,所以无处可逃。Popova 引用的 Hannah Fries 原话很精准:refugium 的礼物是『时间』——它在小小的安全里托住一个新世界的承诺,借给生命它可能需要几百、几千、几万年才能找到的那个世界的全部岁月。Core insight: a refugium's value is not in how long you stay, but in knowing it exists. Most people don't lack a refugium; they don't know they have one — when exhausted, they don't know where to retreat to, so they have nowhere to retreat. Popova quotes Hannah Fries precisely: the gift of a refugium is 'time' — it holds, in its small cup of safety, the promise of a new world to come, lending life the centuries or millennia it may take to find that world.
- 最疯狂的一注:在所有人都押稳的时候押大冷The Wildest Bet Is the Winning Bet
- Popova 开篇用一首诗论证:我们从一块『宇宙打折区的、伤痕累累的岩石』诞生,长出了线粒体、音乐、蜂鸟翅膀比眼睛快一百倍的振翅速度——这一切不是因为它『必然』或『高概率』发生,而是宇宙押了最疯狂的赌注赢了。Popova opens with a poem: we emerged from 'a battered rock orbiting a star from the discount bin of the universe,' and it bloomed into mitochondria, music, hummingbird wings a hundred times faster than your eye — not because it was likely or necessary, but because the universe won the wildest bet.
- 她的结论:可能性永远包含且超出概率。『wildest bet』(最疯狂的一注)之所以是 winning bet,不是因为它的赔率高,而是因为你所珍视的一切,本来就诞生在概率之外。Her conclusion: the possible always includes and exceeds the probable. The 'wildest bet' is the winning bet not because of high odds, but because everything you treasure was born outside of probability.
- 对程序员的推论:你做的每个项目,最初看起来都像『宇宙打折区的』——别人觉得不成立、概率低、不值得。这个观察不是叫你盲目押大冷,而是提醒你:判断一个机会的价值时,别只用期望值,要问『这件事如果成,它是从概率的哪个尾巴里来的』。For programmers: every project you've started looked, at first, like something from 'the discount bin of the universe' — others said it wouldn't work, the probability was low, not worth it. This observation isn't telling you to blindly bet on long shots; it's a reminder: when judging an opportunity's value, don't use expected value alone — ask 'if this succeeds, which tail of the probability distribution did it come from?'
- 期望值:用概率思考决策的底层框架Expected Value: The Underlying Framework for Thinking About Decisions Probabilistically
- Farnam Street 把期望值描述成『强制把世界变成灰色的工具』——它逼你在做任何决定时都权衡概率和结果,而不是凭直觉。一旦掌握,你会知道什么时候该冒险、什么时候该放弃、什么时候该 All in。Farnam Street describes expected value as the tool that forces the world to turn grey - it forces you to weigh probability and outcome in every decision rather than relying on gut. Once mastered, you know when to take risks, when to quit, and when to go all in.
- 他用停车罚单做例子:如果被抓概率是 1/3,$5 停车费就比罚单划算;如果罚单 $100,被抓概率要高于 1/20 才值得停车费。这就是为什么罚款总显得『过分』——它们覆盖了没被抓到的人。He uses parking tickets as the example: if the probability of getting caught is 1/3, a $5 parking fee beats the fine; if the fine is $100, you need a catch probability above 1/20 for paying to be worthwhile. That is why fines always seem excessive - they account for the people who do not get caught.
- 对程序员的推论:你做的每个技术决策都是期望值计算,不只是成本/收益。『写测试的成本』对比『不写测试时线上故障的概率 × 故障的损失』,这个计算不需要精确数字,需要的是意识。For programmers: every technical decision is an expected-value calculation, not just cost/benefit. The cost of writing tests versus the probability of a production incident when you skip tests times the incident's loss - this calculation does not need precise numbers, it needs awareness.
- 数字极简主义:把每次技术接触变成一次有意识的选择Digital Minimalism: Make Every Touch With Technology a Deliberate Choice
- Buterin 的思想实验:把你每天接触的数字(价格、统计、排行榜、评分)全部删掉,只留描述性文字,生活会变成什么样?他的观察是:数字是压缩比极高的协议——但被压缩掉的正是『你的具体处境』。同一个『3/5 星』在不同行业、不同语境下含义完全不同,大脑却会自动把它当成可比较的绝对量。Buterin's thought experiment: strip out every number you encounter daily (prices, statistics, rankings, ratings) and keep only descriptive text — what happens to your experience of life? His observation: numbers are an extremely high-compression protocol, but what gets compressed away is precisely 'your specific situation.' The same '3/5 stars' means something completely different across industries and contexts, yet the brain automatically treats it as a comparable absolute quantity.
- 他的结论不是『别看数字』,而是把每次接触都变成一次有意识的选择:技术是否值得进入这个时刻、这件事本身。这和物理极简主义是同构的——房间越小,越清楚什么东西必须留下;数字也一样,删掉一层就看见下一层是否还在替你说话。His conclusion is not 'stop looking at numbers' but making every touch with technology a deliberate choice: is this technology worth entering this moment, this thing? It is isomorphic to physical minimalism — a smaller room makes it obvious which things must be kept; numbers work the same way, and peeling off a layer reveals whether the next one is still speaking for you.
- 实践建议:区分『你的数字』与『别人的数字』——你的收入、健康指标可以量化,但别人的评分不应该是你决策的锚。Practical advice: separate 'your numbers' from 'other people's numbers' — your income and health metrics can be quantified, but other people's ratings should not be the anchor of your decisions.
- 心流访谈:Steven Kotler 谈『挫败感在教你』Kotler on Flow: 'Frustration Is Teaching You'
- Kotler(《超越极限》作者、心流研究中心执行主任)把心流讲成可训练的东西:任务难度卡在『比当前能力略难』的区间,心流最容易来;太易无聊,太难焦虑。Kotler (author of 'Beyond Limits', exec director of the Flow Research Collective) frames flow as trainable: the task must sit just past your current ability — too easy is boredom, too hard is anxiety.
- 他最反直觉的一点:『挫败感在教你』——学新东西时卡壳的难受本身就是大脑在重塑神经通路,高手往往比新手更主动寻找让自己不舒服的任务,因为那才是长进最快的地方。His most counterintuitive point: 'frustration is teaching you.' Getting stuck while learning is your brain rewiring; experts deliberately hunt for uncomfortable tasks because that's where progress is fastest.
- 他还提到 ADHD 可能是心流优势(注意力缺陷反而逼出对高刺激任务的专注),以及被放弃多年的『爱好』其实是大脑里最值钱的回路——你小时候迷了五年的东西,比任何工作项目都更接近你的心流触发点。He also flags ADHD as a potential flow advantage (attention deficit forcing focus on high-stimulation tasks), and notes that an adult-abandoned childhood hobby is often your brain's most valuable circuit — the thing you loved for five years beats any work project as a flow trigger.
工具角Tools Corner
- Lasm:把 Lean 4 编译成 WebAssemblyLasm: Lean 4 to WebAssembly
- 一套 Lean 4 代码可以同时变成 Node 服务器、serverless 函数和浏览器应用(WASM)。One Lean 4 codebase compiles to a Node server, serverless function, and browser WASM app simultaneously.
- 旗舰示例:Conduit = RealWorld app + 117 个已在 Lean 里证明的定理,全部跑在 WASM 里。Flagship example: Conduit = the RealWorld app plus 117 theorems already proved in Lean, all running in WASM.
- npm 直接装,无需 elan 工具链。Install via npm; no elan toolchain required.
- us-tax-model:把 IRS 税表变成可引用、可机检的数据us-tax-model: IRS Tax Forms as Cited, Machine-Checkable Data
- 每条计算线引用 IRS 原文的哈希锚点;整个原子词表只有约 20 个操作;无 opaque 黑箱。Every computed line cites the IRS original via hash anchor; the entire atom vocabulary is only ~20 operations; no opaque black boxes.
- 构建期的 checker 保证输出与引用一致。A build-time checker ensures output consistency with citations.
- 作者自评:vibe-coded,但设计目标是『不信任作者也能验证』。Author self-assessment: vibe-coded, but the design goal is 'verifiable even without trusting the author.'
- dontallow:两个 Swift 文件自动拒绝 macOS 本地网络权限弹窗dontallow: Two Swift Files That Auto-Dismiss macOS Local Network Prompts
- 监听本地网络权限弹窗,自动点『拒绝』。两个 Swift 文件,零 CPU 占用,开机自启。Watches for the local-network permission prompt and auto-clicks 'Deny.' Two Swift files, zero CPU usage, auto-launches on boot.
- 附带诊断:Chromium 签名路径、版本化安装路径、弹窗错误归属的根源。Includes diagnostics: Chromium signing path, versioned install path, and the root cause of the misattributed prompt.
- 有 `pause` 命令可临时放行。A `pause` command temporarily allows the prompt through.
- BeautifulRust:三个 agent skill 把 Rust 代码 review 自动化BeautifulRust: Three Agent Skills that Automate Rust Code Review
- 三个 skill:rust-best-practices / rust-review / rust-port,加上现成 clippy 配置。Three skills: rust-best-practices / rust-review / rust-port, plus ready-made clippy configuration.
- 技能源自 5 份权威文档,在分歧处作者『选边并说明理由』。Skills derive from 5 authoritative documents; where they disagree, the author 'picks a side and explains why.'
- 所有例子在 stable Rust 上编译通过。All examples compile on stable Rust.
- aerial-tv:给国产电视(小米/TCL/创维)一个 tvOS 式桌面aerial-tv: A tvOS-style Desktop for Chinese TVs (Xiaomi/TCL/Skyworth)
- 无广告、无推荐流的 Android TV launcher;支持手机远程整理、HDMI 绑定、4K 航拍屏保。Ad-free, no-recommendation-flow Android TV launcher; supports phone remote management, HDMI binding, and 4K aerial photos as screensaver.
- 561 commits,中文文档详尽;不需 root,可完整还原出厂设置。561 commits, detailed Chinese docs; no root required, fully restorable to factory settings.
- 专为国产电视定制,兼容小米、TCL、创维等品牌。Customized for Chinese TV brands: Xiaomi, TCL, Skyworth.
- Sketch Stadium:让 agent 玩『你画我猜』,实时看画布Sketch Stadium: Let an Agent Play Pictionary While You Watch the Canvas Live
- 让 AI agent 实时玩『你画我猜』,浏览器里直播看它画布+计分。Let an AI agent play Pictionary in real time, streaming the canvas and score live in the browser.
- 核心价值:不是又一个『画一幅图』的工具,而是一个能观察到 agent 决策过程的窗口。The core value: this is not another 'draw a picture' tool - it is a window into watching an agent's decision process.
- 很轻量的点子,代码量小,但『agent 玩我画我猜』这个 framing 本身很有传播力。A very lightweight idea with small code footprint, but the 'agent plays Pictionary' framing itself has high viral potential.
- Slide by Side:用滑动窗格并排比较两个文本slidebyside: Compare Two Texts Side by Side with a Sliding Pane
- 把两段文本放进左右滑动窗格,拖住中间缝像滑动门一样同时看到两边。Place two texts in left/right sliding panes; drag the middle seam like a sliding door to see both sides simultaneously.
- 核心价值:『同一时刻聚焦同一行』——拖动中间缝时两边同步滚动,不会出现看左边时右边已经滚走了。The core value over side-by-side panes: both sides scroll in sync when you drag the middle seam, so the right side does not drift away while you are reading the left.
- 适合代码 review、文档对比、diff 检查等场景。Useful for code review, document comparison, and diff inspection.