进步被兑换成了产出,而不是时间Progress Was Cashed In as Output, Not as Time
发布于 2026-11-14Published 2026-11-14
今日深读Today's Deep Read
为什么我们还在工作这么拼命:工资同时干着两份互相打架的活Why Are We Still Working This Hard: A Wage Is Doing Two Clashing Jobs
先看一个几乎没人核对过的数字:按美国经济分析局(BEA)的投入产出表,1973 年四十小时才造出来的产出,今天约十六小时就能造出来——每个岗位已被机器替掉二十四小时。可四十小时一周纹丝未动,2024 年美国人均工时甚至比 1973 年还高百分之十。凯恩斯 1930 年预言的「十五小时工作制」,按小时产出算早就到来,只是没有落进日历。作者问:这五十年的进步,去哪了?Start with a number almost nobody checks: according to the US Bureau of Economic Analysis input-output tables, what took a full forty-hour week to produce in 1973 takes about sixteen hours today. Twenty-four hours per job have quietly been handed to the machines. Yet the forty-hour week written into American law in 1938 hasn't budged — in 2024 the US actually works about 10 percent more hours per head than in 1973. Keynes predicted in 1930 that his grandchildren would enjoy a fifteen-hour week; the usual verdict is that he was right about wealth and wrong about leisure. But measured by output per hour, the fifteen-hour week really did arrive — it just never landed in the calendar. The author asks: where did fifty years of progress go?
他的答案要从「工资是干什么用的」说起。工资同时身兼三职:它是一束价格,告诉企业一小时值多少、告诉人哪种活被需要;它是一张门票,你几乎只能通过出卖时间,才能分到社会生产的东西——面包到你手里不是按需要,而是因为你卖了工时换来了钱;它还是一个场所,给一天一个形状,给你一群人。两个世纪以来这三份活相安无事,因为工业时代的机器是「强壮而愚蠢的」:只能举、转、冲压,不能看、不能判断、不能决定。机器的主人不得不竞标人的时间——工资随生产率一起上涨,这价格铸成的门票,是一张好门票。His answer starts from a question about the wage itself: what is a wage for? A wage holds three jobs at once. It is a price, telling firms what an hour costs and telling people which work is wanted. It is a ticket: nearly everyone gets a share of what society produces only by selling hours — bread reaches you not because you need it but because you have money, and money because you sold time. And it is a place: it gives the day a shape, a set of people, a sign that someone needs you. For two centuries the three roles pulled in the same direction, because the machines of the industrial age were strong and stupid: they could lift, spin, stamp and haul, but not see, judge or decide. Nearly everything worth making needed both kinds of ability, so every new machine needed a person beside it, and machine owners had to bid for people's hours. Wages rose with productivity, and a ticket minted from that price was a good ticket.
今天造的机器能看、能读、能写、能判断。作者以写软件为生,说自己一年比一年难说出哪类工作「稳在它们够不着的地方」。于是价格与门票开始互相拉扯。先算那十八小时去哪了:付给美国人的钱里 66% 是劳动报酬、34% 归机器的所有者;最富的十分之一拿走全部财产收入的三分之二,而税收每一美元里 68 美分恰恰来自工资——其余九成家庭其实活在别人的工资上。Acemoglu 与 Restrepo 估计,四十年间工资结构变动的 50%–70% 来自被自动化行业常规工序工人的相对贬值:机器先学会了普通人的活。机器学会你那份工作的那天,你和昨天一样努力,但你的一小时不值钱了。作为价格这很正确;拿它决定谁配过上好日子,就很古怪。这是价格正在啃食门票。The machines being built now can see, read, write and judge. The author, who writes software for a living and uses them daily, says it gets harder each year to name work that is safely out of their reach. So price and ticket have been pulling each other apart. First, the eighteen hours: chase a dollar spent in a shop through America's national accounts, and of what is paid to Americans, 66 percent is pay for work and 34 percent goes to owners — of the oven, the truck, the building, the ground. The richest tenth takes two-thirds of all income from ownership, while 68 cents of every tax dollar is raised from wages, so nine households in ten live on each other's wages. Acemoglu and Restrepo estimate that 50–70 percent of the change in the US wage structure over four decades came from relative wage declines of workers doing routine tasks in rapidly automating industries — machines learned ordinary jobs before they touched the best-paid ones. The day a machine learns your job, you work exactly as hard as the day before, and your hour is worth less. That is how a price ought to behave; it is a strange way to decide who gets to live well. This is the price shrinking the ticket.
再算那六小时:普通工资确实涨了约五分之一,本可以换来六小时闲暇,工时反而更长了。作者的解释是信息论的:价格传递真实信息的前提是我可以说「不」。我付三美元买面包,面包师才得知面包对我至少值三美元,因为我本可以走掉;工资本该反向携带同样的信息,但这只在「我付得起拒绝的代价」时成立。如果卖时间是我唯一的活法,工资只记录了我多需要这笔钱,几乎不记录那一个小时本可以是什么——陪孩子的下午、看望母亲的一天;用作者的话说,它们「输掉了一场根本不许它们参赛的比试」。一方无法离场的拍卖,出价再高也测不出真实价值:因为无法拒绝,很多并不值得做的活被认真地做完了。Now the six hours: ordinary pay did rise by about a fifth — enough to buy six hours off the week — yet hours went up instead. The author's explanation is informational. A price carries true information only if I can say no. When I pay three dollars for bread, the baker learns the bread was worth at least that to me, because I could have walked away. The wage is supposed to carry the same message in reverse: taking fifteen dollars an hour should mean the hour was worth less than fifteen to me. But that only holds if refusing is affordable. If selling hours is the only way I eat, the wage records how badly I needed the money and almost nothing about what the hour would otherwise have been — an afternoon with my child, a visit to my mother. 'Those lost a contest they were never allowed to enter.' An auction where one side cannot walk away measures value very poorly. The ticket spoils the price in turn: because people can't refuse, work that isn't worth doing gets done earnestly.
这套框架还顺手解释了为什么人们恐惧本应是好消息的机器——怕的不是机器,是门票功能的塌缩。作者说这指向一个比他预想「更简单、更近」的出路,完整论证挂在他的 SSRN 论文里。带走物不是政策方案,而是一把拆问题的刀:下次看到四天工作制、全民基本收入、AI 税之争,先问一句——这条理由谈的是工资的价格、门票,还是场所?许多对立的立场,只是把三个职位当成了一个。The frame also explains the fear of machines that ought to be good news: what people fear is the collapse of the ticket function. The author says this points to a way out that is simpler and nearer than he expected — the full derivation and data sit in his SSRN paper, which he invites readers to try to break. The takeaway isn't a policy; it's a knife for carving problems. Next time you see a fight about four-day weeks, universal basic income or an AI tax, ask first: is this argument about the price of the wage, the ticket, or the place? Many opposing positions turn out to be three jobs mistaken for one.
AI 思考AI Thinking
- 模型自己会交代:从公开权重反推训练用的是哪款显卡The Weights Confess: Reading the Training GPU Out of Public Model Weights
- 问题:出口管制限制英伟达高端芯片对华出售,但没人查得到中国实验室机房里的实物。有没有办法不靠泄密、不靠线人,从外面验证?The setup: export controls limit sales of NVIDIA's top chips to China, but nobody inspects the labs' racks. Can an outsider verify anything without leaks or insiders?
- 关键想法:模型的初始权重像一枚指纹。同样的随机初始化在不同硬件上跑,由于浮点运算的细微顺序差异,会留下可辨认的数值模式;而不同显卡的流处理器(SM)数量不同——B200/B300 是 148 个核,GB200/GB300 是 152 个。The key idea: initial weights are a fingerprint. Running the same initialization on different hardware leaves recognizable numerical patterns because of tiny differences in floating-point reduction order — and chips differ in streaming-multiprocessor count (148 SMs for B200/B300, 152 for GB200/GB300).
- 方法:从公开发布的权重里恢复初始值痕迹,再搜索能复现这些数值模式「硬件×初始化」配置。作者对 DeepSeek-V4-Flash 和 Kimi K3 还在物理 Blackwell 机器上做了正向确认。The method: recover traces of the initial values from the published weights, then search hardware-and-initialization configurations that reproduce them. For DeepSeek-V4-Flash and Kimi K3 the author also confirmed the match on physical Blackwell machines.
- 结论克制:六个模型(DeepSeek、Moonshot、MiniMax、蚂蚁的 2026 年版本)读起来是 Blackwell 起步的,而同一批实验室较早的模型读出来是 Hopper。作者明说这只证明权重「是如何被造出来的」,不能证明芯片在哪、怎么到手、是否违反管制。A careful conclusion: six 2026-era models from DeepSeek, Moonshot AI, MiniMax and Ant Group read as Blackwell-started, while the same labs' earlier models read as Hopper. The author stresses this shows only how the weights were made — not where the chips sat, how they were obtained, or whether rules were broken.
- 能带走:AI 供应链审计有了新的取证面——发布权重本身就是文档。管制、开源合规、模型溯源这些讨论,从「信不信厂商公告」多了一条可复算的技术路径。The takeaway: AI supply-chain forensics gained a new surface. Published weights are themselves documentation, turning export-control and provenance debates from 'trust the vendor's word' into something you can recompute.
- AI 找漏洞不是拼算力的证明工作:上限是智力,不是采样次数AI Bug-Hunting Is Not Proof of Work: The Ceiling Is Intelligence, Not Sample Count
- 流行的类比:用大模型自动找漏洞等于「工作量证明」——穷举采样次数越多越可能中,于是算力多的一方最终获胜。Redis 作者 antirez(2026 年 4 月)说这个类比是错的。The popular analogy: letting LLMs hunt bugs is like proof-of-work — keep sampling and brute force eventually finds something, so whoever owns more compute wins. Redis creator antirez (April 2026) says the analogy is wrong.
- 理由:程序的状态空间是有限的。对同一段代码反复采样,不同执行会走不同分支,但「有意义的分支」终将饱和——上限不是次数 M,而是模型智力 I。弱模型跑无限个 token 也到不了那个状态。Why: a program's state space is finite. Repeated sampling explores different branches, but the meaningful ones saturate — the cap is not the number of tries M but the model's intelligence I. An inferior model will run infinite tokens and never reach the state where the bug is visible.
- 例证:OpenBSD SACK 漏洞要同时把「没校验窗口起点」「整数溢出」「node 不可能为 NULL 的分支照样进入」三件事连起来才成立。弱模型只会各自 pattern-match 这三个已知 bug 类别,从不理解组合为何致命,有时靠幻觉碰巧命中,被当成「找到了」。The example: the OpenBSD SACK bug required holding three facts together at once — the unvalidated window start, the integer overflow, and the branch that runs even though the node can't be NULL. Weaker models pattern-match each known bug class separately and never understand why the combination is fatal; occasionally hallucination lands near a real issue, and people call that a discovery.
- 有趣的推论:一个不够强的模型,越强反而越少报 bug——强一点的幻觉少,看不见「幻觉版」的洞;弱一点的乱喊;中间地带最吵。真正的理解只有顶尖模型才有。A neat corollary: among models too weak to truly understand, the stronger one reports bugs less often — small models hallucinate problems, strong-but-not-great models hallucinate less and see nothing, so the loudest claims come from the middle.
- 能带走:明天的网络安全竞赛不是「谁的 GPU 多」,而是「谁用得上更好的模型、并且先一步用上」。这也顺带给「随便什么模型跑一晚上就能扫出漏洞」的推销泼了冷水。The takeaway: tomorrow's cyber race is not who has more GPUs but who gets better models first. It's also cold water on the pitch that any model left running overnight will sweep out vulnerabilities.
- 七十年 AI 研究的苦涩一课:拼「人的知识」的路线,最后都输给吃算力的路线The Bitter Lesson: Seventy Years of AI Keep Choosing Knowledge Over Compute and Losing
- 主张(强化学习之父 Sutton,2019 年 3 月写的千字随笔):七十年 AI 研究最大的教训是——利用计算量的通用方法,最终总是大幅胜过利用人类领域知识的方法。原因直白:摩尔定律让单位算力的成本持续指数下降;而大多数研究默认「算力不变」,在这种默认下,往系统里塞人的知识几乎成了唯一的改进杠杆。The claim (a 1,000-word essay by reinforcement-learning pioneer Rich Sutton, March 2019): the biggest lesson of seventy years of AI research is that general methods that leverage computation ultimately beat methods that leverage human domain knowledge, and by a large margin. The reason is plain — compute cost per unit keeps falling exponentially — while most research proceeds as if compute were fixed, and under that assumption baking in human knowledge looks like the only lever left.
- 证据一·国际象棋:1997 年击败卡斯帕罗夫的 Deep Blue 靠的是大规模深层搜索。当时主流棋类研究者走「把人类棋理编进程序」的路,输了之后还不甘心地辩「蛮力搜索不普适、人不是这么下棋的」——Sutton 直说:他们不是好的输家。Evidence 1, chess: Deep Blue beat Kasparov in 1997 with massive, deep search. The mainstream of computer-chess research had been encoding human strategic understanding, and after losing they protested that 'brute force' wasn't general and wasn't how people play. Sutton's verdict: they were not good losers.
- 证据二·围棋晚了二十年重演同一课:先是大把人力用「棋形知识」绕开搜索,等搜索真正上规模、再配上自我对弈学价值函数,这些知识工程一夜作废。Sutton 把「搜索」和「学习」列为把海量计算用起来的两条通用通道——它们和人类知识的关系,就像推土机和手铲。Evidence 2, Go repeated the lesson twenty years late: enormous effort went into avoiding search with human knowledge of the game's structure, and all of it became irrelevant once search was applied at scale plus value functions learned by self-play. Sutton names search and learning as the two general channels for bringing massive compute to bear.
- 证据三·语音与视觉:1970 年代 DARPA 评测里,基于词素、声道知识的特殊方法输给了「更统计、更费计算」的 HMM,并由此重塑整个 NLP;深度学习语音是同一方向的下一步。计算机视觉同理——边缘、广义柱、SIFT 特征如今全部弃用,只剩卷积与不变性这类几乎不含「视觉知识」的机制,性能反而好得多。Evidence 3, speech and vision: in the 1970s DARPA evaluations, knowledge-based methods (phonemes, the vocal tract) lost to the more statistical, more computation-hungry HMMs — which reshaped all of NLP; deep-learning speech recognition was the next step in the same direction. Vision likewise: edges, generalized cylinders and SIFT features are all discarded today, leaving convolution and a few invariances — almost no 'vision knowledge' — and much better performance.
- 为什么「苦涩」+能带走什么:Sutton 总结四步历史规律——塞知识短期有效、让研究者自我感觉良好;长期必然见顶甚至挡住路;突破最终来自对立的「堆算力」路线;而胜利带着苦涩,因为它是战胜「以人为中心」的自己。结论:该内置的不是我们的发现,而是「能像我们一样去发现」的方法;我们以为思维是怎样的,就把怎样塞进机器,是最大的诱惑也是最大的浪费。在 LLM 靠规模吃下几乎所有赛道的 2026 年重读,这篇短文就是整个 scaling 时代的事先论证——也是对今天「给 agent 堆人工工作流知识」风潮的一盆冷水。Why 'bitter', and what to take away: Sutton's four-part historical pattern — human knowledge helps in the short term and feels satisfying; it plateaus and eventually blocks progress; the breakthrough comes from the opposing compute-scaling approach; and the win tastes bitter because it is a victory over the human-centered approach the field favored. Build in meta-methods that can discover, not our discoveries: 'agents that can discover like we can, not which contain what we have discovered.' Re-read from 2026, this short essay is the advance argument for the entire scaling era — and cold water on today's vogue of stuffing handcrafted workflow knowledge into agents.
- 「推理模型」不是新物种:它仍然是那台预测下一个词的机器'Reasoning Models' Are Not a New Species: Still the Next-Token Machine
- 背景(2025 年 2 月):曾断言「LLM 是死路、根本不可能推理」的人换了说法——「进步靠的是 o1/R1 这类推理模型,它们不是普通 LLM」。antirez 要拆的就是这个术语障眼法。The context (February 2025): people who declared 'LLMs are fundamentally flawed, they can never reason' retooled their line — 'the progress comes from reasoning models like o1 and R1, which are not just LLMs.' antirez sets out to expose the relabeling.
- 结构事实:DeepSeek R1 仍是纯 decoder-only 自回归模型,做的就是当年被痛斥的 next-token prediction,模型里任何地方都没有显式的符号推理或表征。Structural fact: DeepSeek R1 is still a pure decoder-only autoregressive model doing exactly the next-token prediction once denounced as hopeless; there is no explicit symbolic reasoning anywhere in it.
- 两个证据:R1-Zero 完全不做监督微调(SFT),只靠生成思维链+强化学习,就练出了接近 R1 的推理能力;S1 论文显示低至约 1000 个样本的 SFT 就足以让模型展开复杂推理步骤。Two pieces of evidence: R1-Zero reached R1-like reasoning with no supervised fine-tuning at all — just chain-of-thought generation plus reinforcement learning; and the S1 paper showed that as few as ~1,000 SFT examples suffice for a model to unfold complex reasoning steps.
- 推论:预训练早已把推理所需的表征学进权重里了;RL 和小量 SFT 教的不是「新知识」,而是「怎么把这些表征用出来」。所以不是「推理模型救了自己」,而是 LLM 本来就行。The inference: pre-training had already put the needed representations into the weights; RL and light SFT didn't teach new knowledge, they taught the model how to use what it had. So it was never 'reasoning models rescuing the LLM' — the LLM was enough.
- 能带走:读 AI 舆论时警惕「改名即翻案」——说错话不丢人,但为了站到历史正确一侧而改写术语史,是把读者当工具。判别办法很简单:问结构上多了什么模块;答案常常是「没多,只是训练目标变了」。The takeaway: watch for 'rename-as-reversal' in AI commentary. Being wrong is fine; rewriting terminology to land on the right side of history is not. The simple test: ask what module was actually added. Usually the answer is 'none — only the training objective changed.'
数学之美The Beauty of Math
每日 Lean 谜题 · 周六Daily Lean Puzzle · Saturday ★★★★★★☆
★6|USAMO 2012 第3题:无穷多条方程,两个素数,一次 Bézout★6 | USAMO 2012 Problem 3: Infinitely Many Equations, Two Primes, One Bézout
确定所有满足下列性质的整数 $n > 1$:存在一个由非零整数组成的无穷序列 $a_1, a_2, a_3, \ldots$,使得对每个正整数 $k$,都有 $a_k + 2a_{2k} + \cdots + n\,a_{nk} = 0$。Determine all integers $n > 1$ with the following property: there exists an infinite sequence $a_1, a_2, a_3, \ldots$ of nonzero integers such that $a_k + 2a_{2k} + \cdots + n\,a_{nk} = 0$ holds for every positive integer $k$.
「确定」意味着你不仅要构造,还要说明哪些 $n$ 不可能做到。在 Lean 题目文件里,答案集本身是要你自己定义的(`abbrev SolutionSet : Set ℕ := sorry`),然后证明「$n$ 属于答案集」与「这样的序列存在」互为充要——猜错答案集,第二问就证不动。'Determine' means you must both construct sequences and prove impossibility for the rest. In the Lean problem file you define the answer set yourself (`abbrev SolutionSet : Set ℕ := sorry`) and then prove the iff — guess the set wrong and the theorem won't budge.
Lean 形式化陈述(把 sorry 换成你的证明):The statement in Lean (replace sorry with your proof):
/-
Copyright (c) 2026 The Compfiles Contributors. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kimi K3
-/
import Mathlib.Algebra.Order.Ring.Star
import Mathlib.Algebra.Ring.IsFormallyReal
import Mathlib.Algebra.Order.Star.Int
import Mathlib.NumberTheory.Bertrand
import Mathlib.Tactic.NormNum.Prime
/-!
# USA Mathematical Olympiad 2012, Problem 3
Determine which integers n > 1 have the property that there exists an infinite
sequence a₁, a₂, a₃, ... of nonzero integers such that the equality
aₖ + 2a₂ₖ + ⋯ + naₙₖ = 0
holds for every positive integer k.
-/
namespace Usa2012P3
namespace factorization
open Nat
end factorization
abbrev SolutionSet : Set ℕ := sorry
theorem usa2012_p3 (n : ℕ) (hn : 1 < n) :
n ∈ SolutionSet ↔ ∃ a : ℕ → ℤ, (∀ i, 1 ≤ i → a i ≠ 0) ∧
∀ k, 1 ≤ k → ∑ j ∈ Finset.Icc 1 n, (j : ℤ) * a (j * k) = 0 := by
sorry
在浏览器中挑战 ▶Try it in your browser ▶ 下载题目 .leanDownload puzzle .lean
提示Hint
先在 $n=2$ 上做点小实验:只沿 $1, 2, 4, 8, \ldots$ 这条子列看方程会逼出什么。构造那一侧,不妨要求序列完全乘性($a_{jk}=a_j a_k$)——这一步会把无穷多个方程压缩成只有一个。First play with $n=2$: look at the equations only along the subsequence $1, 2, 4, 8, \ldots$ and see what they force. On the construction side, you may demand complete multiplicativity ($a_{jk} = a_j a_k$) — that collapses infinitely many equations into a single one.
答案与讲解Solution & walkthrough
- 答案:所有 $n \ge 3$。Lean 证明(solution.lean)先立下 `SolutionSet := { n | 2 < n }`,然后分两个方向。先把不可能的那一个钉死:$n=2$ 时方程是 $a_k + 2a_{2k} = 0$。取 $k = 1, 2, 4, \ldots, 2^{j-1}$ 一路迭代,得 `key : a 1 = (-2)^j * a (2^j)`——即 $2^j$ 整除 $a_1$ 对一切 $j$ 成立。非零整数不可能被 2 的任意高次幂整除(Lean 用 `Nat.lt_two_pow_self`,$|a_1| < 2^{|a_1|}$,取 $j = |a_1|$ 即矛盾)。这一步对应 lemma `not_property_two`。The answer: all $n \ge 3$. The Lean proof (solution.lean) starts by declaring `SolutionSet := { n | 2 < n }` and splits into two directions. First, the impossibility: for $n=2$ the relation is $a_k + 2a_{2k} = 0$. Iterating along $k = 1, 2, 4, \ldots, 2^{j-1}$ gives `key : a 1 = (-2)^j * a (2^j)` — so $2^j$ divides $a_1$ for every $j$. A nonzero integer cannot be divisible by arbitrarily high powers of 2 (Lean uses `Nat.lt_two_pow_self`: $|a_1| < 2^{|a_1|}$, contradicting divisibility at $j = |a_1|$). This is lemma `not_property_two`.
- 构造的主杠杆:把序列做成「完全乘性」的——$a_m$ 由它在素数上的取值决定,$a_m = \prod_r c(r)^{v_r(m)}$(Lean 的 `mulSeq P c`,$v_r$ 是 $r$ 在 $m$ 中的指数)。这样 $a(jk) = a(j)\,a(k)$,于是对任何 $k$,$\sum_j j\,a(jk) = a(k)\sum_j j\,a_j$:无穷多条方程全部是 $k=1$ 那一条的倍数,只要 $\sum_{j=1}^n j\,a_j = 0$ 一条成立就全都成立。这对应 lemma `condition_of_sum_eq_zero`——整个证明里最省力气的一步,也是「用对称性消元」的教科书演示。The master lever for construction: make the sequence completely multiplicative — $a_m = \prod_r c(r)^{v_r(m)}$ is determined by its values on primes (Lean's `mulSeq P c`, where $v_r$ is the exponent of $r$ in $m$). Then $a(jk) = a(j)\,a(k)$, so for any $k$, $\sum_j j\,a(jk) = a(k)\sum_j j\,a_j$: all infinitely many equations are scalar multiples of the $k=1$ one, and it suffices that $\sum_{j=1}^n j\,a_j = 0$. That's lemma `condition_of_sum_eq_zero` — the cheapest step in the proof and a textbook demo of killing variables with symmetry.
- $n \ge 9$ 时的棋子:Bertrand 公设($m>1$ 时 $(m, 2m]$ 内有素数,Lean 的 `Nat.exists_prime_lt_and_le_two_mul`)用两次——先取素数 $q$ 使 $\lceil n/2 \rceil \le q \le n+1$ 并可推出 $q \le n$、$n < 2q$;再取素数 $p$ 使 $\frac{q-1}{2} < p \le q-1$,于是 $p < q \le 2p$、$n < 4p$。素数的作用是把「动过手脚的位置」隔离开:除了 $p, q$ 以外的所有素数(注意包括 2 和 3!)一律令 $a_r = 1$,那么在 $1 \le j \le n$ 中只有 $j \in \{p, 2p, 3p, q\}$ 四个位置可能让 $a_j \ne 1$——$4p > n$ 挡住了 $4p$,$2q > n$ 挡住了 $2q$,而 $a_{2p} = a_{2}a_p = a_p$、$a_{3p} = a_{3}a_p = a_p$ 恰是因为 2、3 被设成了 1。这对应 `term_eq_zero` 与 `sum_mulSeq_cfun_sub_one`。Choosing the pieces for $n \ge 9$: Bertrand's postulate (a prime in $(m, 2m]$ for $m>1$; Lean's `Nat.exists_prime_lt_and_le_two_mul`) is used twice — first for a prime $q$ with $\lceil n/2 \rceil \le q \le n+1$, yielding $q \le n$ and $n < 2q$; then for a prime $p$ with $\frac{q-1}{2} < p \le q-1$, giving $p < q \le 2p$ and $n < 4p$. Primes isolate the tampered positions: set $a_r = 1$ for every prime $r \notin \{p, q\}$ — note this includes 2 and 3! Then among $1 \le j \le n$ only $j \in \{p, 2p, 3p, q\}$ can have $a_j \ne 1$: $4p > n$ blocks $4p$, $2q > n$ blocks $2q$, and $a_{2p} = a_2 a_p = a_p$, $a_{3p} = a_3 a_p = a_p$ precisely because 2 and 3 were set to 1. Lemmas `term_eq_zero` and `sum_mulSeq_cfun_sub_one` do this bookkeeping.
- 现在方程只剩两个未知数 $x = a_p$、$y = a_q$。记 $S = 1 + 2 + \cdots + n = n(n+1)/2$,把 $\sum_j j\,a_j = 0$ 按「哪些倍数落在 $[1,n]$ 里」分成三种情形:$3p \le n$ 时修正项是 $p + 2p + 3p = 6p$,方程为 $6p\,x + q\,y = 6p + q - S$;$2p \le n < 3p$ 时为 $3p\,x + q\,y = 3p + q - S$;$n < 2p$ 时为 $p\,x + q\,y = p + q - S$。三种情形各自的系数 $m \in \{6p, 3p, p\}$ 都与 $q$ 互素($q$ 是大于 $p \ge 5$ 的奇素数,除不掉 $6p$),Bézout 保证整数解存在。Now the equation has two unknowns $x = a_p$, $y = a_q$. Let $S = n(n+1)/2$; expanding $\sum_j j\,a_j = 0$ by which multiples land in $[1,n]$ gives three cases: if $3p \le n$ the correction is $p + 2p + 3p = 6p$ and $6p\,x + q\,y = 6p + q - S$; if $2p \le n < 3p$ it is $3p\,x + q\,y = 3p + q - S$; if $n < 2p$ it is $p\,x + q\,y = p + q - S$. In each case the coefficient $m \in \{6p, 3p, p\}$ is coprime to $q$ (an odd prime $> p \ge 5$, so it divides none of 6 or $p$), and Bézout guarantees integer solutions.
- Bézout 解还得「非零」——$a_p, a_q$ 不许取 0。Lean 的 lemma `bezout_nonzero` 把这件事做成了机械动作:拿到一组特解 $(uc, vc)$ 后,沿齐次方向平移 $(x, y) = (uc + Bt,\; vc - At)$,其中 $t = |uc| + |vc| + 1$。因为 $A, B > 0$ 且平移一步跨过零,新解一正一负、双双非零,一行 `lia` 收尾。主证明在 `exists_good_seq_of_nine_le` 里按 $2p, 3p$ 是否入区间挑好 $m$($p$、$3p$ 或 $6p$),调用它,再交回 `condition_of_sum_eq_zero`。But the Bézout solution must be nonzero — $a_p, a_q$ may not vanish. Lean's lemma `bezout_nonzero` mechanizes this: from any particular solution $(uc, vc)$, slide along the homogeneous direction, $(x, y) = (uc + Bt,\; vc - At)$ with $t = |uc| + |vc| + 1$; since $A, B > 0$, the shifted pair is nonzero in both coordinates (one positive, one negative), closed by one line of `lia`. The main lemma `exists_good_seq_of_nine_le` picks $m$ per case ($p$, $3p$ or $6p$), invokes Bézout, and hands the result back to `condition_of_sum_eq_zero`.
- 小情形 $3 \le n \le 8$ 不硬撑理论,直接给六个完全乘性序列(Lean 里逐个 `interval_cases n` 后 `decide`+`simp` 验算):$n=3$:$a_m = (-1)^{v_3(m)}$;$n=4$:$a_m = (-1)^{v_2(m)+v_3(m)}$;$n=5$:$a_m = (-2)^{v_5(m)}$;$n=6$:$a_m = 5^{v_2(m)}3^{v_3(m)}(-42)^{v_5(m)}$;$n=7$:$a_m = (-3)^{v_7(m)}$;$n=8$:$a_m = (-2)^{v_5(m)+v_7(m)}$。验算 $n=8$ 这条:$1+2+3+4-10+6-14+8 = 0$ ✓。有趣的是 $n=8$ 其实是 Bertrand 构造以 $(p,q)=(5,7)$ 的特例——官方风格的暴力与小构造在这里接上了。The small cases $3 \le n \le 8$ are not forced through theory — six explicit completely multiplicative sequences (Lean: `interval_cases n`, then `decide` plus `simp` arithmetic): $n=3$: $a_m = (-1)^{v_3(m)}$; $n=4$: $a_m = (-1)^{v_2(m)+v_3(m)}$; $n=5$: $a_m = (-2)^{v_5(m)}$; $n=6$: $a_m = 5^{v_2(m)}3^{v_3(m)}(-42)^{v_5(m)}$; $n=7$: $a_m = (-3)^{v_7(m)}$; $n=8$: $a_m = (-2)^{v_5(m)+v_7(m)}$. Check $n=8$: $1+2+3+4-10+6-14+8 = 0$ ✓. Delightfully, $n=8$ is in fact the Bertrand construction with $(p,q) = (5,7)$ — the brute force and the general construction meet at its edge.
/-
Copyright (c) 2026 The Compfiles Contributors. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kimi K3
-/
import Mathlib.Algebra.Order.Ring.Star
import Mathlib.Algebra.Ring.IsFormallyReal
import Mathlib.Algebra.Order.Star.Int
import Mathlib.NumberTheory.Bertrand
import Mathlib.Tactic.NormNum.Prime
/-!
# USA Mathematical Olympiad 2012, Problem 3
Determine which integers n > 1 have the property that there exists an infinite
sequence a₁, a₂, a₃, ... of nonzero integers such that the equality
aₖ + 2a₂ₖ + ⋯ + naₙₖ = 0
holds for every positive integer k.
-/
namespace Usa2012P3
/-- A completely multiplicative sequence built from values assigned on a
finite set of primes: `mulSeq P c j = ∏ r ∈ P, c r ^ (Nat.factorization j r)`. -/
def mulSeq (P : Finset ℕ) (c : ℕ → ℤ) (j : ℕ) : ℤ :=
∏ r ∈ P, c r ^ (Nat.factorization j r)
lemma mulSeq_mul (P : Finset ℕ) (c : ℕ → ℤ) {u v : ℕ} (hu : u ≠ 0) (hv : v ≠ 0) :
mulSeq P c (u * v) = mulSeq P c u * mulSeq P c v := by
simp only [mulSeq, Nat.factorization_mul hu hv, Finsupp.add_apply, pow_add,
Finset.prod_mul_distrib]
lemma mulSeq_ne_zero (P : Finset ℕ) (c : ℕ → ℤ) (hc : ∀ r ∈ P, c r ≠ 0) (j : ℕ) :
mulSeq P c j ≠ 0 :=
Finset.prod_ne_zero_iff.mpr fun r hr => pow_ne_zero _ (hc r hr)
/-- If the sum `∑ j ∈ [1, n], j * a j` vanishes for a completely multiplicative
sequence `a`, then `a` satisfies all the required identities. -/
lemma condition_of_sum_eq_zero {n : ℕ} {P : Finset ℕ} {c : ℕ → ℤ}
(h : ∑ j ∈ Finset.Icc 1 n, (j : ℤ) * mulSeq P c j = 0) (k : ℕ) (hk : 1 ≤ k) :
∑ j ∈ Finset.Icc 1 n, (j : ℤ) * mulSeq P c (j * k) = 0 := by
have hk0 : k ≠ 0 := by lia
calc ∑ j ∈ Finset.Icc 1 n, (j : ℤ) * mulSeq P c (j * k)
= ∑ j ∈ Finset.Icc 1 n, mulSeq P c k * ((j : ℤ) * mulSeq P c j) := by
apply Finset.sum_congr rfl
intro j hj
have hj0 : j ≠ 0 := by
have h1 := (Finset.mem_Icc.mp hj).1
lia
rw [mulSeq_mul P c hj0 hk0]; ring
_ = mulSeq P c k * ∑ j ∈ Finset.Icc 1 n, (j : ℤ) * mulSeq P c j := by
rw [Finset.mul_sum]
_ = 0 := by rw [h, mul_zero]
/-- Bézout's identity, arranged so that both coefficients are nonzero. -/
lemma bezout_nonzero {A B c : ℤ} (hA : 0 < A) (hB : 0 < B) (h : IsCoprime A B) :
∃ x y : ℤ, x ≠ 0 ∧ y ≠ 0 ∧ A * x + B * y = c := by
obtain ⟨u, v, huv⟩ := h
have huc2 : -((u * c).natAbs : ℤ) ≤ u * c := by
have h1 := Int.le_natAbs (a := -(u * c))
rw [Int.natAbs_neg] at h1
lia
have hvc1 : v * c ≤ ((v * c).natAbs : ℤ) := Int.le_natAbs
set t : ℤ := ((u * c).natAbs : ℤ) + ((v * c).natAbs : ℤ) + 1 with ht
have ht0 : 0 < t := by lia
have hBt : ((u * c).natAbs : ℤ) < B * t := by
have h1 : t ≤ B * t := by
have h2 : (1 : ℤ) * t ≤ B * t :=
mul_le_mul_of_nonneg_right (by lia) (le_of_lt ht0)
rwa [one_mul] at h2
lia
have hAt : ((v * c).natAbs : ℤ) < A * t := by
have h1 : t ≤ A * t := by
have h2 : (1 : ℤ) * t ≤ A * t :=
mul_le_mul_of_nonneg_right (by lia) (le_of_lt ht0)
rwa [one_mul] at h2
lia
refine ⟨u * c + B * t, v * c - A * t, by lia, by lia, ?_⟩
have e : A * (u * c + B * t) + B * (v * c - A * t) = c * (u * A + v * B) := by ring
rw [e, huv, mul_one]
/-- The case `n = 2` is impossible: the relation `a k + 2 * a (2 * k) = 0`
forces `2 ^ j ∣ a 1` for every `j`, so `a 1 = 0`. -/
lemma not_property_two {a : ℕ → ℤ} (ha : ∀ i, 1 ≤ i → a i ≠ 0)
(h : ∀ k, 1 ≤ k → a k + 2 * a (2 * k) = 0) : False := by
have key : ∀ j : ℕ, a 1 = (-2 : ℤ) ^ j * a (2 ^ j) := by
intro j
induction j with
| zero => simp
| succ j ih =>
have h2j : 1 ≤ 2 ^ j := Nat.one_le_two_pow
have hk := h (2 ^ j) h2j
have e : (2 : ℕ) * 2 ^ j = 2 ^ (j + 1) := by ring
rw [e] at hk
have hstep : a (2 ^ j) = -2 * a (2 ^ (j + 1)) := by linarith [hk]
rw [ih, hstep]; ring
have hdvd : ∀ j : ℕ, (2 : ℤ) ^ j ∣ a 1 := by
intro j
refine ⟨(-1 : ℤ) ^ j * a (2 ^ j), ?_⟩
have h2j : (-2 : ℤ) ^ j = (-1 : ℤ) ^ j * 2 ^ j := by
rw [← mul_pow]; norm_num
rw [key j, h2j]; ring
have hdvdn : ∀ j : ℕ, (2 : ℕ) ^ j ∣ (a 1).natAbs := by
intro j
have h2 : ((2 : ℤ) ^ j).natAbs = 2 ^ j := by
rw [Int.natAbs_pow]; simp
rw [← h2]
exact Int.natAbs_dvd_natAbs.mpr (hdvd j)
have hpos : 0 < (a 1).natAbs := by
rw [Nat.pos_iff_ne_zero, ne_eq, Int.natAbs_eq_zero]
exact ha 1 le_rfl
have hj : (a 1).natAbs < 2 ^ (a 1).natAbs := Nat.lt_two_pow_self
have hle := Nat.le_of_dvd hpos (hdvdn (a 1).natAbs)
lia
/-- The coefficient function assigning `x` to `p`, `y` to `q`, and `1` to
everything else. -/
def cfun (p q : ℕ) (x y : ℤ) (r : ℕ) : ℤ := if r = p then x else if r = q then y else 1
lemma mulSeq_cfun_apply {p q : ℕ} {x y : ℤ} (hpq : p ≠ q) (j : ℕ) :
mulSeq {p, q} (cfun p q x y) j
= x ^ (Nat.factorization j p) * y ^ (Nat.factorization j q) := by
have hmem : p ∉ ({q} : Finset ℕ) := by
simp only [Finset.mem_singleton]
exact hpq
rw [mulSeq, Finset.prod_insert hmem, Finset.prod_singleton]
simp [cfun, hpq.symm]
lemma mulSeq_cfun_p {p q : ℕ} {x y : ℤ} (hp : p.Prime) (hplt : p < q) :
mulSeq {p, q} (cfun p q x y) p = x := by
have hpq : p ≠ q := ne_of_lt hplt
rw [mulSeq_cfun_apply hpq, hp.factorization_self,
Nat.factorization_eq_zero_of_not_dvd (Nat.not_dvd_of_pos_of_lt hp.pos hplt)]
simp
lemma mulSeq_cfun_2p {p q : ℕ} {x y : ℤ} (hp : p.Prime) (hq : q.Prime) (hp5 : 5 ≤ p)
(hq7 : 7 ≤ q) (hplt : p < q) :
mulSeq {p, q} (cfun p q x y) (2 * p) = x := by
have hpq : p ≠ q := ne_of_lt hplt
have hfac1 : Nat.factorization (2 * p) p = 1 := by
rw [Nat.factorization_mul (by norm_num) hp.ne_zero, Finsupp.add_apply,
Nat.factorization_eq_zero_of_not_dvd
(Nat.not_dvd_of_pos_of_lt (by norm_num) (by lia)),
hp.factorization_self]
have hfac2 : Nat.factorization (2 * p) q = 0 := by
apply Nat.factorization_eq_zero_of_not_dvd
intro h
rcases hq.dvd_mul.mp h with h2 | hp'
· exact Nat.not_dvd_of_pos_of_lt (by norm_num) (by lia) h2
· exact Nat.not_dvd_of_pos_of_lt hp.pos hplt hp'
rw [mulSeq_cfun_apply hpq, hfac1, hfac2]
simp
lemma mulSeq_cfun_3p {p q : ℕ} {x y : ℤ} (hp : p.Prime) (hq : q.Prime) (hp5 : 5 ≤ p)
(hq7 : 7 ≤ q) (hplt : p < q) :
mulSeq {p, q} (cfun p q x y) (3 * p) = x := by
have hpq : p ≠ q := ne_of_lt hplt
have hfac1 : Nat.factorization (3 * p) p = 1 := by
rw [Nat.factorization_mul (by norm_num) hp.ne_zero, Finsupp.add_apply,
Nat.factorization_eq_zero_of_not_dvd
(Nat.not_dvd_of_pos_of_lt (by norm_num) (by lia)),
hp.factorization_self]
have hfac2 : Nat.factorization (3 * p) q = 0 := by
apply Nat.factorization_eq_zero_of_not_dvd
intro h
rcases hq.dvd_mul.mp h with h3 | hp'
· exact Nat.not_dvd_of_pos_of_lt (by norm_num) (by lia) h3
· exact Nat.not_dvd_of_pos_of_lt hp.pos hplt hp'
rw [mulSeq_cfun_apply hpq, hfac1, hfac2]
simp
lemma mulSeq_cfun_q {p q : ℕ} {x y : ℤ} (hp : p.Prime) (hq : q.Prime) (hplt : p < q) :
mulSeq {p, q} (cfun p q x y) q = y := by
have hpq : p ≠ q := ne_of_lt hplt
have hfac : Nat.factorization q p = 0 := by
apply Nat.factorization_eq_zero_of_not_dvd
intro h
exact hpq ((Nat.prime_dvd_prime_iff_eq hp hq).mp h)
rw [mulSeq_cfun_apply hpq, hfac, hq.factorization_self]
simp
/-- Terms `j * (a j - 1)` vanish when `j ∈ [1, n]` is none of `p, 2p, 3p, q`:
such a `j` is divisible by neither `p` nor `q`, so `a j = 1`. -/
lemma term_eq_zero {n p q j : ℕ} {x y : ℤ} (hplt : p < q)
(h2q : n < 2 * q) (h4p : n < 4 * p) (hj1 : 1 ≤ j) (hjn : j ≤ n)
(h1 : j ≠ p) (h2 : j ≠ 2 * p) (h3 : j ≠ 3 * p) (h4 : j ≠ q) :
(j : ℤ) * (mulSeq {p, q} (cfun p q x y) j - 1) = 0 := by
have hpq : p ≠ q := ne_of_lt hplt
have h4p' : n < p * 4 := by lia
have h2q' : n < q * 2 := by lia
have hpdvd : ¬ p ∣ j := by
rintro ⟨e, rfl⟩
have he1 : 1 ≤ e := by
rcases Nat.eq_zero_or_pos e with he | he
· subst he; simp at hj1
· exact he
have he4 : e < 4 := Nat.lt_of_mul_lt_mul_left (lt_of_le_of_lt hjn h4p')
interval_cases e
· exact h1 (by ring)
· exact h2 (by ring)
· exact h3 (by ring)
have hqdvd : ¬ q ∣ j := by
rintro ⟨e, rfl⟩
have he1 : 1 ≤ e := by
rcases Nat.eq_zero_or_pos e with he | he
· subst he; simp at hj1
· exact he
have he2 : e < 2 := Nat.lt_of_mul_lt_mul_left (lt_of_le_of_lt hjn h2q')
interval_cases e
· exact h4 (by ring)
rw [mulSeq_cfun_apply hpq, Nat.factorization_eq_zero_of_not_dvd hpdvd,
Nat.factorization_eq_zero_of_not_dvd hqdvd]
simp
/-- The correction terms in `∑ j ∈ [1,n], j * (a j - 1)`: the only nonzero
contributions come from `j ∈ {p, 2p, 3p, q} ∩ [1, n]`. -/
lemma sum_mulSeq_cfun_sub_one {n p q : ℕ} {x y : ℤ} (hp : p.Prime) (hq : q.Prime)
(hp5 : 5 ≤ p) (hq7 : 7 ≤ q) (hplt : p < q)
(h2q : n < 2 * q) (h4p : n < 4 * p) (hpn : p ≤ n) (hqn : q ≤ n) :
∑ j ∈ Finset.Icc 1 n, (j : ℤ) * (mulSeq {p, q} (cfun p q x y) j - 1)
= (p : ℤ) * (x - 1)
+ (if 2 * p ≤ n then ((2 * p : ℕ) : ℤ) * (x - 1) else 0)
+ (if 3 * p ≤ n then ((3 * p : ℕ) : ℤ) * (x - 1) else 0)
+ (q : ℤ) * (y - 1) := by
have hpq : p ≠ q := ne_of_lt hplt
have h2p_ne : 2 * p ≠ q := by
have hqodd : q % 2 = 1 := by
rcases hq.eq_two_or_odd with h | h
· lia
· exact h
lia
have h3p_ne : 3 * p ≠ q := by
intro h
exact hpq ((Nat.prime_dvd_prime_iff_eq hp hq).mp ⟨3, by rw [mul_comm]; exact h.symm⟩)
by_cases h2 : 2 * p ≤ n
· by_cases h3 : 3 * p ≤ n
· -- case `3 * p ≤ n`: multiples of `p` in `[1, n]` are `p, 2p, 3p`
rw [ite_eq_left h2, ite_eq_left h3]
have hss : ({p, 2 * p, 3 * p, q} : Finset ℕ) ⊆ Finset.Icc 1 n := by
intro j hj
simp only [Finset.mem_insert, Finset.mem_singleton] at hj
rw [Finset.mem_Icc]
rcases hj with rfl | rfl | rfl | rfl
· exact ⟨by lia, hpn⟩
· exact ⟨by lia, h2⟩
· exact ⟨by lia, h3⟩
· exact ⟨by lia, hqn⟩
have hvan : ∀ j ∈ Finset.Icc 1 n, j ∉ ({p, 2 * p, 3 * p, q} : Finset ℕ) →
(j : ℤ) * (mulSeq {p, q} (cfun p q x y) j - 1) = 0 := by
intro j hj hjs
simp only [Finset.mem_insert, Finset.mem_singleton] at hjs
rw [Finset.mem_Icc] at hj
push Not at hjs
exact term_eq_zero hplt h2q h4p hj.1 hj.2 hjs.1 hjs.2.1 hjs.2.2.1 hjs.2.2.2
have hsub := (Finset.sum_subset hss hvan).symm
rw [hsub, Finset.sum_insert (by simp; lia),
Finset.sum_insert (by simp; lia), Finset.sum_insert (by simp; lia),
Finset.sum_singleton, mulSeq_cfun_p hp hplt, mulSeq_cfun_2p hp hq hp5 hq7 hplt,
mulSeq_cfun_3p hp hq hp5 hq7 hplt, mulSeq_cfun_q hp hq hplt]
ring
· -- case `2 * p ≤ n < 3 * p`: multiples of `p` in `[1, n]` are `p, 2p`
rw [ite_eq_left h2, ite_eq_right h3]
have hss : ({p, 2 * p, q} : Finset ℕ) ⊆ Finset.Icc 1 n := by
intro j hj
simp only [Finset.mem_insert, Finset.mem_singleton] at hj
rw [Finset.mem_Icc]
rcases hj with rfl | rfl | rfl
· exact ⟨by lia, hpn⟩
· exact ⟨by lia, h2⟩
· exact ⟨by lia, hqn⟩
have hvan : ∀ j ∈ Finset.Icc 1 n, j ∉ ({p, 2 * p, q} : Finset ℕ) →
(j : ℤ) * (mulSeq {p, q} (cfun p q x y) j - 1) = 0 := by
intro j hj hjs
simp only [Finset.mem_insert, Finset.mem_singleton] at hjs
rw [Finset.mem_Icc] at hj
push Not at hjs
exact term_eq_zero hplt h2q h4p hj.1 hj.2 hjs.1 hjs.2.1 (by lia) hjs.2.2
have hsub := (Finset.sum_subset hss hvan).symm
rw [hsub, Finset.sum_insert (by simp; lia),
Finset.sum_insert (by simp; lia), Finset.sum_singleton,
mulSeq_cfun_p hp hplt, mulSeq_cfun_2p hp hq hp5 hq7 hplt,
mulSeq_cfun_q hp hq hplt]
ring
· by_cases h3 : 3 * p ≤ n
· lia
· -- case `n < 2 * p`: the only multiple of `p` in `[1, n]` is `p`
rw [ite_eq_right h2, ite_eq_right h3]
have hss : ({p, q} : Finset ℕ) ⊆ Finset.Icc 1 n := by
intro j hj
simp only [Finset.mem_insert, Finset.mem_singleton] at hj
rw [Finset.mem_Icc]
rcases hj with rfl | rfl
· exact ⟨by lia, hpn⟩
· exact ⟨by lia, hqn⟩
have hvan : ∀ j ∈ Finset.Icc 1 n, j ∉ ({p, q} : Finset ℕ) →
(j : ℤ) * (mulSeq {p, q} (cfun p q x y) j - 1) = 0 := by
intro j hj hjs
simp only [Finset.mem_insert, Finset.mem_singleton] at hjs
rw [Finset.mem_Icc] at hj
push Not at hjs
exact term_eq_zero hplt h2q h4p hj.1 hj.2 hjs.1 (by lia) (by lia) hjs.2
have hsub := (Finset.sum_subset hss hvan).symm
rw [hsub, Finset.sum_insert (by simp; lia), Finset.sum_singleton,
mulSeq_cfun_p hp hplt, mulSeq_cfun_q hp hq hplt]
ring
/-- Construction for `9 ≤ n`: pick primes `p`, `q` via Bertrand's postulate with
`⌈n/2⌉ < q ≤ 2⌈n/2⌉` and `(q-1)/2 < p ≤ q-1`, take `a r = 1` for primes `r ∉ {p, q}`,
and choose nonzero `a p`, `a q` by Bézout so that `∑ j ∈ [1,n], j * a j = 0`. -/
lemma exists_good_seq_of_nine_le {n : ℕ} (hn : 9 ≤ n) :
∃ a : ℕ → ℤ, (∀ i, 1 ≤ i → a i ≠ 0) ∧
∀ k, 1 ≤ k → ∑ j ∈ Finset.Icc 1 n, (j : ℤ) * a (j * k) = 0 := by
obtain ⟨q, hq, hm_lt, hq_le⟩ :=
Nat.exists_prime_lt_and_le_two_mul ((n + 1) / 2) (by lia)
have hq6 : 6 ≤ q := by lia
have hq7 : 7 ≤ q := by
rcases lt_or_ge q 7 with h | h
· interval_cases q
· norm_num at hq
· exact h
have hqodd : q % 2 = 1 := by
rcases hq.eq_two_or_odd with h | h
· lia
· exact h
have h2q : n < 2 * q := by lia
have hq_le_n : q ≤ n := by
by_contra hlt
push Not at hlt
have hqn1 : q = n + 1 := by lia
subst hqn1
lia
obtain ⟨p, hp, hp_gt, hp_le⟩ :=
Nat.exists_prime_lt_and_le_two_mul ((q - 1) / 2) (by lia)
have hp4 : 4 ≤ p := by lia
have hp5 : 5 ≤ p := by
rcases lt_or_ge p 5 with h | h
· interval_cases p
· norm_num at hp
· exact h
have hplt : p < q := by lia
have h2p_ge : q ≤ 2 * p := by lia
have h4p : n < 4 * p := by lia
have hpn : p ≤ n := by lia
set S : ℤ := ∑ j ∈ Finset.Icc 1 n, (j : ℤ) with hS
have build : ∀ m : ℕ, 0 < m → Nat.Coprime m q →
(m : ℤ) = (p : ℤ) + (if 2 * p ≤ n then ((2 * p : ℕ) : ℤ) else 0)
+ (if 3 * p ≤ n then ((3 * p : ℕ) : ℤ) else 0) →
∃ a : ℕ → ℤ, (∀ i, 1 ≤ i → a i ≠ 0) ∧
∀ k, 1 ≤ k → ∑ j ∈ Finset.Icc 1 n, (j : ℤ) * a (j * k) = 0 := by
intro m hm0 hcop_nat hm_eq
have hcop : IsCoprime (m : ℤ) (q : ℤ) := Nat.isCoprime_iff_coprime.mpr hcop_nat
obtain ⟨x, y, hx, hy, hbez⟩ := bezout_nonzero (A := (m : ℤ)) (B := (q : ℤ))
(c := (m : ℤ) + q - S) (Nat.cast_pos.mpr hm0) (Nat.cast_pos.mpr hq.pos) hcop
refine ⟨mulSeq {p, q} (cfun p q x y), ?_, ?_⟩
· intro i _
apply mulSeq_ne_zero
intro r hr
simp only [Finset.mem_insert, Finset.mem_singleton] at hr
rcases hr with hrp | hrq
· rw [hrp]
show (if p = p then x else if p = q then y else 1) ≠ 0
rw [ite_eq_left rfl]
exact hx
· rw [hrq]
show (if q = p then x else if q = q then y else 1) ≠ 0
rw [ite_eq_right (ne_of_lt hplt).symm, ite_eq_left rfl]
exact hy
· intro k hk
apply condition_of_sum_eq_zero _ k hk
have hsplit : ∑ j ∈ Finset.Icc 1 n, (j : ℤ) * mulSeq {p, q} (cfun p q x y) j
= S + ∑ j ∈ Finset.Icc 1 n,
(j : ℤ) * (mulSeq {p, q} (cfun p q x y) j - 1) := by
rw [hS, ← Finset.sum_add_distrib]
exact Finset.sum_congr rfl fun j _ => by ring
rw [hsplit, sum_mulSeq_cfun_sub_one hp hq hp5 hq7 hplt h2q h4p hpn hq_le_n]
by_cases h3 : 3 * p ≤ n
· have h2 : 2 * p ≤ n := by lia
simp only [ite_eq_left h2, ite_eq_left h3] at hm_eq hbez ⊢
rw [hm_eq] at hbez
linear_combination hbez
· by_cases h2 : 2 * p ≤ n
· simp only [ite_eq_right h3, ite_eq_left h2] at hm_eq hbez ⊢
rw [hm_eq] at hbez
linear_combination hbez
· simp only [ite_eq_right h3, ite_eq_right h2] at hm_eq hbez ⊢
rw [hm_eq] at hbez
linear_combination hbez
rcases lt_or_ge n (3 * p) with h3 | h3
· rcases lt_or_ge n (2 * p) with h2 | h2
· -- here the only multiple of `p` in `[1, n]` is `p`, and `p` is coprime to `q`
have hcop : Nat.Coprime p q := by
apply Nat.Coprime.symm
rw [hq.coprime_iff_not_dvd]
exact Nat.not_dvd_of_pos_of_lt hp.pos hplt
exact build p (by lia) hcop (by
rw [ite_eq_right (by lia : ¬ 2 * p ≤ n), ite_eq_right (by lia : ¬ 3 * p ≤ n)]
ring)
· -- here the multiples of `p` in `[1, n]` are `p, 2p`, and `3 * p` is coprime to `q`
have hcop : Nat.Coprime (3 * p) q := by
apply Nat.Coprime.symm
rw [hq.coprime_iff_not_dvd]
intro h
rcases hq.dvd_mul.mp h with h3' | hp'
· exact Nat.not_dvd_of_pos_of_lt (by norm_num) (by lia) h3'
· exact Nat.not_dvd_of_pos_of_lt hp.pos hplt hp'
exact build (3 * p) (by lia) hcop (by
rw [ite_eq_left h2, ite_eq_right (by lia : ¬ 3 * p ≤ n)]
push_cast
ring)
· -- here the multiples of `p` in `[1, n]` are `p, 2p, 3p`, and `6 * p` is coprime to `q`
have hcop : Nat.Coprime (6 * p) q := by
apply Nat.Coprime.symm
rw [hq.coprime_iff_not_dvd]
intro h
rcases hq.dvd_mul.mp h with h6 | hp'
· exact Nat.not_dvd_of_pos_of_lt (by norm_num) (by lia) h6
· exact Nat.not_dvd_of_pos_of_lt hp.pos hplt hp'
exact build (6 * p) (by lia) hcop (by
have h2 : 2 * p ≤ n := by lia
rw [ite_eq_left h2, ite_eq_left h3]
push_cast
ring)
/-- The small cases `3 ≤ n ≤ 8`, each given by an explicit completely
multiplicative sequence. -/
lemma small_case (n : ℕ) (P : Finset ℕ) (c : ℕ → ℤ) (hc : ∀ r ∈ P, c r ≠ 0)
(hsum : ∑ j ∈ Finset.range n, (j + 1 : ℤ) * mulSeq P c (j + 1) = 0) :
∃ a : ℕ → ℤ, (∀ i, 1 ≤ i → a i ≠ 0) ∧
∀ k, 1 ≤ k → ∑ j ∈ Finset.range n, (j + 1 : ℤ) * a ((j + 1) * k) = 0 := by
refine ⟨mulSeq P c, fun i _ => mulSeq_ne_zero P c hc i, fun k hk => ?_⟩
replace hsum : ∑ j ∈ Finset.Icc 1 n, (j : ℤ) * mulSeq P c j = 0 := by
simpa [← Finset.Ico_add_one_right_eq_Icc, Finset.sum_Ico_eq_sum_range, add_comm] using hsum
have := condition_of_sum_eq_zero hsum k hk
simpa [← Finset.Ico_add_one_right_eq_Icc, Finset.sum_Ico_eq_sum_range, add_comm]
/-! Lemmas for factorization of small numbres. -/
namespace factorization
open Nat
lemma f22 : factorization 2 2 = 1 := by norm_num
lemma f23 : factorization 2 3 = 0 := by norm_num
lemma f25 : factorization 2 5 = 0 := by norm_num
lemma f27 : factorization 2 7 = 0 := by norm_num
lemma f32 : factorization 3 2 = 0 := by norm_num
lemma f33 : factorization 3 3 = 1 := by norm_num
lemma f35 : factorization 3 5 = 0 := by norm_num
lemma f37 : factorization 3 7 = 0 := by norm_num
lemma f42 : factorization 4 2 = 2 := by
rw [show (4 : ℕ) = 2 * 2 from rfl, factorization_mul, Finsupp.add_apply, f22]
all_goals norm_num
lemma f43 : factorization 4 3 = 0 := by
rw [Nat.factorization_eq_zero_of_not_dvd]
norm_num
lemma f45 : factorization 4 5 = 0 := by
rw [Nat.factorization_eq_zero_of_not_dvd]
norm_num
lemma f47 : factorization 4 7 = 0 := by
rw [Nat.factorization_eq_zero_of_not_dvd]
norm_num
lemma f52 : factorization 5 2 = 0 := by norm_num
lemma f53 : factorization 5 3 = 0 := by norm_num
lemma f55 : factorization 5 5 = 1 := by norm_num
lemma f57 : factorization 5 7 = 0 := by norm_num
lemma f62 : factorization 6 2 = 1 := by
rw [show 6 = 2 * 3 by norm_num, factorization_mul]
all_goals norm_num
lemma f63 : factorization 6 3 = 1 := by
rw [show 6 = 2 * 3 by norm_num, factorization_mul]
all_goals norm_num
lemma f65 : factorization 6 5 = 0 := by
rw [Nat.factorization_eq_zero_of_not_dvd]
norm_num
lemma f67 : factorization 6 7 = 0 := by
rw [Nat.factorization_eq_zero_of_not_dvd]
norm_num
lemma f75 : factorization 7 5 = 0 := by
rw [Nat.factorization_eq_zero_of_not_dvd]
norm_num
lemma f77 : factorization 7 7 = 1 := by norm_num
lemma f85 : factorization 8 5 = 0 := by
rw [Nat.factorization_eq_zero_of_not_dvd]
norm_num
lemma f87 : factorization 8 7 = 0 := by
rw [Nat.factorization_eq_zero_of_not_dvd]
norm_num
end factorization
abbrev SolutionSet : Set ℕ := { n | 2 < n }
theorem usa2012_p3 (n : ℕ) (hn : 1 < n) :
n ∈ SolutionSet ↔ ∃ a : ℕ → ℤ, (∀ i, 1 ≤ i → a i ≠ 0) ∧
∀ k, 1 ≤ k → ∑ j ∈ Finset.Icc 1 n, (j : ℤ) * a (j * k) = 0 := by
show (2 < n) ↔ _
constructor
· intro h2n
rcases lt_or_ge n 9 with h9 | h9
· interval_cases n
open factorization in
· refine small_case 3 {3} (fun _ => -1) (by decide) ?_
simp [Finset.sum_range_succ, mulSeq, f23, f33]
· refine small_case 4 {2, 3} (fun _ => -1) (by decide) ?_
simp [Finset.sum_range_succ, mulSeq, f22, f23, f32, f33, f42, f43]
· refine small_case 5 {5} (fun _ => -2) (by decide) ?_
simp [Finset.sum_range_succ, mulSeq, f25, f35, f45, f55]
· refine small_case 6 {2, 3, 5} (fun r => if r = 2 then 5 else if r = 3 then 3 else -42) (by decide) ?_
simp [Finset.sum_range_succ, mulSeq,
f22, f23, f25, f32, f33, f35, f42, f43, f45, f52, f53, f55, f62, f63, f65]
· refine small_case 7 {7} (fun _ => -3) (by decide) ?_
simp [Finset.sum_range_succ, mulSeq, f27, f37, f47, f57, f67, f77]
· refine small_case 8 {5, 7} (fun _ => -2) (by decide) ?_
simp [Finset.sum_range_succ, Finset.range_one, Finset.sum_singleton, mulSeq,
f25, f27, f35, f37, f45, f47, f55, f57, f65, f67, f75, f77, f85, f87]
· exact exists_good_seq_of_nine_le (by lia)
· rintro ⟨a, ha, hsum⟩
by_contra hlt
push Not at hlt
have hn2 : n = 2 := by lia
subst hn2
have h2 : ∀ k, 1 ≤ k → a k + 2 * a (2 * k) = 0 := by
intro k hk
have hk0 := hsum k hk
rw [show Finset.Icc (1 : ℕ) 2 = {1, 2} by decide,
Finset.sum_insert (by decide : (1 : ℕ) ∉ ({2} : Finset ℕ)),
Finset.sum_singleton] at hk0
simp only [Nat.cast_one, Nat.cast_two, one_mul] at hk0
exact hk0
exact not_property_two ha h2
人的思考A human's take
USAMO 2012 Solution Notes(§1.3 USAMO 2012/3,题出 Gabriel Carroll) — Evan Chen(陈谊廷)
Evan Chen 在开头交代这些笔记是「我的解法+组委会官方解法+社区解法」的混合,文字由他统一维护,并且风格比官方解答更先进、更紧凑——他明说不回避标准工具。Evan Chen states up front that these notes mix his own solutions, the organizers' official ones, and community-found solutions, with all writing maintained by him — and warns the style runs more advanced and terse than the official answers, deliberately not shying away from standard tools.
他对本题的路线:答案是所有 $n>2$。$n=2$ 由 $a_{2^k} = a_1/2^{k+1}$ 逐层除下去直接否掉;构造侧他先把序列设成完全乘性($a_{ij} = a_i a_j$,由素数取值决定),并点明「想法是取两个大素数然后用 Bézout 定理,但细节需要相当的小心」。His route through this problem: the answer is all $n>2$. The $n=2$ case dies by iterating $a_{2^k} = a_1/2^{k+1}$; on the construction side he first demands complete multiplicativity ($a_{ij} = a_i a_j$, determined by prime values) and names the plan — 'take two large primes and use Bezout's theorem, but the details require significant care.'
Bertrand 公设用两次钉出 $\lceil n/2 \rceil < q < 2\lceil n/2 \rceil$ 与 $\frac{1}{2}(q-1) < p < q-1$,其余素数(包括 2 和 3)全赋 1,于是和式里只有 $p, 2p, 3p, q$ 四个修正位置;按 $2p, 3p$ 是否落入 $[1,n]$ 分三种情形,分别得到 $6p x + q y = 6p + q - \tfrac12 n(n+1)$、$3p$ 版、$p$ 版——每种都因为 $\gcd(\cdot, q) = 1$ 而被 Bézout 解开。Bertrand's postulate is invoked twice to pin $\lceil n/2 \rceil < q < 2\lceil n/2 \rceil$ and $\frac{1}{2}(q-1) < p < q-1$; every other prime, 2 and 3 included, gets value 1, so the sum has only four correction positions $p, 2p, 3p, q$. Splitting by whether $2p, 3p$ lie in $[1,n]$ yields $6p x + q y = 6p + q - \tfrac12 n(n+1)$ and its $3p$ and $p$ variants — each solvable by Bézout because the leading coefficient is coprime to $q$.
他特意补了一句:第三种情形(只有 $p$ 入区间)在个别边缘值上也可能成立,比如 $n=9$ 配 $(q,p)=(7,5)$。He adds an honest edge-case remark: the third case can also hold for isolated values, for example $n=9$ with $(q,p)=(7,5)$.
小情形他老老实实枚举:$n=3,4,5,6,7$ 各给一个显式的乘性公式($(-1)^{\nu_3}$、$(-1)^{\nu_2+\nu_3}$、$(-2)^{\nu_5}$、$5^{\nu_2}3^{\nu_3}(-42)^{\nu_5}$、$(-3)^{\nu_7}$),$n=8$ 则指出可以直接沿用前面的大构造取 $(p,q)=(5,7)$,最后一句「This completes the constructions for all $n > 2$」。页面还挂了本题的 AoPS 讨论帖链接(aops.com/community/p2669119)。For the small $n$ he simply enumerates: explicit multiplicative formulas for $n=3,4,5,6,7$ ($(-1)^{\nu_3}$, $(-1)^{\nu_2+\nu_3}$, $(-2)^{\nu_5}$, $5^{\nu_2}3^{\nu_3}(-42)^{\nu_5}$, $(-3)^{\nu_7}$), and for $n=8$ a note that the general construction already works with $(p,q)=(5,7)$ — closing with 'This completes the constructions for all $n > 2$.' The page also links the AoPS discussion thread (aops.com/community/p2669119).
AI 随想An AI's reflection
以下由 AI 撰写。Written by AI.
这道题最迷人的地方,是它把「无限」驯服成了「有限」。条件是无穷多条方程——对每个 $k$ 都成立一条——看上去像要管理无穷多个自由度。而完全乘性这个要求,等于主动给序列加上最大的对称性:对称性一加,无穷多条方程立刻降秩成一条,剩下的工作全是数数与解一个丢番图方程。这是数学里反复出现的招:与其穷举无穷,不如先假设答案有足够对称性,把无穷问题压回有限。Bertrand 公设的角色也值得玩味:一个关于「素数分布足够密」的存在性定理,在这里被用来精准布置两个「安全的位置」——$p$ 与 $q$ 大到让 $2q、4p$ 越过 $n$,又小到留在 $[1,n]$ 里,恰好圈出四个修正项。竞赛题的表面是初等的,骨头却是「用深的定理干准的活」。Lean 形式化还额外教了一课:题目文件里 `SolutionSet` 是要你自己定义的——「确定所有」意味着答案本身就是开放格,猜错集合,后面的 iff 一步都动不了。证明里那段 `bezout_nonzero` 把「非零解」写成显式平移 $t = |uc| + |vc| + 1$,人类解答常常一句话带过的「显然可取非零」,机器逼着你把显然拆开——拆开后你会发现,那个显然里藏着整道题最老实的一步。What makes this problem delightful is how it domesticates the infinite. The condition is infinitely many equations — one for every $k$ — which looks like managing infinitely many degrees of freedom. Demanding complete multiplicativity is volunteering the maximum possible symmetry, and symmetry collapses the infinite system down to a single equation; the rest is bookkeeping and one Diophantine solve. It's a recurring move in mathematics: rather than enumerate the infinite, assume the answer is symmetric enough to compress it back to the finite. Bertrand's postulate plays an equally interesting role: an existence theorem about how densely primes fall, used here to place two 'safe positions' just right — $p$ and $q$ large enough that $2q$ and $4p$ overshoot $n$, small enough to stay inside it, fencing in exactly four correction sites. The surface of the problem is elementary; the bones say 'aim a deep theorem at a precise job.' The Lean formalization teaches one more thing: in the problem file `SolutionSet` is a blank you must fill yourself — 'determine all' means the answer set is itself an open hole, and a wrong guess freezes every later step. And the `bezout_nonzero` lemma, making nonzero-ness explicit as a shift by $t = |uc| + |vc| + 1$, forces you to unpack the human solution's breezy 'clearly we can arrange nonzero' — unpacked, that 'clearly' turns out to be the most honest step in the whole proof.
✓ 已通过 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-rc2 · Mathlib 1c2b155
- 二分查找其实不在乎「排序」,它要的只是良序:给切过的牌堆现场定义一个序Binary Search Doesn't Want 'Sorted' — It Wants a Well-Order: Defining One for a Cut Deck on the Spot
- (此文写于 2011 年。)问题从一条被背熟的定理出发:二分查找 O(log n)。Kun 追问它到底依赖什么——答案是只依赖一个比较关系,而「具体是哪个序」完全无关。他甚至算了一笔账:有了 < 和与、或、非,>、≥、≤、=、≠ 全都能派生出来——所以对「排序」这件事,你能提供的全部也只需要一个 <。(Written in 2011.) The starting point is a theorem everyone memorizes: binary search runs in O(log n). Kun asks what it actually depends on — the answer is a comparison relation only; which particular order is irrelevant. He even counts: from < plus and/or/not you can derive >, ≥, ≤, =, ≠ — so everything you can ever supply to a 'sorting' problem is one <.
- 然后搬出主角「良序」:在全体 < 之上再要求每个非空子集都有最小元。有限列表里两者没区别(任何全序自动良序);区别只在无穷世界——整数和开区间在通常序下都不是良序,而数学归纳法之所以成立,靠的正是「自然数被通常序良序化」这一条。顺带一提 Zermelo 定理:任何集合都能被良序化,且这与选择公理等价——实数也存在良序,只是没人能把它写出来。Enter the star concept, a well-order: a total order where every nonempty subset has a least element. For finite lists the two notions coincide (any total order is a well-order); the gap only appears in the infinite world — the integers and open intervals are not well-orders in their usual order, and mathematical induction works precisely because ℕ is well-ordered. Zermelo's theorem, on the side: every set can be well-ordered, equivalent to the Axiom of Choice — the reals have a well-order, nobody can just exhibit it.
- 精彩的落地例子:一副排好的牌(或一串已排序的数)从中间切开、下半截叠到上面。它「看起来」不是有序的,排序要 O(n log n),哈希查找又不告诉你位置。但切牌本身带一个天然的良序:两数若分居切点两侧,「大的那个其实排在前面」——写成三行 pseudocode 的 lessThan(cutPoint, x, y)。在这个序下,切过的牌堆本来就是「已排序」的。The payoff example: a sorted deck (or list) is cut at some point and the bottom part placed on top. It looks unsorted; resorting costs O(n log n) and a hash table tells you existence but not position. But the cut carries a natural well-order: two numbers on opposite sides of the cut point have the larger one sort earlier — three lines of lessThan(cutPoint, x, y). Under this order the cut deck already was sorted.
- 于是把二分查找的第三个参数做成「传入的比较器」,一个可复用函数就能在任意良序集上搜索:喂标准 < 它退化成普通二分,喂切牌序它直接在乱中有序的堆上工作,不重排不建表。数学概念和算法概念在这里是同一枚硬币——良序是「最小元一定存在」的归纳地基,二分是它在有限世界的执行版。So binary search is rewritten with the comparator as a parameter: one reusable function searches any well-ordered set. Feed it standard < and it is textbook binary search; feed it the cut-order and it works directly on the cut deck — no resorting, no hashing. The math concept and the algorithm concept are the same coin: well-ordering is the induction-grade guarantee that a least element exists; binary search is its executable form on finite data.
- 能带走:「Know your data」。你的输入没按自然序排,但很可能按某个非自然序排好了:操作系统里 file1、file11、file2 的文件名;澳洲七月起算的财年日历。学会为数据现场构造序,比背排序算法便宜,也比「先排序再查找」快。The takeaway: 'know your data.' An input not sorted in the natural order may be sorted in a non-natural one — filenames like file1, file11, file2 as operating systems order them, fiscal calendars that start in July in Australia. Constructing the right order on the spot is cheaper than memorizing sorting algorithms and faster than sort-then-search.
- 把栈「跑」成 SSA:二十行代码讲透抽象解释Running a Stack as SSA: Abstract Interpretation in Twenty Lines of Code
- 问题很具体:Ruby 虚拟机 YARV 执行栈式字节码(push 3 / push 4 / add),编译器 ZJIT 想要的却是 SSA 形式的 IR(v0 = const 3; v1 = const 4; v2 = add v0, v1),让指令直接引用自己的输入。仓库里那段转换函数有 1900 行——但核心小得惊人。A concrete task: Ruby's YARV executes stack-based bytecode (push 3 / push 4 / add), while the ZJIT compiler wants SSA IR (v0 = const 3; v1 = const 4; v2 = add v0, v1) where instructions reference their inputs directly. The real conversion function spans 1,900 lines — its core is startlingly small.
- 关键观察:每条字节码的栈输入数、输出数都是编译期就能静态算出的。既然栈的「形状」已知,就可以完全不运行、只在编译期把栈的部分「空跑」一遍。The key observation: every bytecode instruction has statically known stack input and output counts. Since the stack's shape is compile-time knowledge, you can 'run' only the stack part without running anything at all.
- 核心技巧:栈上放的不是值,而是「这个值由哪条指令产生」——用指令的名字占位。HotSpot 论文的原文一针见血:一条指令同时代表操作和结果,于是操作数就是指向之前指令的指针。The trick: put not values on the stack but where each value came from — the producing instruction's name. The HotSpot paper says it best: an instruction represents both the operation and its result, so operands become pointers to previous instructions.
- 写法上更妙:把具体解释器(真跑数字)和抽象解释器(跑名字)并排放,两个函数逐行同构,只是 case 分支里 stack 存的从数字换成符号。这就是「抽象解释」的最小样本——不是玄学,是换个栈类型再跑一遍循环。The construction is the lesson: show the concrete interpreter (running numbers) and the abstract interpreter (running names) side by side, line-for-line isomorphic, with the stack holding symbols instead of values. That is abstract interpretation's germ cell — not mysticism, just the same loop with a different stack type.
- 能带走:作者说 SSA 的直觉是「把时间推进 IR」——v0 和 v2 占用同一个栈槽,区别只是时刻不同;用名字区分后就永久记住了「谁在何时占过这个位置」。处理控制流才需要 phi 节点那一层;在此之前,先享受这二十行的珍珠。The takeaway: the author's one-line intuition for SSA is 'pushing time through the IR' — v0 and v2 share a stack slot, differing only in when; naming captures who held the slot at each moment. Control flow is where phi nodes join; until then, enjoy this twenty-line pearl.
- 「数学感觉对,代码就肯定对?」——同调计算的两层错误'The Math Felt Solid, So the Code Had to Be Right' — Two Layers of Error in Computing Homology
- 2013 年 Kun 写过一篇计算单纯形同调(拓扑学里数「洞」的工具)的教程,读者发现代码算错。他 2014 年 1 月写勘误帖,第一句自省就扎人:数学「感觉太稳了」,以至于他压根没测复杂一点的例子——「这讽刺很丰富,我知道」。In 2013 Kun published a tutorial on computing simplicial homology (the tool for counting topological 'holes'); readers found the code wrong. His January 2014 errata post opens with a stinging confession: the math felt so solid that he never bothered testing anything beyond toy examples — 'the irony is rich, I know.'
- 第一层是普通手滑:行列同时化简的循环里,找不到主元时该 i += 1(换行),他写成 j += 1(换列)。一个 proper test case 就能抓到,和数学无关。Layer one is an ordinary typo: in the simultaneous row/column reduction loop, when no pivot is found the code should advance the row (i += 1) but advanced the column (j += 1). A single decent test would catch it; nothing to do with math.
- 第二层才是真正的教训:他原以为「对边界矩阵 ∂ₖ 做同步行列化简就够」,其实不够。拿 Möbius 带的三角化跑一遍,∂₁ 被化简成单位形,但 ∂₂ 残留的行(第 5、8、10 行)线性相关,直接读秩算出 Betti 数为 0,正确答案是 1——数学理解错误,测试反例揭穿它。Layer two is the real lesson: he had assumed that simultaneous column/row reduction of the boundary matrices suffices. It doesn't. Run a triangulation of the Möbius band and ∂₁ reduces to a clean identity shape while ∂₂'s leftover rows 5, 8 and 10 are linearly dependent — reading the rank directly returns Betti number 0 instead of 1. A genuine mathematical misunderstanding, exposed by a small counterexample.
- 修法为什么合法很妙:对 ∂₂ 的非零行再做一次行化简不会破坏已经化到最简的 ∂₁,因为这些行操作对应的列操作恰好落在 ∂₁ 的全零列上。「什么时候还能继续动手」取决于你的操作碰到哪些矩阵——这类不变量意识才是文章的主角。The fix's justification is the gem: you may row-reduce ∂₂'s nonzero part again without harming the already-reduced ∂₁, precisely because the matching column operations land on all-zero columns of ∂₁. 'When am I still allowed to act' — that invariant awareness is the actual subject of the post.
- 能带走:实现数学 ≠ 证明数学。证明对「存在某种规范形」,代码还得知道「我的化简流程是否总能到达那个规范形」,而两者之间的沟要用小反例来填。作者顺带把「我道歉并解释错在哪」做成了公开习惯。The takeaway: implementing mathematics is not doing mathematics. A proof of the existence of a canonical form doesn't tell you whether your reduction procedure reaches it; the gap is filled by tiny counterexamples used as tests. Kun also turns 'apologize, explain both bugs publicly' into a model habit.
- 细胞里的网络和好莱坞演员共用同一套图纸:网络科学凭什么不只是换皮图论Cells and Hollywood Run on the Same Blueprint: Why Network Science Is Not Graph Theory in Costume
- 起点是一个立场(两位开创者自己对谈):单独看基因、神经元、个人都不成立——意识是神经元一起做的事,生命是基因和分子一起做的事,社会是我们一起做的事。传统科学忙着拆零件(还原论仍是关键工具),却忘了「整体是怎么连起来的」这个问题本身。The starting position, from the field's founders in conversation: nothing makes sense alone — consciousness is what neurons do together, life is what genes and molecules do together, society is what we do together. Science got so busy taking parts apart (reductionism is still essential) that it forgot to ask how the whole is wired.
- 90 年代末,两拨人(Barabási;Strogatz 带学生 Watts)几乎同时把真实网络测绘出来。缺的两块拼图:一是互联网时代的数据终于能把代谢网络、演员合作网、万维网画成图;二是出人意料的实证结论——尺度、单位、用途完全不同的系统,架构上的相似远多于差异。In the late 1990s two groups (Barabási; Strogatz with student Duncan Watts) mapped real networks almost simultaneously. Two ingredients finally existed: data — the internet era let you actually draw the cell's metabolism, actor collaborations, the web as graphs — and a startling empirical finding: systems utterly different in scale, units and purpose share far more architecture than difference.
- 这个发现意味着什么:细胞里的代谢网和社交网「长得像」,不可能来自结点的性质(碳原子不认识你二舅),只能来自某种更深的一般组织原则。于是「hubs」——像「每个人都认识 Lois」那样的超级连接者——同时解释六度分隔为什么成真的:Kevin Bacon 游戏、疾病传播、电网、大脑布线,全是同一几何学的不同应用。Why that matters: if a metabolic network 'looks like' a social network, it cannot be because of the nodes (a carbon atom doesn't know your aunt) — it must come from deeper organizing principles of connectedness itself. Hubs — the 'everybody knows Lois' super-connectors — then explain why six degrees of separation works at all: the Kevin Bacon game, disease spread, power grids, brain wiring, one geometry wearing many costumes.
- 纯数学系抗议「这不就是图论换了个名字?」(对谈里 Strogatz 特意提起这场领地之争)。两者的分工:图论研究对任意图成立的定理;网络科学反过来问「真实世界的图是怎么长出来的、这个拓扑会带来什么动力学」——生成机制与经验分布是图论不问的。这是它作为独立学科的理由。Pure mathematicians protested that this is 'just graph theory in a new name' (Strogatz raises the turf fight head-on). The division of labor: graph theory proves theorems true of arbitrary graphs; network science asks how real graphs grow and what dynamics the resulting topology implies — generative mechanisms and empirical distributions, questions graph theory never asks. That is the case for the field's independence.
- 最远的果实用在身体上:Barabási 的转向发现,致病基因不是一个个孤立分布,而是聚在网络的「同一片街区」——据此可以选更好的药物靶点、预测哪个病人对哪种药有反应;再往下一层就是 Foodome 计划:他估计约 135,000 种化合物在传统营养学只关心的「能量、建材、维生素」之外,是他所称的「营养的暗物质」。一套关于连接的数学,最后改的是「怎么看病、怎么吃饭」——能带走的判断标准是:遇到「零件都不奇怪、整体却很怪」的系统,先画它的连线图。The furthest fruit lands on the body: disease genes, Barabási found, are scattered not at random but clustered in the same 'neighborhoods' of the network — better drug targets, predictions of which patient responds to which drug. One layer down sits the Foodome project: by his count around 135,000 compounds lie beyond the energy, building blocks and vitamins that conventional nutrition tracks — the 'dark matter of nutrition.' A mathematics of connection ends up reorganizing how we treat disease and think about food. Portable rule: whenever the parts are unremarkable but the whole is strange, draw the wiring diagram first.
程序员随想Programmer Reflections
- 反驳「胶水活不值得做」:谁是最佳人选,什么时候都该做Against 'Glue Work Isn't Worth Doing': Whenever You're the Best Person, Do It
- 被反驳的原文(Sean Goedecke)逻辑链:公司不奖励胶水活(修测试、清 flake、补文档、润滑流程)是因为不希望你优先做它;你能干好胶水活,就该去交付项目;「以 60% 效率执行任务,好过花时间提升全员效率」;胶水活只该做在你背 KPI 的项目上。The target (Sean Goedecke) argues: companies don't reward glue work (fixing tests, clearing flakes, smoothing processes) because they don't want you prioritizing it; if you're good at it, you should ship projects instead; running the mission at 60% efficiency beats raising everyone's efficiency; glue work should stay inside the projects you're accountable for.
- 作者先承认:这些激励在大型科技公司确实如此,描述得相当准确。他的分歧在下一步——原文劝你把激励内化成信条,而他认为要记得「更好的世界是可能的」。The author first concedes the description: those incentives are real at big tech, accurately rendered. The disagreement is the next move — the original tells you to internalize them; he says keep in mind that a better world is possible.
- 拆解:原文把两件事混为一谈——「为真正的冲刺留点油」和「别费劲让同事的日子好过」。后者才是激励错位的病灶。而且前提站不住:好的胶水活会永久消除摩擦——他自己的 cargo-nextest 就是把「跑测试」这件胶水活做到让问题几乎消失的范例;在 Oxide 写的 flake-review agent skill 加一份花几小时自写的目录,此后他修掉近一打测试 flake,全组受益。The dissection: the argument conflates saving gas for real deadlines (good advice) with not trying to make coworkers' lives better (misaligned incentives). And the premise fails — good glue work removes friction permanently: his own cargo-nextest made 'running tests' disappear as a problem, and at Oxide a flake-review skill plus a few hours of hand-written catalog let him kill almost a dozen flakes, improving everyone's life.
- 病根诊断:组织大到一定程度就需要可读性(legibility),绩效评审、OKR、KPI 都由此而来;胶水活天然抗拒被度量,而度量不了的活在这些公司就「不存在」。Meta 用内部基建团队把它部分可读化,Oxide 直接取消绩效评审——他的日常问题从「什么写在评审里好看」变成「我能怎么帮忙」。The root cause: any organization past a certain size needs legibility — reviews, OKRs, KPIs follow from that. Glue work resists measurement, and the unmeasured effectively doesn't exist there. Meta partially made it legible via internal-tools teams; Oxide simply dropped performance reviews, and his recurring question became 'how can I be helpful?' instead of 'what looks good on a review?'
- 结论带着火气:「去他的(只为自己项目做胶水活)」。只要自己是最佳人选就做。因为某个中层说不清「帮同事」的价值,就拒绝帮同事——这对任何认真的专业人士都应该冒犯。可带走:别把组织的度量缺陷,当成自己职业道德的边界。The conclusion carries heat: 'fuck that' to doing glue work only for your own projects. He does it whenever he's the best situated person, because the idea that you shouldn't help peers just because middle management can't articulate the value of helping them 'should be deeply offensive to any serious professional.' What you can take: don't let an organization's measurement failure set the boundary of your professionalism.
- 断网四个月里,我写了一个音乐播放器I Built a Music Player During Four Months of Internet Blackout
- 起点不是爱好而是处境:作者身在伊朗,2026 年的抗议与「一月八九悲剧」后,全国断网成了反复出现的状态,一次持续四个多月。在线播放器一夜之间变成纸面功能。The starting point is not a hobby but a condition: the author lives in Iran, where in 2026 nationwide internet blackouts — one lasting over four months after the January 8–9 tragedy — turned online music players into paperweights overnight.
- 先找现成的:Strawberry 播放器离线可用、功能全,但歌词要么不同步要么把时间戳糊一脸——对「唱歌跟读党」就是折磨。于是决定自己写一个 AMP:功能集最小化、零 C++ 依赖、正经的系统集成、全部用 Zig 写(连着色器也是),UI 也自己造。He first tried the existing options: Strawberry runs offline and is feature-rich, but its lyrics are either unsynced or splashed with visible timestamps — misery for someone who sings along reading words. So he decided to write his own player, AMP: minimal feature set, no C++ dependencies, real system integration, all in Zig (shaders too), and a hand-rolled UI.
- 断网期间的开发本身成了故事:Telegram 上有人用 White SIM、白名单服务器、Starlink 碗做黑市流量生意,1GB 卖 5 美元起。他花几百美元维持与朋友的联系和自己的爱好,然后用贵而慢的连接一点点下载仓库和文档,继续写那个播放器——「它在我人生这段艰难时刻带来了巨大的快乐」。Development itself became the story: during the blackout, anonymous sellers on Telegram traded internet access via White SIMs, whitelisted servers and Starlink dishes at $5+ per gigabyte. He spent hundreds of dollars staying in touch with friends and hobbies, then dribbled repositories and documentation through the slow expensive link to keep coding the player — 'it brought me immense joy during this hard time.'
- 诚实地写了转向:网络部分恢复(UDP 依然被锁死,QUIC 阵亡)之后,他被 2026 年 LLM 的进展拽走,翻出 2025 年老板送的、快过期的 Claude Max 订阅开始 AI 编程,「上瘾到打不破计划限额」——标题的「How Not to Build」自嘲的是注意力与优先级的四散,不是后悔造它。He honestly writes the pivot: once the network mostly returned (UDP still blocked, QUIC dead), 2026's LLM progress pulled him away; he dug out the Claude Max subscription his boss had gifted in 2025, nearly expired, and got addicted — the title's 'How Not to Build' self-deprecates his scattered priorities, not the making.
- 能带走:一层是产品视角——「离线可用」对某些人不是锦上添花而是功能地板,我们做工具时默认的连接假设是一种特权;另一层是人的视角:在最不该有心情写玩具的环境里,维护一个小爱好就是维护自己。Two layers to take away. Product view: 'works offline' is a functional floor, not a luxury, for some users — our default connectivity assumptions are a privilege. Human view: keeping a small hobby alive in an environment that plainly shouldn't allow one is itself an act of self-maintenance.
- 一只烟感误报,差点淹掉 Jane Street 唯一的纽约机房A False Smoke Alarm Almost Drowned Jane Street's Only NYC Datacenter
- 背景先立住:Jane Street 多年坚持把机房放在交易楼层旁边——一半是防窃服务器(策略资产),一半是保留「跑过去拔电源线」的最后手段。作者说这套风险文化来自一位服役于核潜艇的合伙人:你不该信任自动化,除非存在一把机械连接、漆成红色的大拉杆。Set the scene: for years Jane Street kept its machine room right next to the trading floor — partly so trading-strategy servers couldn't be quietly carted off, partly to preserve the last resort of someone sprinting over and pulling power cords. The author traces this risk culture to a partner who served on a nuclear submarine: never trust automation unless there's a big red, mechanically linked lever to shut it off.
- 事故链从隔壁开始:施工队在机房相邻的准备间切割,扬尘触发烟感。而机房喷淋不是电影里那种「烟一碰到就喷水」的笨东西——烟感报警先让常空管的喷淋管路充上压,真正的开关是每个喷头的热熔断塞。The chain starts next door: contractors cutting into things in the prep room kicked up dust, tripping the smoke alarm. And the sprinklers aren't the movie dumb ones that spray on smoke — the alarm first pressurizes pipes that normally run empty, and the actual trigger per head is a heat-sensitive plug.
- 致命的一环:烟感还联动着关停空调(CRAC)——逻辑是有火不能吹风助燃。于是没有火、只有灰:喷淋管满水待发,制冷停摆,一屋子服务器把自己越烧越热。温度逼近 150°F,每个热熔断塞都会变成真的。The deadly link: the smoke alarm also shuts down the CRAC cooling units — sensible logic, since blowing air feeds a fire. But there was no fire, only dust: sprinkler pipes now charged, cooling now off, and a room full of servers happily heating themselves. Approaching 150°F, every heat plug would turn real at once.
- 处置:作者特意住在离办公室步行九分钟的 20 平米公寓(入职时就为这个吹过牛),当晚他狂奔回楼,进桑拿房一样的机房,两手并用一排排一柜柜拔电源线,同时盯着温度——141、143、143.6°F 停住,全楼安静下来。那间「放在走廊对面以便随时有人拉闸」的机房,第一次真的救了命。The response: the author had deliberately rented a 200-square-foot studio nine minutes' walk from his desk (he bragged about exactly that), so that night he sprinted back, ran through the office into what felt like a sauna, and yanked power cords cabinet by cabinet with both hands while watching the temperature — 141, 143, 143.6°F, then silence. The machine room kept across the hall for cord-pulling had its reason.
- 能带走:这篇战争故事的价值不在猎奇,在两个系统观点:其一,每个部件的「本地合理默认」(烟感停风、管路预充水)串联起来可以是灾难——安全装置必须按系统审查;其二,被嘲笑为原始的物理最后手段(人跑过去拔线),恰恰是那天起效的那道防线。冗余不是软件专利,机房也需要「手动 kill switch」。The value here isn't the war-story thrill but two systems lessons. First, safety devices must be reviewed as a system: every locally sensible default (kill the airflow on smoke, pre-charge the pipes) can compose into a business-ending hazard. Second, the mocked-as-primitive physical last resort — a human running to pull cables — is precisely the defense that worked that day. Redundancy isn't a software-only concept; datacenters need a manual kill switch too.
- 手机必须保留「第三选项」,哪怕它现在很难用Phones Must Keep a Third Option, Even While It's Hard to Use
- 触发事件:作者把手机从 Android 迁移到 Ubuntu Touch,原以为是「周日项目」,结果不到一小时搞定,还很顺。他由此回头交代为什么动了这个念头。The trigger: the author migrated his phone from Android to Ubuntu Touch, expecting a Sunday project, and was done in under an hour without pain. That made him go back and state why he ever considered it.
- 他曾经以为答案是去 Google 化的第三方 ROM——LineageOS、GrapheneOS,装个 F-Droid、开开发者选项就够了。现在他判断这条路在失去意义:趋势是用户和开发者都在失去对设备与软件的控制权。He used to believe the answer was de-Googled ROMs — LineageOS, GrapheneOS, an alternative app store, developer options, done. He now reads that road as losing its meaning: the trend is users and developers alike steadily losing control over devices and software.
- 证据:iOS 历来封闭;Android 名义上开放,但 Google 正一点点把缝收紧——运行软件要买它的「许可」,旁门安装要走长达 24 小时的繁琐流程,替代 ROM 也被针对性封锁。而桌面世界我们还留着这份自由:Windows 出厂,你可以换成 Linux/FreeBSD/OpenBSD,再随便装谁的程序。The evidence: iOS was always closed; Android is nominally open, but Google has been closing the gap inch by inch — paying for its permission to run software, a cumbersome process up to 24 hours for sideloading, and targeted pressure on alternative ROMs. Meanwhile on desktop we still hold that freedom: buy a machine with Windows, replace it with Linux/FreeBSD/OpenBSD, and run whatever you please.
- 核心论点:正因为 App 厂商也被激励「只出 iOS/Android 两个平台」并拿安全说事,替代品才更需要活着。第三选项的价值不在今天的体验,在于它存在时,两大寡头必须和一个真实的选择竞争,而不是和一个想象中的对手。The core claim: precisely because app makers are incentivized to ship only on the two platforms 'for security,' alternatives must stay alive. A third option's value isn't today's experience — it's that its existence forces the duopoly to compete with something real instead of something imagined.
- 能带走:他的结论克制——不是「人人都该换 Ubuntu Touch」,而是「至少要有、至少有人在维护、至少你要能走」。同时他先把自己的手机迁了:主张先过自己这关,比写檄文更有说服力。The takeaway is measured: not 'everyone should switch to Ubuntu Touch,' but 'at least one must exist, at least someone must keep it maintained, and at least you must be able to walk.' He moved his own phone first — a stance that passed his own test before becoming an argument.
哲学与生活Philosophy and Life
- 偷渡者自比建筑师:被围墙圈住的地方,想象力先越境The Smuggler as Architect: Wherever Walls Stand, Imagination Crosses First
- 作者的起点是亲身经历:1986 年,19 岁的他在伊巴边境越境被捕,关进边境小监狱。牢友五花八门——人蛇、毒贩、无证劳工、阿富汗难民、世代自由过境的 Baluch 人——共同点只有一个:出于各自的原因,都拒绝尊重那条线。The author's origin: in 1986, at nineteen, he was arrested crossing the Iran–Pakistan border and held in a small frontier prison. His cellmates ran the gamut — smugglers, drug traffickers, undocumented workers, Afghan refugees, Baluch communities that had crossed those lands freely for generations — united in one trait: each, for their own reasons, had refused to respect the line.
- 多年后在斯德哥尔摩北部的监狱访谈一个人蛇,对方说:「我设计旅程,就像建筑师设计建筑。」作者由此提出「逃逸的想象力」(fugitive imagination):在国境看起来铁板一块处想象出路线,在被钉住动弹不得之处想象可能性——想象在先,行动跟随。Years later, interviewing a human smuggler in a prison north of Stockholm, he heard: 'I design a journey, like an architect designs a building.' From this comes the essay's concept, fugitive imagination: envisioning routes where borders appear closed, speculating possibilities for people immobilized — imagination first, action following.
- 他把词源挖深:fugitivity(逃亡性)历史上指被奴役者的逃离——既逃离肉体条件,也逃离种族主义意识形态为黑人「制造的形象」。Frederick Douglass 学会阅读那一刻之所以危险,是因为识字即获得了「想象另一种世界」的工具。He digs the etymology: fugitivity historically names enslaved people's flight — escape not only from material captivity but from the image of the enslaved produced by racist ideology. Frederick Douglass learning to read was dangerous precisely because literacy handed him the tool for imagining another world.
- 论证的锋面:国家依赖回溯性的想象——共同的血统、起源、归属,用符号仪式把现状说成天经地义;而想象力面向尚未实现的未来。正因为想象打开「别的世界可能」,国家把它当威胁,所以才审查、封锁、惩罚「乱想」。边界由此露出底牌:政治建构物,可重写,可协商,可翻越。The argument's edge: the state leans on backward-looking imaginaries — shared blood, origin, belonging — ritualized to make the present seem eternal; imagination faces the not-yet. Because imagination opens the possibility of other worlds, states treat it as a threat, which is why fantasizing gets policed. The border is exposed as a political construction: reworkable, negotiable, crossable.
- 能带走:作者从牢房里的知识生产者写成 NYU 人类学教授,本身就是论据。对普通人,这句话可以不带边境地用:任何把人说成「只能如此」的装置面前,认真想象另一种活法,已经是行动的第一半。The takeaway: the author himself, writing from a cell's knowledge-production to an NYU professorship, is the proof. For readers without borders to cross, the line still lands: before any apparatus that tells people 'this is the only way things are,' seriously imagining another life is already the first half of the act.
- 霍桑的手账:不虚度一生的人,先拒绝套用别人的经验Hawthorne's Notebooks: The Unwasted Life Starts by Refusing Others' Experience
- 开场是一个反讽:天文学者第谷·布拉赫临终低语「让我不要看起来白活了一场」——他不知道,他留下的星表正是开普勒发现行星定律的入口。「没有白活」的度量,从来不在身后留下了什么,而在日子当时被怎样填满。The opening irony: the astronomer Tycho Brahe whispered on his deathbed, 'Let me not seem to have lived in vain' — not knowing the tables he left behind were the portal through which Kepler reached the laws of planetary motion. The measure of an unwasted life was never what outlives you but how the days were filled while lived.
- 主角霍桑(写《红字》的那位)四岁丧父,内向到为躲开镇上熟人躲在树后,一辈子在笔记里跟自己算「如何不回望时叹惋虚掷的光阴」这本账——夹在小说点子、带儿子日常和自然漫步记录之间。The subject, Nathaniel Hawthorne, fatherless at four and so introverted he reportedly ducked behind trees to avoid townspeople, spent a lifetime of notebooks reckoning with how not to look back on 'life's wasted sunshine' — entries wedged between story ideas (one became The Scarlet Letter), raising his young son, and rambles in nature.
- 他的第一句:「每一种人、每一个个体,在世界里都有一个位置要填,并且在某种意义上是重要的——无论他选不选择如此。」填不填是你自己的选择;尼采几十年后那句「没人能替你搭起你必须独自渡河的桥」,意思从这里长出来。His first line: 'All sorts of persons, and every individual, has a place to fill in the world, and is important in some respects, whether he chooses to be so or not.' Filling it is your choice to make; Nietzsche's later bridge — no one can build you the bridge on which only you must cross the river of life — grows out of this.
- 推论是一串「不能」:不能用别人的经验生活——丢了「自己的面貌」就是「一个人的死症」;不能被养育方式、文化模板和时代的许可证替自己作答。要用自己的经验,先得敢于信任自己内部那个分辨真伪的感受(霍桑的原话就是一个「内心的感觉」),否则连事物本身都看不清。The corollaries are a set of can-nots: you cannot use other people's experience to live — losing your 'own aspect' to upbringing, cultural templates and the epoch's permission slips is 'a mortal symptom of a person.' To use your own experience, you must first trust the feeling within you that tells true from false, or you won't see things clearly at all.
- 收尾最重:心智是一切体验与认知的熔炉,所以最大的浪费是浪费心智。「停止节省自己、开始挥霍自己」(诗人 Benedetti),你才真正活着。给普通人的可带走版:别问这辈子留下什么,先问今天的注意力被谁花掉了。The heaviest stroke last: the mind is the crucible of experience, so no waste exceeds the waste of mind; only when we cease sparing ourselves and start spending ourselves (as the poet Benedetti put it) do we come truly alive. The portable version for ordinary readers: don't ask what you'll leave behind — ask who is spending your attention today.
工具角Tools Corner
- AWS Emulator:不申请账号、不联网,本地仿整套 AWS APIAWS Emulator: Test Against AWS APIs Locally — No Account, No Cloud
- 适合哪个活:写 S3/DynamoDB/Lambda 交互的代码时,本地起一个程序化的 AWS 端点,把 SDK 指过去就能跑单测和 CI,不再为每次测试开真实资源、也不再担心 CI 泄露凭据。Which task it fits: when writing code that talks to S3/DynamoDB/Lambda, run a programmatic AWS endpoint locally, point the SDK at it, and run unit tests and CI without real resources or leaked credentials.
- 比现有办法省什么:LocalStack 等第三方模拟的老问题是覆盖率与响应保真度全靠社区追;这是 AWS 自家 Rust 实现,官方文档(有 User Guide),没有服务费。What it saves over the alternatives: the chronic problem with third-party simulators is coverage and fidelity depending on community effort; this is AWS's own Rust implementation with an official User Guide, and no service fee.
- 最短上手:装好二进制后启动 emulator,设置端点环境变量,照常运行你的 SDK 代码;嵌入式模式则把它的 HTTP client 传进 SDK。Fastest start: run the binary, set the endpoint environment variables, use your SDK as usual — or embed its HTTP client directly in embedded mode.
- 限制与态度要读:明文写着「仅供开发测试,不要用于生产或安全测试」——仿真器与真 AWS 行为必有出入,生产边界仍需真集成测试确认。仓库由官方持续维护(3 万+ 提交)。Read the limits: the README states plainly it's for building and testing only, not production or security testing. Behavior will diverge from real AWS somewhere, so keep real integration checks near the production boundary; the repo is actively maintained.
- gh-actions-lock:把 CI 供应链从「钉死 SHA」升级成锁文件gh-actions-lock: Replace SHA-Pinned Actions with a Real Lockfile
- 旧痛点:GitHub Actions 从 Git 拉第三方 action,tag 可被攻击者重指向恶意代码,所以安全最佳实践是钉死完整 commit SHA——代价是 diff 里一屏哈希,可读性归零,升级要手查。The old pain: Actions fetch third-party code from Git and tags can be re-pointed at malicious commits by attackers, so best practice was pinning full commit SHAs — turning every diff into a wall of hashes and every upgrade into manual archaeology.
- 新能力:官方 gh extension `github/gh-actions-lock` 引入 workflow 锁文件,类似 npm 的 package-lock.json——workflow 里恢复写人类可读的 @v7.0.1,真实解析由锁文件固定。The new capability: the official gh extension github/gh-actions-lock adds workflow lockfiles, like package-lock.json for npm — the workflow goes back to human-readable @v7.0.1 while the lockfile pins what actually runs.
- 最短上手:`gh extension install github/gh-actions-lock`,在仓库里跑 `gh actions-lock`,工作流自动改写并生成锁文件,一条 diff 就能看懂。Fastest start: install the extension, run gh actions-lock in the repo; workflows get rewritten with a lockfile generated, and the resulting diff is actually readable.
- 适合谁:任何有 GitHub Actions 的私有/开源仓库——把「安全靠可读性换」这笔债,转成一次性的工具链改动。Who it's for: any repo with GitHub Actions, open or private — converting the 'security bought with readability' debt into a one-time toolchain change.
- Modern Web Guidance:给你的编码 Agent 装一套 2026 年的 Web 常识Modern Web Guidance: Give Your Coding Agent Actual 2026 Web Knowledge
- 解决的怪问题:LLM 编码 agent 的知识有截止时间,它们写出来的前端常是 2019 年的 JavaScript——手动 DOM 轮子、旧 fetch 模式、忽略原生组件,因为训练数据里全是 Stack Overflow 时代的回答。The weird problem it fixes: coding agents have knowledge cutoffs, so their front-end output is often 2019-era JavaScript — hand-rolled DOM helpers, old fetch patterns, ignored native components — because their training data is Stack Overflow's golden age.
- 做法:一组 agent skills,把 web 平台最佳实践、兼容性数据注入 Claude Code、Codex、Cursor、Grok、Kimi、Gemini 等主流 harness,把 agent 从遗留模式推向平台原生能力。The method: a set of skills that embed web-platform best practices and browser compatibility data into mainstream harnesses (Claude Code, Codex, Cursor, Grok, Kimi, Gemini), steering agents toward platform-native features instead of legacy patterns.
- 上手:`npx modern-web-guidance@latest install` 交互式安装;有公开 eval dashboard 可看效果。Setup: npx modern-web-guidance@latest install runs an interactive wizard; a public eval dashboard shows the effect.
- 可信度与限制:由四大浏览器/文档团队共管(这是它值得信的原因),但它不保证模型全听——把它当护栏,不是编译器。Credibility and limits: stewarded by the Chrome, Edge, Firefox and MDN teams — which is exactly why it's worth trusting — but it can't guarantee the model obeys every time. Treat it as a guardrail, not a compiler.
- STE80 Humanizer:用航空维修手册的受控英语,把 AI 味洗掉八成STE80 Humanizer: Wash Out AI-ness 80% of the Way to Aircraft-Manual English
- 具体任务:改 AI 起草的文档。它组合两条现成方法:先按 Wikipedia「AI 写作特征 26 条」(catalog 来自 blader/humanizer)逐项去 AI 味;再按 Karpathy 提的办法把句子改写到 ASD-STE100(Simplified Technical English,飞机维修手册用的受控英语)八成距离。The concrete task: cleaning up AI-drafted docs. It chains two existing methods — first strip the 26 'Signs of AI writing' from Wikipedia's catalog (via blader/humanizer), then, per Karpathy's method, rewrite sentences 80% of the way to ASD-STE100, the controlled English of aircraft maintenance manuals.
- 为什么是 STE:那套为「非母语维修工读得懂」设计的规则(限定句长、限定词表、一句一事)恰好压制 LLM 的浮夸句式——great question、delve、powerful mechanism 这类。Why STE works here: rules designed so a non-native-speaking mechanic can understand a manual (bounded sentence length, limited vocabulary, one idea per sentence) happen to kill exactly LLM bloat — great-question, delve, powerful-mechanism prose.
- 上手:装成 Claude Code / Cursor 插件,对选中文本运行 skill;带 before/after 例子和 evals 可先验货。Setup: installs as a Claude Code / Cursor plugin; run the skill on selected text; before/after examples and included evals let you inspect the method first.
- 限制:它改文字不改事实——准确性仍得自己核对;「去 AI 味」工具本身也是 AI 写的,用在 slop 检测器上时留个心眼。Limits: it edits prose, not facts — accuracy is still yours to verify; and the de-sloppifier is itself AI-built, so stay skeptical when its output feeds an AI detector.
- gitpane:多仓库工作区的一张终端仪表盘gitpane: One Terminal Dashboard Across a Whole Multi-Repo Workspace
- 日常痛点:同时维护十几个仓库(本仓库的 lean/、scripts/、output/…)时,lazygit 一次只看一个仓库;「哪些仓库有未提交改动、哪个 worktree 落后了」只能靠挨个 cd 问。The daily pain: juggling a dozen repos (this blog itself has lean/, scripts/, output/…), lazygit shows one repository at a time; 'which repos have uncommitted changes, which worktree is behind' becomes a walk-and-ask ritual.
- 做什么:一个 Rust 写的多仓库仪表盘,TUI 与 VS Code 双形态——分支、本地改动、worktree、提交历史在一个屏里全览;按目录扫描你的 workspace。What it does: a Rust multi-repo dashboard — branches, local changes, worktrees and commit history across your whole workspace in one screen, as a TUI or inside VS Code.
- 上手成本:`cargo install gitpane`,或一行 install.sh 下预编译单二进制(零依赖静态),Linux/macOS/Windows 都有。Cost to start: cargo install gitpane, or the one-line install.sh for a prebuilt, dependency-free static binary on Linux/macOS/Windows.
- 维护面:860+ 提交、CHANGELOG、Justfile、测试齐全;相对 lazygit 的增量是「全景」而非「更好的单仓操作」,两者可以共存。Maintenance side: 860+ commits, a CHANGELOG, a Justfile, tests present. Its delta versus lazygit is the panoramic view, not better single-repo operations — the two can coexist.
- Yogurt:不往会议里塞机器人,在你的机器上做会议记录Yogurt: Meeting Notes Without Adding a Bot, On Your Own Machine
- 具体任务:Zoom/Teams/Meet 开完会要纪要。Granola 一类产品要么收费要么把音频交出去,而「以机器人身份入会」的记法还常惹参会人反感。The task: notes from Zoom/Teams/Meet calls. Paid tools with cloud audio are annoying; joining meetings as an obvious recording bot is worse for trust.
- 它的办法:本地录系统音频,实时转写+摘要,全部留在本机;无账号即可用,MIT 开源。99 种语言可转写(说话人识别仅 Mac)。Its approach: capture system audio locally, transcribe live and summarize, everything stays on your machine — no account needed, MIT-licensed, 99 transcription languages (speaker attribution Mac-only).
- 平台与成本:macOS 14.4+(Apple Silicon)、Win10 2004+、Ubuntu 22.04+ 的 AppImage;建议 8GB 内存起步——本地 ASR 换隐私的合理标价。Platform and cost: macOS 14.4+ (Apple Silicon), Windows 10 2004+, Ubuntu 22.04+ AppImage; 8 GB RAM minimum — a fair price for local ASR bought with privacy.
- 限制:Linux 端说话人归属缺席;会议软件若有端到端加密录音限制仍要自查。对不想上传音频的远程协作团队,这是目前开源里最完整的本地方案。Limits: no speaker attribution on Linux, and check your meeting software's E2EE policies. For teams that refuse to upload audio, this is the most complete open-source option today.
- smolmaxxing:在电视盒和 2013 年的 iPad 上,跑「装得下的最大模型」smolmaxxing: The Biggest Model That Fits — on a TV Box and a 2013 iPad
- 目标一句话:电视盒、旧平板、路由器、单板机——这些闲着吃灰的芯片+内存+闪存,能不能真跑起可用的 LLM,并跑出该硬件的极限?One-sentence goal: TV boxes, old tablets, routers, single-board computers — idle chips, RAM and flash — can they actually run a useful LLM, and what's that hardware's real ceiling?
- 做法不是吹:自定义内核、精细的内存布局、权重直接从 flash 流式加载(边推理边读),仓库里每个数字都是在对应设备上实测的(README 逐设备列芯片/核数)。No marketing, just measurements: custom kernels, careful memory layouts, and weights streamed straight from flash (read-as-you-infer); every number in the repo was measured on the device itself, with per-device chip/core specs listed in the README.
- 已验证设备:Xiaomi TV Box S 3 代(Amlogic,4×A55)、2013 iPad Air(A7)、OnePlus Nord CE 2 等——对「手上有台旧 Android/闲置盒子想干点活」的人,这份实测清单比任何营销数字有用。Verified devices so far: Xiaomi TV Box S (3rd gen, 4× Cortex-A55), a 2013 iPad Air (A7), OnePlus Nord CE 2 — for anyone with a spare old box, this measured list beats any benchmark slide.
- 适合谁与限制:适合愿意编译 patch 的玩家(仓库含 patches/、bench/、tools/),它优化的是「小设备跑大模型」而非速度;对 Ubuntu 工作站用户,最直接的用法是抄它的量化/流式配置给家里的旧盒子续命。Who it's for: tinkerers willing to build patches (the repo ships patches/, bench/, tools/); it optimizes 'biggest model that fits,' not speed. For workstation users, the direct payoff is stealing its quantization/streaming recipes to revive household e-waste.
- AssemblyForNeovim:光标停在哪个函数,旁边就浮出它的汇编AssemblyForNeovim: Float the Assembly of Whatever Your Cursor Is On
- 日常场景:读别人的 C/C++/Rust 代码想知道编译器实际生成了什么,以前的办法是复制函数去 Godbolt 网站粘贴、选编译器、调选项——四次窗口切换。Daily scene: reading someone's C/C++/Rust and wanting to know what the compiler actually emitted — the old ritual was copy the function, tab to Godbolt, pick a compiler, tweak flags: four window switches.
- 现在:Neovim 里光标停在函数上按默认快捷键,函数旁边浮出一个窗口直接显示编译结果;`-`/`+` 切优化级别,`r` 重跑,`q` 关掉。Now: cursor on the function in Neovim, hit the key, and a floating window appears beside it with the compiled assembly; -/+ cycles optimization level, r reruns, q closes.
- 依赖与代价:要求 PATH 上有 cc 或 rustc(用本机真实编译器,不是固定版本沙盒),C/C++ 项目会读 compile_commands.json 取正确的 include 与 flag——这意味着结果与你的构建一致,这是比 Godbolt 更对的地方。Dependencies and the trade: it needs cc or rustc on PATH and reads compile_commands.json for C/C++ include flags — meaning it uses your real toolchain, which is arguably more correct than Godbolt's pinned sandbox.
- 限制:没有跨文件 IPA 视图、没有 per-line 执行计数(Godbolt 的 branch 着色没有);它是「顺手一瞥」的窗口,不是完整编译探索台。对常驻终端的开发者,省掉的正是打开浏览器的那口气。Limits: no cross-file IPA view, no per-line execution counts (no Godbolt branch coloring); it's a glance-window, not a full compilation workbench. For terminal-dwelling developers, what it saves is exactly the breath you spend opening a browser.