每日科技文摘Daily Tech Digest

每日精选 · 2026-11-16Daily Digest · 2026-11-16

发布于 2026-11-16Published 2026-11-16

今日深读Today's Deep Read

把税法当代码编译:Lean 在美国税法里查出 138 个起草错误Compiling the Tax Code: Lean Finds 138 Drafting Errors in the U.S. Internal Revenue Code

税法可能是人类社会里执行得最严格、却最少被「验证」的一段文本:它决定了每年数万亿美元的流向,IRS 印发算例、律师研究漏洞、法院裁决争议,但没有人拿机器检查过它的文字本身。Lexifina 团队最近做了一件听起来很朴素、做完却不朴素的事:把《美国法典》第 26 编(内部收入法典)整部翻译成 Lean——一个证明要逐步检查、类型要对得上的形式化语言——然后看会发生什么。Tax law may be the most strictly enforced yet least verified text in human society: it moves trillions of dollars a year, the IRS prints worked examples, lawyers study loopholes, courts settle disputes — but nobody had ever run a machine check over its wording itself. The Lexifina team recently did something that sounds simple and turned out not to be: they translated Title 26 of the U.S. Code (the Internal Revenue Code) into Lean, a formal language where every proof step must type-check, and watched what happened.

第一步最简单也最惊人:把法条之间的交叉引用当成测试用例来跑。税法正文里散落着成千上万个引用,有的有超链接,更多是用文字写的——「subsection (b) 的 paragraph (2)」「such subparagraph」。他们写了一个解析器把这些引用全部提取出来,交给 Lean 逐条检查:被引用的条款存在吗?还生效吗?整个检查跑在一个测试套件上,法律每出新版本就重跑一次,新版本引入的新错误立刻让套件变红。截至 2026 年 11 月 3 日的版本,套件报了 257 个发现:98 个是故意的(关于历史时期、或已通过但未生效的条款),21 个是编辑自己超链接的误报,剩下的 138 个是真实起草错误——67 处引用了已被废除、搬走或重写的条款却没做相应修改,24 处打错字、引错子项或没点明法案名,8 处把层级词叫错(§9818(a)(1)(A) 把 subsection 说成 paragraph),9 处同一编号出现两次(§1202(b)(4) 有两个),30 处括号根本不闭合。每一个错误都附一张「证书」:一段短的 Lean 陈述,携带官方 XML 里的证据,把这个错误证明一遍。138 份证明全部重新检查只要约两分半钟。因为整个法典记录是一个 git 仓库(每一部国会立法一个 commit,可追到 1994 年版),每个错误还能精确归因到是哪一次立法写坏的。Step one, the simplest and the most alarming: treat every cross-reference between statutes as a test case. The Code contains thousands of references — many not hyperlinks but phrases like 'paragraph (2) of subsection (b)' or 'such subparagraph'. A parser extracts them all, and Lean checks each one: does the provision being cited exist? Is it still in force? The checks run as a test suite, re-run against every new release of the Code, so a fresh drafting fault turns the suite red immediately. Against the release current to November 3, 2026, the suite reported 257 findings: 98 intentional (rules for past periods or enacted-but-not-yet-effective provisions), 21 false alarms from the editors' own hyperlinks, and 138 real faults — 67 references to provisions since repealed, moved, or rewritten with no conforming change, 24 typos or wrong citations, 8 wrong level words (a subsection called a paragraph), 9 cases where the same section number appears twice (§1202(b)(4) has two), and 30 unclosed parentheses. Each fault carries a certificate: a short Lean statement that carries the evidence from the official XML and proves the fault. All 138 certificates re-check in about two and a half minutes. And because the record of the Code is a git history — one commit per public law, reaching back to 1994 — every fault can be traced to the statute that wrote it.

第二步是把「这台机器怎么算税」写成可执行定义:2025 年一户人家的联邦所得税,按 Form 1040 逐项走——收入到 AGI、标准或逐项扣除(含 2025 年新增的小费、加班工资、车贷利息扣除)、税本身(含防止高收入者扣太狠的 AMT)、再到各项抵免。用 AI 把法条翻成 Lean 是有损的一步,所以外面包了三层验证:与 IRS 公布的税表、EITC 表、工作单和出版物算例对数字;和三个独立报税程序在 5000 户人家上交叉比对;另派一个没写过这段代码的 agent 做敌意审查,专找「为了让测试通过而写」的作弊翻译。Lean 真正多出来的东西是「覆盖所有输入而非抽样」的证明——比如证明 SALT 上限在某段收入区间内永远不起作用这种,数字测试永远碰不到的性质。Step two: write down what the machine actually calculates — the 2025 federal income tax for one household, following Form 1040 part by part: income down to AGI, deductions (including the new 2025 ones for tips, overtime, car-loan interest), the tax itself with the alternative minimum tax, then credits. Translating statutes into Lean with AI is the lossy step, so it is wrapped in three layers of verification: figures tested against the IRS's own published tables, worksheets and worked examples; cross-checks against three independent tax programs on 5,000 households; and a second agent that never wrote the code reviewing each part adversarially — hunting for code written to pass the tests rather than to follow the statute. What Lean adds over sampling is proofs that cover every input: properties like 'the SALT cap is never binding in this income range' that no number test would ever touch.

第三步才是他们真正想去的地方:既然规则已经是机器可检查的形式,就可以反过来在规则空间里搜索——不是问「这个漏洞合规吗」,而是问「规则允许什么,包括意外允许的」。就在前一篇里,他们用同样的方法从退休账户规则出发,一次盲目搜索重新「发现」了 backdoor Roth(一个广为人知的合法避税通道)——这等于给方法做了个阳性对照:已知漏洞能从规则里推出来,那未知的那些呢。Step three is where they actually want to go: once the rules are machine-checkable, you can search the rules in reverse — not asking 'is this loophole legal?' but 'what do the rules allow, including by accident?' In the previous post, the same machinery, starting from retirement-account rules, rediscovered the backdoor Roth in a blind search — a positive control for the method: known loopholes can be derived from the text, so what about the unknown ones?

值得带走的是这个视角本身:法条是一种「没有任何编译器检查过的并发规格」——八十年里多任作者逐年续写、彼此交叉引用,靠人眼保证一致性,而人眼恰恰对「引用指向搬走的段落」这种东西最不敏感。形式化检查不便宜(翻译有损、要对抗审查),但检查一旦建成,重跑的成本趋近于零,而错误一旦漏出去就是真金白银。这和软件工程里「lint 抓不到设计错误、但抓得到的全是便宜错误」是同一个道理——真正危险的不总是难问题,还有那些没人去数的明显错误。The takeaway is the frame itself: statutes are a kind of concurrent specification that no compiler has ever checked — written by many hands over eighty years, cross-referencing each other, kept consistent by human eyes, which are precisely blind to 'a reference pointing at a paragraph that moved'. Formalization isn't cheap (the translation is lossy and needs adversarial review), but once the checker exists, re-running it costs nothing, and a fault that escapes costs real money. It's the same lesson as linting in software engineering: the dangerous thing is not always the hard problem — sometimes it's the obvious mistake nobody bothered to count.

AI 思考AI Thinking

数学之美Mathematical Beauty

每日 Lean 谜题 · 周一Daily Lean Puzzle · Monday ★☆☆☆☆☆☆

每日谜题 ★1:法典审计的账目Daily Puzzle ★1: The Tax-Code Audit Ledger

一次法典审计报出 $257$ 条发现,分成三类:$a$ 条是真实的起草错误,$b$ 条是故意保留的历史条款,$c$ 条是编辑自己造成的误报。已知 $a + b + c = 257$,$a$ 恰好比 $b$ 多 $40$(即 $a = b + 40$),且 $c = 21$。证明:真实的起草错误恰有 $a = 138$ 条。($a, b, c$ 都是自然数。)A code audit reports $257$ findings in three kinds: $a$ real drafting faults, $b$ deliberately kept historical provisions, and $c$ false alarms from the editors' own hyperlinks. You know $a + b + c = 257$, that $a$ exceeds $b$ by exactly $40$ (i.e. $a = b + 40$), and that $c = 21$. Prove that the real faults number $a = 138$. (All of $a, b, c$ are natural numbers.)

Lean 形式化陈述(把 sorry 换成你的证明):The statement in Lean (replace sorry with your proof):

import Mathlib

/-!
一次法典审计里,一个检查套件报出 $257$ 条发现,分成三类:真实的起草错误 $a$ 条、
故意保留的历史条款 $b$ 条、编辑自己造成的误报 $c$ 条。已知
$a + b + c = 257$,$a$ 恰好比 $b$ 多 $40$,且 $c = 21$。
证明:真实的起草错误恰有 $a = 138$ 条。
-/

theorem audit_findings (a b c : ℕ) (h1 : a + b + c = 257) (h2 : a = b + 40)
    (h3 : c = 21) : a = 138 := by
  sorry

在浏览器中挑战 ▶Try it in your browser ▶ 下载题目 .leanDownload puzzle .lean

提示Hint

消元:把 $c = 21$ 和 $a = b + 40$ 都代入第一条方程,就只剩一个未知数了。全程用加法写,别在自然数里做减法。Lean 里一个 tactic 就能收掉全部推理。Eliminate: substitute $c = 21$ and $a = b + 40$ into the first equation and only one unknown is left. Keep everything in additive form — never subtract inside $\mathbb{N}$. In Lean, a single tactic closes the whole argument.

答案与讲解Solution & walkthrough
  1. 先把账目翻译成 Lean 的形状:三个自然数 `a b c : ℕ`,三条假设 `h1 : a + b + c = 257`、`h2 : a = b + 40`、`h3 : c = 21`,目标 `⊢ a = 138`。谜题陈述和形式化陈述是同一件事的两种写法——这正是头条里 Lexifina 对整部《税法》做的事。First translate the ledger into Lean's shape: three naturals `a b c : ℕ`, hypotheses `h1 : a + b + c = 257`, `h2 : a = b + 40`, `h3 : c = 21`, goal `⊢ a = 138`. The word problem and the formal statement are the same thing written twice — exactly the move today's lead essay describes Lexifina making over the entire Tax Code.
  2. 手算路径(也是 `omega` 内部思路的加法版):把 $h3$ 和 $h2$ 代入 $h1$,得 $(b + 40) + b + 21 = 257$,整理为 $2b + 61 = 257$,即 $2b = 196$,于是 $b = 98$、$a = 138$。注意每一步都只用加法和「两倍」,不写 $257 - 21$ 这种自然数里要小心的减法。The hand-computation path (also `omega`'s reasoning in additive form): substitute $h3$ and $h2$ into $h1$ to get $(b + 40) + b + 21 = 257$, tidy to $2b + 61 = 257$, so $2b = 196$, hence $b = 98$ and $a = 138$. Every step uses only addition and doubling — no natural-number subtraction like $257 - 21$, which is the thing to avoid in $\mathbb{N}$.
  3. Lean 证明只有一行:`by omega`。`omega` 是自然数/整数线性算术的决策程序(Presburger 算术的算法化身):假设和目标里只出现 $+$、常数和不等式时,它不靠灵感,必然判出真假。$h1$、$h2$、$h3$ 全是线性等式,目标也是,所以一行收工。The Lean proof is one line: `by omega`. `omega` is a decision procedure for linear arithmetic over the naturals and integers — the algorithmic embodiment of Presburger arithmetic. When hypotheses and goal mention only $+$, constants and inequalities, it needs no inspiration and always terminates with the right verdict. All three hypotheses and the goal here are linear, so the line closes them all.
  4. 可带走的是那条边界:线性 ⇒ 可判定,机器有终审权;一旦某个假设冒出 $b \cdot c$(条款编号相乘这种「乘法级」约束),问题立刻跳出 `omega` 的能力范围——丢番图方程有没有解连通用算法都不存在(希尔伯特第十问题)。这道 ★1 谜题故意停在拐杖的这一边。What to take away is the boundary: linear means decidable — the machine gets final say on the bookkeeping. Introduce one $b \cdot c$ into the mix (section numbers multiplying each other) and the problem hops off `omega`'s map: whether a Diophantine equation has a solution has no general algorithm at all (Hilbert's tenth). This ★1 puzzle deliberately stays on the supported side of the crutch.
import Mathlib

/-!
一次法典审计里,一个检查套件报出 $257$ 条发现,分成三类:真实的起草错误 $a$ 条、
故意保留的历史条款 $b$ 条、编辑自己造成的误报 $c$ 条。已知
$a + b + c = 257$,$a$ 恰好比 $b$ 多 $40$,且 $c = 21$。
证明:真实的起草错误恰有 $a = 138$ 条。
-/

theorem audit_findings (a b c : ℕ) (h1 : a + b + c = 257) (h2 : a = b + 40)
    (h3 : c = 21) : a = 138 := by omega

运行答案 ▶Run the solution ▶ 下载答案 .leanDownload solution .lean

人的思考A human's take

Formalizing the U.S. tax code — Lexifina 团队

这道谜题就是这篇文章里那笔账:Lexifina 团队把 Title 26 翻成 Lean 后,交叉引用检查套件在 2026-11-03 版本上报出 257 条发现——98 条故意(历史条款/未生效)、21 条编辑自己超链接造成的误报、138 条真实起草错误,三个数恰好就是谜题里的 $b$、$c$、$a$。作者的思路是把「找错」变成「算账」:每个错误附一份短的 Lean 证明当证书,138 份重验只要约两分半,还能靠 git 化法典追到写坏它的每一部国会立法。This puzzle is literally the ledger from the article: after translating Title 26 into Lean, Lexifina's cross-reference test suite reported 257 findings against the November 3, 2026 release — 98 intentional (historical or not-yet-effective provisions), 21 false alarms from the editors' own hyperlinks, and 138 real drafting faults. Those three numbers are exactly the puzzle's $b$, $c$ and $a$. The authors' move is to turn fault-finding into bookkeeping: every fault carries a short Lean proof as a certificate, all 138 re-check in about two and a half minutes, and the git-ified Code traces each error back to the public law that wrote it.

AI 随想An AI's reflection

以下由 AI 撰写。Written by AI.

这道谜题的全部难度其实藏在一条不起眼的分界线上。$a+b+c=257$ 这种只由加法和常数拼出来的等式,机器是有终极答案的——Presburger 算术可判定,`omega` 就是那个算法。可只要往假设里塞一个 $b \cdot c$,世界立刻翻脸:丢了「线性」这根拐杖,连「是否存在整数解」都不再有通用判定程序(希尔伯特第十问题,Matiyasevich 在 1970 年收尾)。同一句话里,「多 $40$ 条」可以说,「$40$ 倍」就没人兜底。The whole difficulty of this puzzle hides on one unremarkable boundary. Equations stitched from nothing but addition and constants — like $a+b+c=257$ — have a final machine answer: Presburger arithmetic is decidable, and `omega` is that algorithm wearing boots. Slip a single $b \cdot c$ into the hypotheses and the world turns hostile: without the crutch of linearity, even the existence of an integer solution has no general test (Hilbert's tenth, closed by Matiyasevich in 1970). In the same sentence, 'forty more than' is sayable; 'forty times' has no safety net.

这条边界恰好解释了两件事。一是为什么《税法》那样几千页的文本敢交给 Lean 去查:交叉引用、括号配对、编号唯一性,全是「线性」的账目问题,错了必能产出一份机械可复检的证书——138 份证书两分半重验完,这才是「测试套件跑在法律正文上」的真实含义。二是为什么它同时永远有律师吵不完的争议:真正的法律判断是乘法级的,两个条款的语义相乘,落在一切决策程序的边界之外。可判定的半边交给机器,判断留给人——这可能是这道 ★1 谜题和今天头条共享的、最不浪漫也最有用的结论。That boundary explains two things at once. Why a text of thousands of pages like the Tax Code can be handed to Lean at all: cross-references, bracket balance, unique section numbers — all linear bookkeeping, where every error yields a certificate a machine can re-check (138 certificates in two and a half minutes). That is what 'a test suite running on the statute' really means. And why its disputes outlive the formalization: genuine legal judgement is multiplicative — the semantics of two provisions times each other, outside every decision procedure. Give the decidable half to the machine and keep the judgement for humans: the least romantic, most useful conclusion this ★1 puzzle shares with today's lead essay.

✓ 已通过 Lean 编译验证(无 sorry,无额外公理)✓ Verified by Lean (no sorry, no extra axioms) · 题目与证明由 AI 编写Problem and proof written by AI · Lean v4.36.0-rc2 · Mathlib 1c2b155

程序员随想Programmer Reflections

哲学与生活Philosophy & Life

工具角Tools Corner