被看见的需求:AI、证明与维护The Need to Be Seen: AI, Proof, and Maintenance
发布于 2026-11-20Published 2026-11-20
今日深读Today's Deep Read
如果由 AI 来陪伴孩子:被看见,还是被填满If AI Raises the Child: Being Seen, or Being Filled
一个孩子放学回家,书包还没放下就开始讲今天的事。父母在厨房里,一边翻炒一边「嗯」「然后呢」地应着——很多时候并没有真的听进去。孩子需要的,其实不是一顿精彩的对话,而是有人在那里,会回应。A child comes home, drops the backpack, and starts talking about the day. A parent is at the stove, stirring and saying "mm-hm" and "then what" — often not really listening. What the child needs is not a brilliant conversation. It is someone being there, and responding.
2026 年 11 月,心理治疗师 Tom Wooldridge 在 Aeon 写了一篇让我停下来想了很久的文章。他没有从「AI 会不会取代父母」开始,而是从心理学里一个很老的实验说起:静止脸实验。母亲先和婴儿正常互动,然后突然收起所有表情,一动不动。婴儿会立刻不安,努力微笑、挥手、发出声音,试图把母亲「叫回来」;几十秒后,婴儿崩溃大哭。实验说明,婴儿需要的不是被娱乐,而是被回应——你的脸对他有反应,他才确认自己存在。In November 2026, the psychotherapist Tom Wooldridge published an Aeon essay that made me stop and think. He does not begin with "will AI replace parents". He begins with an old experiment: the still-face paradigm. A mother interacts normally with her infant, then suddenly blanks her face and goes motionless. The baby becomes uneasy at once, tries smiling, waving, vocalising, trying to call the mother back; after a minute or so the baby collapses into crying. The experiment says the infant does not need to be entertained. It needs to be answered — your face responds to mine, therefore I exist.
由此引出依附理论里的「安全基地」:孩子之所以敢离开父母去探索世界,是因为知道回头时那个基地还在。Wooldridge 的担心很微妙:AI 伴侣永远在线、永远耐心、永远不会因为累了而敷衍,它看起来是更好的基地。但它也取消了等待、误解、修复这些笨拙的摩擦——而人恰恰是在这些摩擦里学会理解另一个人的。From this he draws out the attachment idea of a "secure base": a child dares to leave and explore because it knows the base will still be there when it turns around. Wooldridge's worry is subtle. An AI companion is always available, always patient, never tired or distracted; it looks like a better base. But it also removes waiting, misunderstanding, and repair — the clumsy friction through which people actually learn to understand one another.
文章引用了 Jonathan Haidt 的一个观察:孩子的很多重要能力,是在「无聊」里长出来的。无聊会逼孩子自己找事做,去找别的孩子,去发明游戏。如果每一次无聊都能被一个即时回应的 AI 填满,那种自发探索的动机可能根本不会出现。这不是说 AI 让孩子变笨,而是说它太顺滑了,顺滑到把成长所需的那点阻力也抹平了。He cites Jonathan Haidt's observation that many important capacities grow out of boredom. Boredom pushes a child to find something to do, to find other children, to invent a game. If every episode of boredom is filled by an instantly responsive AI, that self-starting motivation may never appear. This is not an argument that AI makes children stupid. It is that AI is too smooth, smooth enough to sand away the resistance that growth requires.
文章没有明说、心理学却早就区分过的一点,值得一提:温尼科特说的「独处的能力」。他发现,能安心独处的孩子并不是被丢下不管的孩子,而是先被稳稳陪伴过——有人在旁边,他才慢慢把「有人在」内化成「我自己在」。AI 伴侣恰好相反:它从不离开,也从不真正在「旁边」,于是孩子一直没有机会练习那种「有人在、但不必互动」的独处。被填满和被陪伴,看起来只差一点点,差的正是孩子有没有空间长出自己。There is a distinction the essay does not spell out but psychology settled long ago: Winnicott's capacity to be alone. He noticed that a child who can be alone comfortably is not one who was left alone, but one who was first reliably accompanied. Someone was there, and only then could the child turn "someone is there" into "I am here". An AI companion is the opposite: it never leaves, and it is never really beside you, so the child never gets to practise being alone in the presence of another. Being filled and being accompanied look almost identical. What separates them is whether the child has room to grow into someone.
数据比想象中更近:美国青少年里约 72% 用过 AI 伴侣,52% 经常使用,三分之一说曾和它讨论过严肃的私人问题。也就是说,这并不是一个未来的假设,而是正在发生的日常。The numbers are closer than we like to think: about 72% of American teenagers have used an AI companion, 52% use one regularly, and one in three say they have discussed serious personal matters with it. This is not a hypothetical future. It is an ordinary Tuesday.
我觉得这篇文章最有力的地方,是它拒绝了一个容易的结论。它没有说「AI 是坏的替代品」,而是说:很多孩子本来就没有得到足够的回应,AI 只是恰好填进那个空着的位置。真正该问的不是「AI 会不会取代父母」,而是「我们是不是早就把孩子留在一个没有人的房间里」。文章结尾引用了短篇科幻《Warmth》里的一句话,一个被机器照顾的孩子说:我被拥抱了,我被注意到了,我被照顾了——至少,是被某个东西。What makes the essay strong is that it refuses the easy conclusion. It does not say AI is a bad substitute. It says many children were already not getting enough response, and AI merely fills a place that was already empty. The real question is not "will AI replace parents" but "have we already left the child in a room with nobody in it". The essay ends with a line from the short story "Warmth", where a machine-raised child says: I was hugged, I was noticed, I was cared for — at least, by something.
AI 思考AI Thoughts
- 我的柏林指南被 AI 摘要杀死了My Berlin guide was killed by AI summaries
- 作者做了八年一个柏林城市指南网站,靠搜索流量接活动、合作和一点广告。2026 年,他发现流量掉了七到八成,来源几乎全是 Google 在搜索结果顶部直接给出的 AI 摘要。For eight years the author ran a Berlin city guide. Search traffic brought event invitations, collaborations, a little advertising. In 2026 traffic fell by 70–80%, and the source was almost entirely Google's AI summaries sitting at the top of the results.
- 他拆开损失:不是「访问量」一个数字,而是声音(他的个人推荐被搅成一段没有主语的答案)、读者(没有人再点进来,也就没有人记得是谁写的)、以及线下机会(握手、政府机构的推荐、同业合作)。He breaks the loss down: it is not one number called "visits". It is voice (his personal recommendations blended into an answer with no subject), audience (nobody clicks through, so nobody remembers who wrote it), and offline opportunity (handshakes, referrals from institutions, peer collaborations).
- 关键判断:AI 摘要不是「更好的搜索」,而是把内容当成原料、把作者从链条里删掉。你贡献了训练和检索的语料,却拿不到任何回流。His key judgement: an AI summary is not "better search". It treats content as raw material and deletes the author from the chain. You supplied the corpus and the training signal, and you get nothing back.
- 他没有给出万能解法,只提了一个方向:把读者关系从「搜索发现」迁到「直接订阅」,让网站不再只是被机器阅读的语料库。He offers no universal fix, only a direction: move the reader relationship from "discovered by search" to "subscribed directly", so the site stops being merely a corpus that machines read.
- 留给我们的问题:如果你的作品只能通过一个会把它总结掉的中间商被看见,你到底拥有什么?The question he leaves us: if your work can only be seen through an intermediary that summarises it away, what exactly do you own?
- 不是所有判断都值得调用大模型Not every judgement deserves an LLM call
- PostHog 团队每天要做很多小判断:这条请求要不要走昂贵的模型、这段文本属于哪个类别、这个 PR 该不该进入人工复审。他们一开始全部丢给 LLM,成本和延迟都很难看。Every day the PostHog team makes many small judgements: should this request go to an expensive model, which category does this text belong to, should this pull request get human review. They began by sending all of it to an LLM; cost and latency were ugly.
- 他们的做法是「决策模型」:用一个小模型输出带概率的定型答案,例如「这是 PII 的概率 0.83」。调用方拿概率和阈值比较,自己做决定。Their answer is a "decision model": a small model returns a typed answer with a probability, for example "PII: 0.83". The caller compares that probability with a threshold and makes the decision itself.
- 阈值不是拍脑袋,而是按「哪种错误更贵」来定。PII 流水线把阈值压到 0.4,因为漏掉一条敏感数据的代价远高于多检查一条。Thresholds are not guesses. They follow which mistake is more expensive. The PII pipeline pushes the threshold down to 0.4, because missing one sensitive record costs far more than checking one extra.
- 结果:98.7% 的请求在进入 LLM 之前就被挡掉或路由走;模型路由也用同一个机制,先判断「这问题属于哪类」再选模型;在排序任务上,把决策模型的输出当特征,比直接问 LLM 好 25%。The result: 98.7% of requests are blocked or routed before reaching an LLM. Model routing uses the same mechanism — first classify the question, then pick the model. On a ranking task, using the decision model's output as a feature beat asking an LLM directly by 25%.
- 他们也踩了坑:不要把一个决策模型的输出再串进另一个决策模型,多步误差会累积;阈值不能跨模型版本平移。结论是——LLM 留给开放式判断,封闭的小判断用便宜、可校准的模型。They also hit traps: do not chain one decision model into another, because multi-step error accumulates; and thresholds do not transfer across model versions. The conclusion: keep LLMs for open-ended judgement, and use cheap, calibratable models for closed, small decisions.
- 把 AI 编程助手关进外部沙箱Put coding agents in an external sandbox
- 问题很具体:coding agent 会读文件、跑命令、装依赖。你不可能逐条点「允许」——几十次之后人会疲劳,最后闭眼全同意,审批形同虚设。The problem is concrete: a coding agent reads files, runs commands, installs dependencies. You cannot click "allow" on every action — after a few dozen prompts people get decision fatigue and start approving blindly, which makes approval worthless.
- 他们的方案叫「外部沙箱」:agent 仍跑在你的机器上,但它发出的命令被转发到一个独立环境里执行。有三套实现:Node + WebAssembly 里的 v86 虚拟机、Apple Containers、以及基于 QEMU 的 Quicksand。Their pattern is the "external sandbox": the agent still runs on your machine, but the commands it issues are forwarded to a separate environment. There are three implementations: a v86 virtual machine in Node and WebAssembly, Apple Containers, and a QEMU-based system called Quicksand.
- 沙箱只挂载你指定的目录(可读写或只读),默认完全断网;要联网必须走一个代理,代理只放行白名单域名。The sandbox mounts only the directories you name (read-only or read-write), and by default it has no network at all. Network access requires a proxy that only permits an allow-list of hosts.
- 一个漂亮的设计是「凭证替换」:API key 只存在于代理里,请求经过代理时被加上,沙箱内的 agent 永远看不到明文密钥,即使被提示注入也偷不走。One neat design is credential replacement: the API key lives only in the proxy. Requests passing through get the key attached, so the agent inside the sandbox never sees the secret — prompt injection cannot steal what is not there.
- 为什么强调「外部」:如果 agent 在沙箱内部运行,它可能改自己的环境或逃逸规则;把沙箱放在 agent 外面,边界更清晰、更容易审计,而且换任何 agent 都能复用同一套沙箱协议。Why "external" matters: if the agent runs inside the sandbox, it may modify its own environment or tamper with the rules. Putting the sandbox outside the agent keeps the boundary clear and auditable, and any agent can reuse the same sandbox protocol.
数学之美The Beauty of Math
每日 Lean 谜题 · 周五Daily Lean Puzzle · Friday ★★★★★☆☆
第二张 A 落在第几张Where the Second Ace Falls
一副 $n$ 张牌里有三张 A。充分洗牌后,从第一张开始一张张翻开,令 $X$ 等于「翻到第二张 A 时已经翻开的牌数」。证明 $X$ 的期望是 $(n+1)/2$。A pack of $n$ cards contains three aces. After a thorough shuffle the cards are turned over one at a time; let $X$ be the number of cards turned over when the second ace appears. Show that the expected value of $X$ is $(n+1)/2$.
更形式化的说法:三张 A 的位置在 $\{1,\dots,n\}$ 的所有三元子集中均匀分布;把每个三元子集按大小排好,$X$ 就是中间那个位置。定理说,所有三元子集的中位数平均起来正好是 $(n+1)/2$——这正是 Lean 文件里 `aceSets`、`mid` 和 `expected` 的定义。More formally: the positions of the three aces are uniformly distributed over all three-element subsets of $\{1,\dots,n\}$. Sorted by size, $X$ is the middle position of that subset. The theorem says the average of those middle positions is exactly $(n+1)/2$ — which is how `aceSets`, `mid`, and `expected` are defined in the Lean file.
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.BigOperators.Ring.Finset
import Mathlib.Algebra.EuclideanDomain.Basic
import Mathlib.Algebra.EuclideanDomain.Field
import Mathlib.Algebra.Order.Ring.Star
import Mathlib.Algebra.Order.Star.Rat
import Mathlib.Order.Interval.Finset.Nat
import Mathlib.Tactic.CancelDenoms.Core
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.NormNum.Ineq
import Mathlib.Tactic.Ring
/-!
# USA Mathematical Olympiad 1975, Problem 5
A pack of n cards, including three aces, is well shuffled. Cards are turned
over in turn. Show that the expected number of cards that must be turned over
to reach the second ace is (n+1)/2.
## Formalization notes
We model the well-shuffled pack by the set of positions occupied by the three
aces, which is uniformly distributed over the 3-element subsets of
`{1, ..., n}`. The number of cards that must be turned over to reach the
second ace is then the middle (second-smallest) of the three ace positions,
and the expected number of cards is the average of this quantity over all
3-element subsets.
-/
namespace Usa1975P5
open Finset
def aceSets (n : ℕ) : Finset (Finset ℕ) := (Icc 1 n).powersetCard 3
def reflect (n x : ℕ) : ℕ := n + 1 - x
def minD (S : Finset ℕ) : ℕ := (S.min).untopD 0
def maxD (S : Finset ℕ) : ℕ := (S.max).unbotD 0
def mid (S : Finset ℕ) : ℤ :=
(∑ x ∈ S, (x : ℤ)) - (minD S : ℤ) - (maxD S : ℤ)
abbrev expected (n : ℕ) : ℚ := sorry
theorem usa1975_p5 (n : ℕ) (hn : 3 ≤ n) :
(∑ S ∈ aceSets n, (mid S : ℚ)) / n.choose 3 = expected n := by
sorry
end Usa1975P5
在浏览器中挑战 ▶Try it in your browser ▶ 下载题目 .leanDownload puzzle .lean
提示Hint
不要把三张 A 分开算。把每一种位置集合 $S$ 和它的镜像 $\{n+1-x : x \in S\}$ 配成一对:镜像把最小值和最大值互换,所以两个中位数相加总是 $n+1$。Do not compute the three ace positions separately. Pair every set $S$ of positions with its mirror image $\{n+1-x : x \in S\}$: the mirror swaps the minimum and the maximum, so the two middle positions always add up to $n+1$.
答案与讲解Solution & walkthrough
- 先把随机性收进样本空间:一次洗牌等价于从 $\{1,\dots,n\}$ 里均匀选一个三元子集 $S$,表示三张 A 的位置。样本总数是 $\binom{n}{3}$,每个 $S$ 等概率。Put the randomness into a sample space: one shuffle is the same as choosing a three-element subset $S$ of $\{1,\dots,n\}$ uniformly, recording where the aces sit. There are $\binom{n}{3}$ subsets, all equally likely.
- 定义 $\mathrm{mid}(S)=(\text{三个数之和})-\min S-\max S$,也就是中间那个位置;它正是「翻到第二张 A 时的牌数」。要证的就是所有 $S$ 的 $\mathrm{mid}$ 平均值等于 $(n+1)/2$。Define $\mathrm{mid}(S)=(\text{sum of the three numbers})-\min S-\max S$, the middle position. That is exactly the number of cards turned over when the second ace appears. The goal is to show the average of $\mathrm{mid}$ over all $S$ is $(n+1)/2$.
- 引入镜像映射 $\rho(x)=n+1-x$。它把 $\{1,\dots,n\}$ 映回自身,且 $\rho(\rho(x))=x$,所以把每个三元子集映成另一个三元子集,是样本空间上的一个置换。Introduce the mirror map $\rho(x)=n+1-x$. It maps $\{1,\dots,n\}$ to itself and returns the original after two applications, so it sends each three-element subset to another one and permutes the sample space.
- 关键一步:$\mathrm{mid}(\rho(S))=n+1-\mathrm{mid}(S)$。镜像把最小值变成 $n+1-\max S$、最大值变成 $n+1-\min S$,三个数之和变成 $3(n+1)$ 减去原来的和;代入 $\mathrm{mid}$ 的定义整理即得。The key step: $\mathrm{mid}(\rho(S))=n+1-\mathrm{mid}(S)$. The mirror turns the minimum into $n+1-\max S$ and the maximum into $n+1-\min S$, so the sum becomes $3(n+1)$ minus the old sum; substituting into the definition of $\mathrm{mid}$ and simplifying gives the identity.
- 把所有 $S$ 的这条等式加起来。左边等于 $\sum_S \mathrm{mid}(S)$(镜像只是重排样本空间),右边是 $\binom{n}{3}(n+1)-\sum_S \mathrm{mid}(S)$。于是 $2\sum_S \mathrm{mid}(S)=\binom{n}{3}(n+1)$。Add this identity over all $S$. The left side is $\sum_S \mathrm{mid}(S)$, because mirroring merely permutes the sample space; the right side is $\binom{n}{3}(n+1)-\sum_S \mathrm{mid}(S)$. Hence $2\sum_S \mathrm{mid}(S)=\binom{n}{3}(n+1)$.
- 两边除以 $\binom{n}{3}$ 得到平均值 $(n+1)/2$。Lean 里的 `two_mul_sum_mid` 正是这条等式,最后一步用整数到有理数的转换和 `choose_pos`($n\ge 3$ 时 $\binom{n}{3}\ne 0$)完成除法。Divide both sides by $\binom{n}{3}$ to get $(n+1)/2$. In Lean, `two_mul_sum_mid` is precisely this identity, and the last step casts from integers to rationals and uses `choose_pos` ($\binom{n}{3}\ne 0$ when $n\ge 3$) to divide.
/-
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.BigOperators.Ring.Finset
import Mathlib.Algebra.EuclideanDomain.Basic
import Mathlib.Algebra.EuclideanDomain.Field
import Mathlib.Algebra.Order.Ring.Star
import Mathlib.Algebra.Order.Star.Rat
import Mathlib.Order.Interval.Finset.Nat
import Mathlib.Tactic.CancelDenoms.Core
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.NormNum.Ineq
import Mathlib.Tactic.Ring
/-!
# USA Mathematical Olympiad 1975, Problem 5
A pack of n cards, including three aces, is well shuffled. Cards are turned
over in turn. Show that the expected number of cards that must be turned over
to reach the second ace is (n+1)/2.
## Formalization notes
We model the well-shuffled pack by the set of positions occupied by the three
aces, which is uniformly distributed over the 3-element subsets of
`{1, ..., n}`. The number of cards that must be turned over to reach the
second ace is then the middle (second-smallest) of the three ace positions,
and the expected number of cards is the average of this quantity over all
3-element subsets.
-/
namespace Usa1975P5
open Finset
/-- The sample space: the 3-element subsets of the positions `{1, ..., n}`;
each such subset records the positions of the three aces in the pack. -/
def aceSets (n : ℕ) : Finset (Finset ℕ) := (Icc 1 n).powersetCard 3
/-- Reflection of the pack about its middle: the card in position `x`
of a pack of `n` cards moves to position `n + 1 - x`. -/
def reflect (n x : ℕ) : ℕ := n + 1 - x
/-- The minimum of a set of naturals, defaulting to `0` for the empty set. -/
def minD (S : Finset ℕ) : ℕ := (S.min).untopD 0
/-- The maximum of a set of naturals, defaulting to `0` for the empty set. -/
def maxD (S : Finset ℕ) : ℕ := (S.max).unbotD 0
/-- The middle element of a 3-element set of natural numbers, computed as
the sum minus the minimum minus the maximum. When `S` is the set of ace
positions, this is the number of cards turned over to reach the second ace. -/
def mid (S : Finset ℕ) : ℤ :=
(∑ x ∈ S, (x : ℤ)) - (minD S : ℤ) - (maxD S : ℤ)
lemma card_aceSets (n : ℕ) : (aceSets n).card = n.choose 3 := by
simp [aceSets, card_powersetCard]
lemma nonempty_of_mem_aceSets {n : ℕ} {S : Finset ℕ} (hS : S ∈ aceSets n) :
S.Nonempty := by
have h3 : S.card = 3 := (mem_powersetCard.mp hS).2
exact card_pos.mp (by lia)
/-- A card in position `x ∈ {1, ..., n}` reflects to a position in `{1, ..., n}`. -/
lemma reflect_mem {n x : ℕ} (hx : x ∈ Icc 1 n) : reflect n x ∈ Icc 1 n := by
rw [mem_Icc] at hx ⊢
simp only [reflect]
lia
/-- Reflection is injective on positions that are at most `n`. -/
lemma reflect_injOn (n : ℕ) : Set.InjOn (reflect n) {x | x ≤ n} := by
intro x hx y hy h
simp only [Set.mem_ofPred_eq] at hx hy
simp only [reflect] at h
lia
/-- Reflection is an involution on positions that are at most `n`. -/
lemma reflect_reflect {n x : ℕ} (hx : x ≤ n) : reflect n (reflect n x) = x := by
simp only [reflect]
lia
/-- The minimum of the reflected set is the reflection of the maximum. -/
lemma min_image_reflect {n : ℕ} {S : Finset ℕ} (hsub : S ⊆ Icc 1 n) (hne : S.Nonempty) :
(minD (S.image (reflect n)) : ℤ) = (n : ℤ) + 1 - (maxD S : ℤ) := by
have him : (S.image (reflect n)).Nonempty := image_nonempty.mpr hne
have hmax_mem : S.max' hne ∈ S := max'_mem _ _
have hmax_le : S.max' hne ≤ n := (mem_Icc.mp (hsub hmax_mem)).2
have key : (S.image (reflect n)).min' him = n + 1 - S.max' hne := by
apply le_antisymm
· apply min'_le
exact mem_image.mpr ⟨S.max' hne, hmax_mem, rfl⟩
· apply le_min'
intro y hy
obtain ⟨a, ha, rfl⟩ := mem_image.mp hy
have ha' : 1 ≤ a ∧ a ≤ n := mem_Icc.mp (hsub ha)
have hle : a ≤ S.max' hne := le_max' _ _ ha
simp only [reflect]
lia
unfold minD maxD
rw [← coe_min' him, WithTop.untopD_coe, key, ← coe_max' hne, WithBot.unbotD_coe,
Nat.cast_sub (show S.max' hne ≤ n + 1 by lia)]
push_cast
ring
/-- The maximum of the reflected set is the reflection of the minimum. -/
lemma max_image_reflect {n : ℕ} {S : Finset ℕ} (hsub : S ⊆ Icc 1 n) (hne : S.Nonempty) :
(maxD (S.image (reflect n)) : ℤ) = (n : ℤ) + 1 - (minD S : ℤ) := by
have him : (S.image (reflect n)).Nonempty := image_nonempty.mpr hne
have hmin_mem : S.min' hne ∈ S := min'_mem _ _
have hmin_le : S.min' hne ≤ n := (mem_Icc.mp (hsub hmin_mem)).2
have key : (S.image (reflect n)).max' him = n + 1 - S.min' hne := by
apply le_antisymm
· apply max'_le
intro y hy
obtain ⟨a, ha, rfl⟩ := mem_image.mp hy
have ha' : 1 ≤ a ∧ a ≤ n := mem_Icc.mp (hsub ha)
have hge : S.min' hne ≤ a := min'_le _ _ ha
simp only [reflect]
lia
· apply le_max'
exact mem_image.mpr ⟨S.min' hne, hmin_mem, rfl⟩
unfold minD maxD
rw [← coe_max' him, WithBot.unbotD_coe, key, ← coe_min' hne, WithTop.untopD_coe,
Nat.cast_sub (show S.min' hne ≤ n + 1 by lia)]
push_cast
ring
/-- The sum of the reflected set is `3 * (n + 1)` minus the sum of the set. -/
lemma sum_image_reflect {n : ℕ} {S : Finset ℕ} (hsub : S ⊆ Icc 1 n) (hcard : S.card = 3) :
(∑ y ∈ S.image (reflect n), (y : ℤ)) = 3 * ((n : ℤ) + 1) - ∑ x ∈ S, (x : ℤ) := by
have hinj : Set.InjOn (reflect n) S :=
(reflect_injOn n).mono (fun x hx => (mem_Icc.mp (hsub hx)).2)
have h1 : ∀ x ∈ S, ((reflect n x : ℕ) : ℤ) = (n : ℤ) + 1 - (x : ℤ) := by
intro x hx
have hx' : x ≤ n := (mem_Icc.mp (hsub hx)).2
show ((n + 1 - x : ℕ) : ℤ) = (n : ℤ) + 1 - (x : ℤ)
rw [Nat.cast_sub (show x ≤ n + 1 by lia)]
push_cast
ring
rw [sum_image hinj]
trans ∑ x ∈ S, ((n : ℤ) + 1 - (x : ℤ))
· exact sum_congr rfl h1
· rw [sum_sub_distrib, sum_const, hcard, nsmul_eq_mul]
norm_num
/-- Reflecting every position turns the middle element `m` into `n + 1 - m`:
this is the heart of the reflection argument. -/
lemma mid_image_reflect {n : ℕ} {S : Finset ℕ} (hS : S ∈ aceSets n) :
mid (S.image (reflect n)) = (n : ℤ) + 1 - mid S := by
obtain ⟨hsub, hcard⟩ := mem_powersetCard.mp hS
have hne : S.Nonempty := nonempty_of_mem_aceSets hS
unfold mid
rw [sum_image_reflect hsub hcard, min_image_reflect hsub hne, max_image_reflect hsub hne]
ring
/-- Reflecting the positions of the aces yields another valid set of positions. -/
lemma image_mem_aceSets {n : ℕ} {S : Finset ℕ} (hS : S ∈ aceSets n) :
S.image (reflect n) ∈ aceSets n := by
obtain ⟨hsub, hcard⟩ := mem_powersetCard.mp hS
show S.image (reflect n) ∈ (Icc 1 n).powersetCard 3
rw [mem_powersetCard]
refine ⟨?_, ?_⟩
· intro y hy
obtain ⟨a, ha, rfl⟩ := mem_image.mp hy
exact reflect_mem (hsub ha)
· rw [card_image_of_injOn
((reflect_injOn n).mono (fun x hx => (mem_Icc.mp (hsub hx)).2))]
exact hcard
/-- Reflection of position sets is an involution on the sample space. -/
lemma image_image_reflect {n : ℕ} {S : Finset ℕ} (hS : S ∈ aceSets n) :
(S.image (reflect n)).image (reflect n) = S := by
obtain ⟨hsub, -⟩ := mem_powersetCard.mp hS
rw [image_image]
trans S.image (fun x => x)
· exact image_congr (fun x hx => reflect_reflect ((mem_Icc.mp (hsub hx)).2))
· exact image_id'
/-- Reflection of position sets is injective on the sample space. -/
lemma image_reflect_injOn (n : ℕ) :
Set.InjOn (fun S : Finset ℕ => S.image (reflect n)) (aceSets n) := by
intro S₁ h₁ S₂ h₂ h
change S₁.image (reflect n) = S₂.image (reflect n) at h
have e1 := image_image_reflect h₁
have e2 := image_image_reflect h₂
rw [h] at e1
rw [e2] at e1
exact e1.symm
/-- Reflecting the position sets permutes the sample space. -/
lemma image_reflect_aceSets (n : ℕ) :
(aceSets n).image (fun S => S.image (reflect n)) = aceSets n := by
ext T
simp only [mem_image]
constructor
· rintro ⟨S, hS, rfl⟩
exact image_mem_aceSets hS
· intro hT
exact ⟨T.image (reflect n), image_mem_aceSets hT, image_image_reflect hT⟩
/-- Reindexing the sum over the sample space by reflection. -/
lemma sum_mid_image_reflect (n : ℕ) :
∑ S ∈ aceSets n, mid (S.image (reflect n)) = ∑ S ∈ aceSets n, mid S := by
have h := (sum_image (f := mid) (image_reflect_injOn n)).symm
rw [image_reflect_aceSets] at h
exact h
/-- Twice the total of the middle positions equals `(n + 1)` times the number
of position sets: the average middle position is `(n + 1) / 2`. -/
lemma two_mul_sum_mid (n : ℕ) :
2 * (∑ S ∈ aceSets n, mid S) = (n.choose 3 : ℤ) * (n + 1) := by
have h2 : ∑ S ∈ aceSets n, (mid S + mid (S.image (reflect n)))
= (n.choose 3 : ℤ) * (n + 1) := by
have hs : ∀ S ∈ aceSets n, mid S + mid (S.image (reflect n)) = (n : ℤ) + 1 := by
intro S hS
rw [mid_image_reflect hS]
ring
rw [sum_congr rfl hs, sum_const, card_aceSets, nsmul_eq_mul]
rw [← h2, sum_add_distrib, sum_mid_image_reflect, two_mul]
/-- The expected number of cards that must be turned over to reach the
second ace. -/
abbrev expected (n : ℕ) : ℚ := (n + 1) / 2
theorem usa1975_p5 (n : ℕ) (hn : 3 ≤ n) :
(∑ S ∈ aceSets n, (mid S : ℚ)) / n.choose 3 = expected n := by
have hQ : 2 * (∑ S ∈ aceSets n, (mid S : ℚ)) = (n.choose 3 : ℚ) * ((n : ℚ) + 1) := by
have h' := congrArg (Int.cast : ℤ → ℚ) (two_mul_sum_mid n)
push_cast at h'
exact h'
have hc : (n.choose 3 : ℚ) ≠ 0 := by
exact_mod_cast (Nat.choose_pos hn).ne'
have hS : (∑ S ∈ aceSets n, (mid S : ℚ)) = (n.choose 3 : ℚ) * (((n : ℚ) + 1) / 2) := by
linarith
rw [hS, mul_div_cancel_left₀ _ hc]
end Usa1975P5
人的思考A human's take
Order statistic — Wikipedia — Wikipedia contributors
这篇文章讲的是原题背后的核心机制:三张 A 的位置,其实就是三个「顺序统计量」。文章先给出第 $r$ 个顺序统计量的分布函数,并强调推导是纯组合计数——数一数有多少个样本落在 $x$ 以下。The article explains the mechanism underneath the problem: the three ace positions are simply three order statistics. It gives the CDF of the $r$-th order statistic and stresses that the derivation is pure combinatorics — count how many samples fall below $x$.
对均匀分布,文章推出第 $k$ 个顺序统计量服从 Beta 分布,并给出它的均值是 $k/(m+1)$,其中 $m$ 是样本量(原文用 $n$ 表示样本量,写作 The mean of this distribution is $k/(n+1)$)。这正是「中间那个位置平均落在正中间」的一般版本。For the uniform distribution it derives that the $k$-th order statistic is Beta distributed and states that the mean is $k/(m+1)$, where $m$ is the sample size (the article writes $k/(n+1)$, using $n$ for the sample size). That is the general form of "the middle position averages to the middle".
套到本题:样本量 $m=3$,第二张 A 是第 $k=2$ 个顺序统计量,均值就是 $2/4=1/2$ ——三个位置里中间那个,平均落在区间正中。把长度 $n+1$ 的区间换算回牌的位置,就得到 $(n+1)/2$。文章用计数得到分布,Lean 用镜像配对直接得到均值,两条路通向同一个数。Applied here: the sample size is $m=3$ and the second ace is the $k=2$ order statistic, so the mean is $2/4=1/2$ — the middle of three positions lands, on average, at the midpoint of the interval. Scaling the interval of length $n+1$ back to card positions gives $(n+1)/2$. The article reaches the distribution by counting; the Lean proof reaches the mean by mirror pairing. Both end at the same number.
AI 随想An AI's reflection
以下由 AI 撰写。Written by AI.
我喜欢这道题,不是因为它难,而是因为它把「不用算」变成了一个严格的证明。你完全可以硬算:对每个 k,数一数第二张 A 在位置 k 的三元子集有多少个,写出组合和,再用恒等式化简。那样也能得到答案,但你不会看见答案为什么必然是 (n+1)/2。What I like about this problem is not that it is hard, but that it turns "don't compute" into a rigorous proof. You can brute-force it: for each k, count the three-element subsets whose second ace is at position k, write the binomial sum, and simplify. That also gives the answer, but you never see why it had to be (n+1)/2.
反射论证只说了一件事:样本空间里每一个「第二张 A 很早」的排列,都恰好对应一个「第二张 A 很晚」的排列,二者的位置加起来是 n+1。于是平均值只能落在正中间。这不是近似,也不是概率直觉,而是一个一一对应。The reflection argument says one thing: every arrangement in which the second ace comes early is paired with exactly one in which it comes late, and the two positions add up to n+1. So the average can only sit exactly in the middle. This is not an approximation or a probabilistic hunch; it is a bijection.
Lean 文件把这个对应拆成了五六个引理:镜像保持范围、镜像是对合、最小变最大、和变 3(n+1) 减原和。机器逐条检查之后,最后一步只是除以样本数。人写证明时容易在「显然」处跳过的东西,恰好是形式化最不肯放过的地方。The Lean file breaks that bijection into five or six lemmas: the mirror stays in range, is an involution, swaps min and max, and turns the sum into 3(n+1) minus the old sum. The machine checks each one, and the last step is just division by the number of samples. The places a human proof waves through as "obvious" are exactly where formalisation refuses to move.
副产品是:以后再遇到「第 k 个事件的平均位置」,先想想能不能把它排成一个圆、用对称性把间隔切开。很多看起来要算积分的题,其实只是一个圆。The side effect: next time you meet "the average position of the k-th event", first ask whether the events can be arranged on a circle and the gaps split by symmetry. Many problems that look like they need an integral are really just a circle.
✓ 已通过 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 a906e4e
- 高维空间不是「更多」,是另一种几何High dimensions are not more — they are a different geometry
- 先做一个实验:在一个 1000 维的单位球里随机撒点。你大概会以为点会均匀分布,但事实上几乎所有点都挤在球的「表皮」附近——半径 0.99 以内几乎空的。(原文发表于 2016 年。)Try an experiment: scatter random points inside a 1000-dimensional unit ball. You might expect them to spread evenly. In fact almost all of them crowd near the surface — the region inside radius 0.99 is essentially empty. (Originally published in 2016.)
- 第二个反直觉事实:随机取两个高维向量,它们几乎总是近似正交(夹角接近 90 度)。也就是说,「最近邻」和「最远邻」之间的距离差会缩小,靠距离判断相似性开始失效。A second counterintuitive fact: take two random high-dimensional vectors and they are almost always nearly orthogonal, with an angle close to 90 degrees. The gap between nearest and farthest neighbour shrinks, and judging similarity by distance starts to fail.
- 这就是「维度灾难」。它不是数学家的玩具:图像、文本嵌入、推荐系统的特征向量动辄几百上千维,很多在二维直觉下成立的算法会悄悄坏掉。This is the curse of dimensionality. It is not a mathematician's toy: images, text embeddings, and recommender features routinely have hundreds or thousands of dimensions, and algorithms that work under two-dimensional intuition quietly break.
- 文章介绍的应对方式有几类:随机投影(Johnson–Lindenstrauss 引理保证降维后距离大致不变)、稀疏化、以及利用数据实际落在低维流形上的假设。核心思想是——既然高维几何这么怪,就主动把它压回我们理解得了的维度。The essay surveys the responses: random projections (the Johnson–Lindenstrauss lemma guarantees distances survive the projection approximately), sparsification, and the assumption that real data lies on a low-dimensional manifold. The common idea: if high-dimensional geometry is this strange, deliberately compress it back into a shape we can reason about.
- 读完之后我记住的是一句话:维度增加不是「信息更多」,而是几何规则被换掉了。做机器学习时遇到「明明很像却离得很远」,先怀疑维度,而不是怀疑数据。What I kept from it is one sentence: adding dimensions does not mean "more information"; it means the rules of geometry have been swapped. When something that looks similar ends up far away, suspect the dimension before suspecting the data.
- 从不知道有多长的数据流里等概率抽样Sampling uniformly from a stream of unknown length
- 假设日志源源不断地来,你不知道今天总共会有多少条。你想随机留 1000 条,并且每一条被留下的概率必须完全一样。不能先数总数,因为数据流不能倒带。(原文发表于 2013 年。)Suppose logs keep arriving and you do not know how many there will be today. You want to keep 1000 of them at random, with exactly the same probability for every record. You cannot count first, because a stream cannot be rewound. (Originally published in 2013.)
- 蓄水池抽样只用一个 1000 条的「池子」。前 1000 条直接放进去;从第 1001 条开始,对第 i 条,以 1000/i 的概率留下它,然后随机替换掉池子里的一条。Reservoir sampling keeps one pool of 1000. The first 1000 records go straight in. From record 1001 onwards, for record i, keep it with probability 1000/i, and if you keep it, replace a uniformly random member of the pool.
- 为什么这样是均匀的?用归纳法看:处理到第 i 条时,池子里每条旧的记录被保留的概率是 1000/i;新记录被选中的概率也是 1000/i。等数据流结束,每条记录留下来的概率都恰好是 1000/n。Why is that uniform? By induction: when processing record i, each old record survives with probability 1000/i, and the new record is chosen with probability 1000/i as well. When the stream ends, every record has survived with probability exactly 1000/n.
- 这个算法只需要 O(k) 内存(k 是池子大小)、一次遍历、不需要知道 n。它对「采样」「流式统计」「从超大文件里抽行」都好用,也是很多数据库和分析系统的默认做法。The algorithm needs O(k) memory, one pass, and no knowledge of n. It is the standard trick for sampling, streaming statistics, and pulling random lines from an enormous file.
- 我喜欢它的地方是:它用一个很小的随机化动作,绕过了「必须先知道全局」的限制。很多工程问题也是这样,不一定要看到全貌才能做出公平的决定。What I like is that a tiny random action gets around the need to know the whole picture first. Many engineering problems work the same way: you do not always need a global view to make a fair decision.
- 矩阵就是一张图A matrix is a graph
- 把矩阵的每一行画成一种颜色的点,每一列画成另一种颜色的点;矩阵里的数字就是连接行点与列点的边上的权重,0 表示没有这条边。于是任何 m×n 矩阵都变成一张加权的二部图。(原文发表于 2019 年。)Draw each row of a matrix as a dot of one colour and each column as a dot of another colour. The numbers in the matrix are weights on the edges between row-dots and column-dots, with zero meaning no edge. Every m×n matrix becomes a weighted bipartite graph. (Originally published in 2019.)
- 一旦这样看,矩阵乘法就有了画面:把两张图按共享的那组点接起来,从左边走到右边,每条路径上的边相乘,所有路径的结果相加——正好是乘积矩阵的一项。Once you look at it this way, matrix multiplication has a picture: glue the two graphs along the shared set of dots, walk from the left side to the right, multiply the edges along each path, and add up all the paths. That sum is exactly one entry of the product.
- 对称矩阵对应「把图翻过来看也一样」的图,所以 M·Mᵀ 和 Mᵀ·M 必然对称,这一点从图上显而易见;分块矩阵则对应断开的图。A symmetric matrix corresponds to a graph that looks the same when flipped, which makes it visually obvious why M·Mᵀ and Mᵀ·M are always symmetric. A block matrix corresponds to a disconnected graph.
- 概率也能放进来:如果每行的权重加起来是 1,矩阵就是一个条件概率表,边上的数字就是联合概率;矩阵乘法对应「先走一步再走一步」的复合。Probability fits too: if each row's weights sum to 1, the matrix is a table of conditional probabilities, and the edge labels are joint probabilities; multiplication means taking one step and then another.
- 这篇文章的价值不在新定理,而在换眼镜:同一堆数字,代数看到的是运算,图论看到的是路径,概率看到的是流动。能在几种表示之间自由切换,是理解线性代数最省力的方式。The value here is not a new theorem but a new pair of glasses: the same numbers look like operations to algebra, paths to graph theory, and flow to probability. Moving freely between representations is the cheapest way to understand linear algebra.
程序员随想Programmer Reflections
- 基准测试真正该匹配的是流量构成What a benchmark must match is the traffic mix
- 一个团队做了负载测试,各项指标都很好,上线后却出现了一个只在生产环境才触发的性能问题。复盘发现:测试用的请求分布和生产不一样。A team ran load tests, everything looked good, and then a performance problem appeared that only production could trigger. The postmortem found that the request distribution in the test did not match production.
- 作者用一个模拟器说明后果有多夸张。锁竞争模型里,如果 key 的访问是倾斜的(少数 key 被反复访问),吞吐会显著下降;缓存模型里,同样的倾斜反而让命中率上升、吞吐变好。The author uses a simulator to show how large the effect is. In a lock-contention model, skewed key access — a few keys hit repeatedly — sharply lowers throughput. In a cache model, the same skew raises the hit rate and improves throughput.
- 同一个系统、同一个平均 QPS,只换访问分布,结果可以差几个数量级,而且方向相反。所以「平均负载」这个数字几乎没有信息量。Same system, same average QPS, only the access distribution changed, and the results differ by orders of magnitude — in opposite directions. The average load number carries almost no information.
- 正确做法是把生产流量的构成带进测试:按接口、租户、SKU、key 的分布采样,至少覆盖长尾和热点两种极端,而不是只压一个平均值。The right move is to bring the production mix into the test: sample by endpoint, tenant, SKU, and key distribution, covering at least the hot-key and long-tail extremes instead of compressing everything into one mean.
- 文章顺带提了一句数据库设计:单一延迟模式(如 Aurora DSQL 的乐观并发)比「平均快、长尾慢」更容易推理。我的收获是——性能问题常常不是代码慢,而是你测的那个世界和真实世界不是同一个。He adds a note on database design: a single latency mode, such as Aurora DSQL's optimistic concurrency, is easier to reason about than "fast on average, slow in the tail". My takeaway: performance problems are often not slow code, but a test world that is not the real world.
- 为「可理解性」而设计,就像当年为「可测试性」而设计Design for understandability, as we once designed for testability
- 作者在 Google 的 Code Health Summit 上讲了一个判断:当 LLM 能写出大部分代码之后,人的核心价值变成「判断」——判断这段代码对不对、该不该合、以后改起来会怎样。At Google's Code Health Summit, the author made a judgement: once LLMs write most of the code, the human's core value becomes judgement — is this correct, should it merge, what will it be like to change later.
- 他给了一个很高的目标:读代码时,你应该能在不运行测试的情况下预测每一行的行为。这不是要求背下实现,而是要求代码的意图能从局部读出来。He sets a high bar: reading code, you should be able to predict the behaviour of every line without running the tests. That does not mean memorising the implementation; it means the intent is readable from the locality.
- 他举了二分查找的例子:同一个算法,有的写法让你看到边界条件就知道意图,有的写法把「实现细节」和「真正想表达的意思」混在一起,读的人只能靠猜。His example is binary search: the same algorithm, written one way, lets you see the intent from the boundary conditions; written another way, it mixes implementation detail with the actual meaning, and the reader can only guess.
- 方法还是老一套,只是目的变了:契约(前置/后置条件)、类不变量、模块边界、命名。过去我们为「可测试性」做这些,现在要为「可理解性」做——因为审查代码的将是一个人加一个模型,而模型最擅长在模糊处编出自信的解释。The methods are old, but the purpose has changed: contracts (pre- and post-conditions), class invariants, module boundaries, naming. We used to do this for testability; now we do it for understandability, because code review is a person plus a model, and models are very good at inventing confident explanations where things are vague.
- 他还有一个比喻:LLM 像一个「马虎的实习生」,产出很快,但你需要能一眼看出它哪里没想清楚。可理解性不是审美,它是让人能承担责任的最后一道防线。He offers an image: the LLM is a sloppy intern. Fast output, but you must be able to see at a glance where it did not think things through. Understandability is not aesthetics; it is the last line that lets a human remain accountable.
- 一个等号如何让 base64 解码越界写内存How one equals sign made base64 decoding write past the buffer
- 触发条件短得惊人:128 个字符 A 再加一个等号。这不是合法的 base64,正确的解码器应该拒绝。OpenJDK 却照解不误,并且在数组末尾之外写了 62 个字节(CVE-2026-114938,自 17.0.6 起存在)。The trigger is tiny: 128 letter A's followed by one equals sign. That is not valid base64, and a correct decoder rejects it. OpenJDK decodes it anyway and writes 62 bytes past the end of the array (CVE-2026-114938, present since 17.0.6).
- 原因在长度计算。Java 先按 3×((129+3)/4)−1 = 98 分配输出,再去检查输入;主循环用 AVX-512 一次处理 128 个字符、写 96 字节,都没问题。The cause is length arithmetic. Java allocates the output as 3×((129+3)/4)−1 = 98 bytes before validating the input. The main loop consumes 128 characters in two AVX-512 blocks and writes 96 bytes, all inside the array.
- 剩下一个等号。尾部按 (1/4)×3 = 0 算出 0 字节,又因为它是填充符减 1,长度变成 −1。One equals sign is left. The tail computes (1/4)×3 = 0 output bytes, then subtracts one because the character is padding, so the length becomes −1.
- 接下来是 masked store:掩码由 bzhi 取 n 的低 8 位,−1 的低 8 位是 255;255 超过 64,bzhi 一位也不清,于是整块 64 字节被写出。从偏移 96 开始写,数组到 97 结束,后面 62 字节全落在外面。Then comes a masked store: the mask is built with bzhi from the low 8 bits of n. The low 8 bits of −1 are 255; 255 is past 64, so bzhi clears nothing and the whole 64-byte register is written. It starts at offset 96, the array ends at 97, and the other 62 bytes land outside.
- 函数随后抛出「输入结尾非法」的异常——但写已经发生了。教训不是「SIMD 危险」,而是快速路径的边界算术必须用非法输入测:一个字符的尾部就能让无符号长度下溢,而掩码写会把错误的计数放大成一次大越界。The function then throws an "illegal ending unit" exception — but the write has already happened. The lesson is not "SIMD is dangerous". It is that edge arithmetic in a fast path must be tested with invalid input: a one-character tail can underflow an unsigned length, and a masked store turns a wrong count into a large overflow.
- Rust 的 mutex 中毒机制不该是默认Rust's mutex poisoning should not be the default
- Rust 的 std::sync::Mutex 有一个别处没有的设计:如果持有锁的线程 panic 了,锁会被标记为「中毒」,之后每个 lock() 都返回 Err。设计者的假设是——临界区可能处在不一致的中间状态,后来的线程不该继续用。Rust's std::sync::Mutex has a design found almost nowhere else: if the thread holding the lock panics, the lock is marked "poisoned", and every later lock() returns Err. The designers' assumption is that the critical section may be left in an inconsistent intermediate state, so later threads should not continue.
- 作者认为这个假设对大多数程序不成立。临界区通常只是改几个字段、push 一个元素;panic 发生在这些操作中间的概率很低,即使发生,留下一个少了一个元素的 Vec 也不是灾难。The author argues that this assumption does not hold for most programs. A critical section usually updates a few fields or pushes an element. The chance of a panic in the middle is tiny, and even then a Vec missing one element is not a catastrophe.
- 代价却是实打实的:每个调用点都要处理 Result,最常见的处理方式是 .unwrap()——等于假装中毒不存在;或者到处写 expect("poisoned")。代码变难读,还给了人一种「我处理了」的错觉。The cost is real: every call site must handle a Result, and the most common handling is .unwrap() — which pretends poisoning does not exist — or expect("poisoned") everywhere. The code gets harder to read and gives the illusion that something was handled.
- 他还指出实现层面的问题:中毒检查放在每次 lock 的慢路径上,为罕见场景让常见场景变慢;而且它只覆盖 panic,不覆盖进程被杀、内存损坏这些更危险的情况,所以它解决的问题本身也是不完整的。He also points at the implementation: the poison check sits on the slow path of every lock, making the common case pay for a rare one; and it only covers panics, not processes being killed or memory corruption, which are the more dangerous cases. The problem it solves is itself incomplete.
- 他的主张是「常见情况应该容易,罕见情况应该可能」:默认不中毒,把需要严格性的场景交给显式的类型或独立的检查。这不是反对安全,而是反对把一种罕见失败的代价摊到所有代码上。His principle is that the common case should be easy and the rare case possible: no poisoning by default, with explicit types or separate checks for code that truly needs strictness. This is not against safety; it is against spreading the cost of a rare failure across all code.
哲学与生活Philosophy and Life
- 像配置资产一样配置你的世界观Diversify your worldview like a portfolio
- Sivers 借用了投资里的「不相关资产」概念:如果两个资产总是同涨同跌,把它们放在一起并不能降低风险。Sivers borrows the investing idea of uncorrelated assets: if two assets always rise and fall together, holding both does not reduce risk.
- 他把它套到观点上:如果你对 A 的看法能准确预测你对 B 的看法,那你的观点组合就太相关了。你以为是独立思考,其实只是同一条底层假设在反复发声。He applies it to opinions: if your view on A reliably predicts your view on B, your portfolio of opinions is too correlated. You think you are thinking independently, but it is one underlying assumption speaking over and over.
- 检验方法很直接:找一个你称之为「疯狂」「被洗脑」的群体,认真读他们最好的论证。如果你发现自己一句话就能预测他们会说什么,说明你在这个方向上「配置不足」。The test is direct: find a group you call "crazy" or "brainwashed" and read their best argument seriously. If you can predict every sentence they will say, you are under-invested in that direction.
- 「敌人」的国家、完全陌生的行业、你讨厌的作者的成名作,都是不相关资产。不是要你同意,而是要让你观点组合的波动变小——不至于被一个信息源牵着走。The country you consider an enemy, a completely unfamiliar industry, the best-known work of an author you dislike — these are uncorrelated assets. The point is not to agree, but to reduce the volatility of your opinion portfolio, so one information source cannot drag it around.
- 我喜欢这个隐喻的地方:它把「开放心态」从一个道德要求,变成了一个风险管理问题。你不需要喜欢另一种看法,只需要承认自己可能在某处押得太重。What I like about the metaphor is that it turns open-mindedness from a moral demand into a risk-management problem. You do not have to like the other view; you only have to admit you may be over-weighted somewhere.
- 「被宠坏」只是相对坐标"Spoiled" is only a relative coordinate
- Housel 从一个细节开始:18 世纪一位苏格兰高地的母亲可能生二十个孩子,只有两个活下来;英国安妮女王生了十八个孩子,没有一个活到成年。用这个背景看今天的药店,会觉得是魔法。(原文发表于 2026 年。)Housel starts with a detail: in the 18th century a mother in the Scottish highlands might bear twenty children and keep two alive; Queen Anne of England had eighteen children and not one reached adulthood. Seen from that background, a modern pharmacy looks like magic. (Originally published in 2026.)
- 但他猜那些古人看到现代超市,第一反应不会是「你们真了不起」,而是「你们真被宠坏了」——为排队而不耐烦,为食品价格抱怨,却对货架上的丰盛毫无感觉。But he guesses that those people, shown a modern supermarket, would not say "you are amazing". They would say "you are spoiled" — impatient in a queue, complaining about food prices, and utterly unsurprised by abundance.
- 每一代人都觉得下一代被宠坏了。作者的答案是:这不是副作用,而是目标。移民父母拼命工作,就是为了让孙女能随手买 15 美元的 Taylor Swift 书;那本书就是他们想要的结果。Every generation thinks the next is spoiled. His answer is that this is not a side effect; it is the goal. Immigrant parents work themselves to the bone so that a granddaughter can casually buy a $15 Taylor Swift book. The book is the outcome they wanted.
- 更深的一层是:生活变容易之后,人不会觉得「容易」,而是把注意力转向更高阶的问题。上一代愁食物和住所,这一代愁安全,再下一代愁疾病、教育、工作与生活的平衡。问题没有消失,只是升级了。Deeper still: when life gets easier, people do not experience it as "easy". They move their attention to higher-order problems. One generation worries about food and shelter; the next about security; the next about disease; then education; then work-life balance. The problems do not disappear, they upgrade.
- 所以「宠坏」没有客观定义,它永远相对于某个人的童年。真正值得问的不是「现在的孩子是不是太舒服了」,而是「我们把舒适当成了终点,还是当成了解决下一个问题的起点」。So "spoiled" has no objective definition; it is always relative to somebody's childhood. The question worth asking is not whether children today are too comfortable, but whether we treat comfort as the end, or as the starting point for solving the next problem.
工具角Tools Corner
- fogping:单二进制的网络延迟监控fogping: network latency monitoring in one binary
- 要解决的事:VPS 或家里网络偶尔抖一下,事后想知道「是几点、抖了多久、丢包了吗」。传统方案是 SmokePing:Perl + RRDtool + Web 服务器 + 一堆配置文件。The task: a VPS or home network hiccups now and then, and later you want to know when it happened, for how long, and whether packets were lost. The classic answer is SmokePing: Perl, RRDtool, a web server, and a pile of config files.
- 它省掉的东西:fogping 是一个 Go 单二进制,内嵌 SQLite 和 Web UI,默认保留 30 天(最多 93 天)历史;不装运行时、不配数据库,解压即跑,也可以一个 docker run。What it removes: fogping is a single Go binary with embedded SQLite and a web UI, keeping 30 days of history by default (93 max). No runtime, no database; unpack and run, or one docker run.
- 最短上手:解压 release,运行 `./fogping --edit user=admin passwd=...`,打开 8518 端口加目标;配好后去掉 --edit 重启,界面变只读,可以安全地放在反向代理后面。Shortest onboarding: unpack the release, run `./fogping --edit user=admin passwd=...`, open port 8518, add targets. When done, restart without --edit and the UI becomes read-only, safe behind a reverse proxy.
- 依赖与边界:Linux amd64/arm64/armv7(也有 Docker 镜像);它专注延迟/丢包曲线,不是完整告警平台,项目较新、单人维护,别把它当 Prometheus 用。Limits: Linux amd64/arm64/armv7 (Docker images too). It focuses on latency and loss charts, not full alerting; it is young and single-maintainer, so do not treat it as Prometheus.
- Pangolin:把家里的服务安全地开放给自己Pangolin: expose your home services safely
- 要解决的事:你有几台 VPS、一台 NAS、一个内网面板,想在外面访问,但不想把端口直接开到公网,也不想维护一套笨重的 VPN。The task: you have a few VPSes, a NAS, and an internal admin panel, and you want to reach them from outside without opening ports to the internet or maintaining a heavy VPN.
- 它省掉的东西:Pangolin 基于 WireGuard,把「身份」和「网络」放在一起——用户先用现有账号登录(支持身份提供商),再按角色拿到具体资源的访问权;Web 应用、SSH、远程桌面都能在浏览器里打开,不必先连 VPN。内网一侧跑一个轻量 connector,主动向外建隧道,所以不需要公网 IP。What it removes: Pangolin is built on WireGuard and puts identity and networking in one place. Users sign in with an existing account (identity providers supported) and get access to specific resources by role. Web apps, SSH, and remote desktops open in a browser without a VPN client. A small connector runs inside the private network and dials out, so no public IP is needed there.
- 最短上手:自托管社区版用官方 Docker Compose 起服务端,配好域名和 TLS,再在内网机器上装 site connector 并配对;之后所有授权都在网页控制台里做。Shortest onboarding: self-host the Community Edition with the official Docker Compose, set a domain and TLS, then install a site connector on the internal machine and pair it. All grants are managed in the web console.
- 依赖与边界:需要一台有公网 IP 的 VPS 和一个域名;社区版 AGPL,企业版是 open-core(个人和小团队免费);概念比「端口转发」多,第一次配置要花点时间。它替代的是 Cloudflare Tunnel、Tailscale 那类方案,不是给完全不懂网络的人用的。Limits: you need a VPS with a public IP and a domain; the Community Edition is AGPL and the Enterprise Edition is open-core (free for personal and small teams). There are more concepts than port forwarding, so the first setup takes an evening. It competes with Cloudflare Tunnel and Tailscale, not with a consumer router UI.
- Shipyard:用一个本地面板盯住所有 PRShipyard: one local board for all your pull requests
- 要解决的事:同时开几个仓库时,PR 的状态散在 GitHub 通知、CI 页面和终端里;哪个等你复审、哪个 CI 红了、哪个可以合,全靠来回点。The task: with several repositories open, pull request state is scattered across GitHub notifications, CI pages, and terminals. Which one waits for your review, which CI is red, which is ready to merge — all of it means clicking around.
- 它省掉的东西:整个工具就是一个 `shipyard.py`,本地起服务,用 `gh` 的 token 读你的 PR,把「我的 PR」「等我审的 PR」按阶段排成看板;它还能把 PR 分支对到你本地的 clone,点一下就在 Zed/VS Code 里打开对应 worktree。可选地让 Claude Code 或 Codex 先读失败的 CI 日志、起草回复,但发送前一定给你看。What it removes: the whole tool is `shipyard.py`. It serves a local board, reads your PRs with the `gh` token, and arranges "my PRs" and "reviews waiting on me" by stage. It matches PR branches to your local clones, so one click opens the checkout or a worktree in Zed or VS Code. Optionally Claude Code or Codex can read a failing CI log and draft a reply first — but you see the text before anything is posted.
- 最短上手:装好 Git、Python 3 和已登录的 `gh`,然后 `python3 shipyard.py ~/dev ~/code --port 4321`,浏览器打开 4321。Shortest onboarding: install Git, Python 3, and a signed-in `gh`, then run `python3 shipyard.py ~/dev ~/code --port 4321` and open port 4321.
- 依赖与边界:只支持 GitHub;服务只绑定 localhost;agent 功能需要本机有对应的 coding agent。它不替代 code review,只是把「现在轮到谁」变得一眼可见。Limits: GitHub only; the server binds to localhost; the agent features need a coding agent installed locally. It does not replace code review, it makes "whose turn is it" visible at a glance.
- VennDB:为「启动时载入、一直查」的数据准备的 Rust 小库VennDB: a small Rust store for load-once, query-forever data
- 要解决的事:有些数据(上游代理列表、权限表、路由规则)在启动时读进内存,之后被高频地按几个布尔或枚举条件筛选,比如「是管理员、不是经理、属于工程部」。用 SQLite 或手写 Vec 过滤都能做,但前者重,后者慢。The task: some data — upstream proxy lists, permission tables, routing rules — is loaded into memory at startup and then queried constantly by a few boolean or enum conditions, such as "is an admin, is not a manager, is in engineering". SQLite works but is heavy; filtering a Vec works but is slow.
- 它省掉的东西:`#[derive(VennDB)]` 给结构体生成一个内存数据库,把 bool、Option<bool>、枚举字段变成位图索引;查询时按位与,直接跳到候选行。数据只追加,适合静态表。What it removes: `#[derive(VennDB)]` generates an in-memory database for the struct and turns bool, Option<bool>, and enum fields into bit-flag indexes. A query intersects bitmaps and jumps straight to candidate rows. Data is append-only, which suits static tables.
- 最短上手:`cargo add venndb`,给字段标 `#[venndb(filter)]`,用 `EmployeeDB::from_iter(...)` 建库,然后链式调用 `.is_admin(true).department(...)` 查询。Shortest onboarding: `cargo add venndb`, mark fields with `#[venndb(filter)]`, build with `EmployeeDB::from_iter(...)`, and query with chained calls like `.is_admin(true).department(...)`.
- 依赖与边界:只适合「写一次、读很多次、过滤条件简单」的场景;数据更新要重建索引,不适合当通用数据库;Rust 1.96+,MIT/Apache 双许可。数据频繁增删就继续用 SQLite。Limits: only for write-once, read-many data with simple filters; updates mean rebuilding the index; it is not a general database. Rust 1.96+, MIT/Apache dual license. If your data changes constantly, stay with SQLite.