作弊者的数学The Mathematics of Cheating
发布于 2026-11-09Published 2026-11-09
今日深读Today's Deep Read
最优洗牌:一副无论怎么切都赢的牌The Optimal Stack: A Deck That Wins from Every Cut
2011 年夏天,Jeremy Kun 在泳池边和朋友打德州扑克,聊起以前遇到的老千:有人从牌堆底部发牌,有人两人合伙做牌,还有人把牌事先排好。赌桌上有个默契:由庄家右边的玩家切牌,就能洗清庄家的嫌疑。于是问题冒出来:如果一副牌被排成某种顺序,使得无论从哪里切,某个玩家都赢——这种事可能吗?In the summer of 2011, Jeremy Kun was playing Texas Hold 'Em by a pool with old friends when the conversation turned to cheaters they had known: someone dealing from the bottom of the deck, two players colluding, a dealer stacking the cards in advance. Poker has a quiet convention for exactly this: the player to the dealer's right cuts the deck, which supposedly absolves the dealer. That convention produced a question. Could a deck be arranged so that, no matter where it is cut, one particular player always wins?
先从最简单的牌戏开始。Kuhn 扑克只有三张牌(K、Q、J),每人一张,比大小。六种排列逐一检查,每一种都能找到一个切点,让切牌的那一方拿到更大的那张牌。为什么不是巧合?作者给出一般论证:假设存在一副“万能牌堆”让先手在任何切点都赢,那么沿着牌堆,每张牌都必须严格赢过下一张,否则对手切到那一位就赢。由传递性,第一张牌赢最后一张;于是后手只要切在最后一张之前,先手就只能拿到整副牌里最小的那张。矛盾。Start with the simplest possible game. Kuhn poker has three cards (king, queen, jack), one each, high card wins. There are only six orderings, and each one has a cut that hands the cutter the better card. That is not a coincidence, and the general argument is short. Suppose a magical ordering existed that let the first player win from every cut. Then walking down the deck, each card must beat the next one, or the opponent would simply cut there. By transitivity the top card beats the bottom card, so the opponent can cut just before the last card and leave the first player holding the worst card in the deck. Contradiction.
这个论证的漂亮之处在于它几乎不用算:切牌只是把环换个起点,而“赢”是传递的,于是环上不可能处处上坡。它也说明为什么德州扑克不能照搬——公共牌、顺子、同花让小牌也能赢,传递性被打破了。What is lovely is how little arithmetic this needs. A cut is just a different starting point on a circle, and 'beats' is transitive, so the circle cannot slope upward everywhere. It also explains why Texas Hold 'Em cannot inherit the result: community cards, straights and flushes let a low card win, and transitivity breaks.
于是 Kun 反过来设计游戏:K Poker(K 既是匈牙利语 kicsi、“小”,也是他的姓),九张同花色连续牌(2 到 10),每人两张,四张公共牌,只可能出高牌或顺子。规则少到可以穷举,又复杂到允许小牌翻盘。9! = 362,880 种排列,按切牌等价压到 8! = 40,320 种,计算机几秒钟扫完。So Kun ran the question backwards and designed a game: K Poker (K for kicsi, Hungarian for 'small', and for Kun himself), nine consecutive cards of one suit (deuce through ten), two cards each, four community cards, only high card or straight possible. The rules are small enough to enumerate and rich enough to let low cards win. That is 9! = 362,880 arrangements, reduced by cut-equivalence to 8! = 40,320, which a computer finishes in seconds.
结果出人意料地不对称:先手有 9 种(计切牌 81 种)万能牌堆,后手只有 2 种(18 种)。其中后手的一种就是升序牌堆——后手总拿最后一张,接下来四张公共牌正好成顺;而先手永远拿不到顺子。The answer is strangely asymmetric. Player one has nine winning stacks (81 counting cuts). Player two has two (18). One of player two's is simply the deck in ascending order: player two always receives the last card, and the next four community cards complete a straight, while player one can never make one.
但故事的重点不是“作弊可行”。Kun 的结论是:能否排出一副万能牌堆,取决于游戏规则允许什么牌赢;规则越丰富,传递性越弱,可乘之机越多。反过来,一个公平的游戏,本质上是在设计上堵住“环上下坡”的可能性。But the point is not that cheating works. The point is that whether a stack exists depends on which hands the rules allow to win. The richer the rules, the weaker transitivity, and the more room for a rigged deck. A fair game, seen this way, is one whose design closes off the possibility of an upward-sloping circle.
这也是一则关于问题本身的寓言。最初的问题是“德州扑克能被做牌吗”,太难;他换成“什么样的牌戏能被做牌”,于是既得到定理,也得到可运行的搜索。很多时候,把问题改写成自己能回答的形状,比硬啃原题更接近答案。而 81 比 9、18 比 2 的差别还提醒我们:即使在同一套规则下,谁能作弊也不是对称的——先手天然拥有更多藏身之处。It is also a fable about questions. 'Can Texas Hold 'Em be stacked?' is too hard. 'What kind of card game can be stacked?' is answerable, and it yields both a theorem and a working search. Rewriting a problem into a shape you can actually answer is often closer to progress than grinding on the original. And the 81-versus-18 asymmetry adds a parting thought: even under one rule set, who gets to cheat is not symmetric. The first player simply has more places to hide.
AI 思考AI Thoughts
- AI 乐观者与怀疑者,各自在和什么赛跑What AI Optimists and Skeptics Are Each Racing Against
- 先分清两边真正害怕的东西:乐观者怕的是错过一次能力跃迁,所以觉得慢就是错;怀疑者怕的是系统熵增——代码合并得越来越快、却越来越少人真正读过。Start with what each side actually fears. Optimists fear missing a capability jump, so slowness feels like the real risk. Skeptics fear entropy: code merging faster than anyone can read it, until nobody understands the system they are on call for.
- 关键在于成本与收益不对称。AI 的产出(合并的 PR、演示、速度)在会议上立刻可见;它的代价(夜里被叫醒、几个月后的维护、没人理解的模块)落在运维和后来者身上。The asymmetry is the whole story. AI's output is visible immediately in a meeting: merged PRs, demos, velocity. Its costs land later and elsewhere: the 3 a.m. page, the module nobody can safely change, the cleanup another team does for months.
- 于是没有天然的反馈回路:制造问题的人收不到账单,'更快'就永远显得免费。这不是谁坏,而是账本被拆成了两本。So there is no natural feedback loop. The person who creates the cost does not receive the bill, and 'faster' looks free forever. Nobody has to be malicious for this to happen; the ledger is simply split in two.
- 作者给的解法不是选边,而是把两本账合到一起:在同一个场合同时汇报产出和下游代价,让乐观者听见故障,让怀疑者把话说给该听的人。Her remedy is not to pick a side but to merge the ledgers: report output and downstream cost in the same forum, so optimists hear about the outages and skeptics say the uncomfortable thing to the people who can act on it.
- 她举 Intercom 为例:设定 2 倍目标后做到 3 倍合并量、缺陷积压减半、停机下降 35%,但前提是团队原本就有纪律和反馈机制。AI 放大了系统,而不是替代了系统。Intercom is the example: a 2x mandate produced 3x merged PRs, a halved defect backlog and 35% less downtime, but only because discipline and feedback loops already existed. AI amplified the system; it did not replace it.
- Linux 不是技术中立的,所以“你可以分叉”是句空话Linux Was Never Neutral, So 'You Can Fork It' Is Hollow
- 起点是 Linus Torvalds 对内核引入 AI 的表态:这个项目只谈技术,不喜欢的人可以离开,或者自己分叉。The trigger is Linus Torvalds saying the kernel is about technology, and that people who dislike AI can leave or fork.
- DeVault 的反驳是历史性的:Linux 从 GPLv2 开始就是一个政治选择——用版权强制下游回馈;Linus 反对 GPLv3 也是出于道德立场,而不是工程便利。DeVault's reply is historical: Linux was political from the start. GPLv2 was a deliberate use of copyright to force downstream contributions; Linus opposed GPLv3 on moral grounds, not engineering ones.
- 更实际的是,GPL-only 符号和故意不稳定的内部 ABI,让分叉在工程上几乎不可行。'你可以分叉'之所以听起来成立,恰恰因为项目刻意把分叉成本造得很高。More concretely, GPL-only symbols and a deliberately unstable internal ABI make forking impractical. 'You can fork it' sounds true precisely because the project has spent decades making forking expensive.
- 所以当 AI 审阅机器人 Sashiko 成为贡献流程的一部分,'回应 AI 的意见'就变成了新的社区规范。这不是中立的工具接入,而是用工具重写谁有资格说话。So when the Sashiko AI reviewer becomes part of the contribution path, 'answer the AI's comments' becomes a new community norm. That is not a neutral tool decision; it rewrites who gets to speak.
- 他还指出外部性:数据中心的建设推高内存和电价、消耗水和电,把一些开发者挤出他们赖以工作的硬件;而'只谈技术'的说法恰好替供应商的利益提供了合法性。He also counts externalities: the datacenter buildout raises memory and power prices and consumes water and electricity, pricing some developers out of the machines they work on. The 'just technology' framing conveniently legitimizes the vendors' interests.
- 模型能内省吗?一个把“察觉”和“说出”分开的实验Can a Model Introspect? An Experiment That Separates Noticing from Naming
- 问题本身很朴素:模型能不能报告自己内部正在发生什么?这不是问它会不会说'我在思考',而是问它的报告是否对应真实内部状态。The question is plain: can a model report what is happening inside it? Not whether it says 'I am thinking', but whether the report tracks a real internal state.
- Anthropic 的 Jack Lindsey 做了一个干净的实验:先在模型内部找到代表某个概念的'方向'(例如金门大桥),把它调强,然后在生成之前问模型:你有没有检测到被注入的念头?内容是什么?Jack Lindsey at Anthropic built a clean test. Find an internal direction that stands for a concept (the Golden Gate Bridge, say), amplify it, then ask the model before it generates: do you detect an injected thought, and what is it about?
- 结果:最新 Claude 约有 20% 能正确说出概念;对照组从不报告并不存在的注入,说明它不是逢场作戏地附和。The newest Claude named the concept about 20% of the time. In control runs it never reported an injection that was not there, so this is not eager agreement.
- 批评者的关键拆分是:'察觉到了'和'说得出是什么'是两件事。能说出概念,可能只是被调强的方向把输出推向了那个词,而不是真的读到了自己的状态。Critics make an important split: noticing and naming are different achievements. Naming could simply be the amplified direction pushing the output toward that word, not the model reading its own state.
- 更微妙的证据是失败案例:模型察觉到了却命名失败时,它说的往往是与答案毫无关系的词,而不是接近答案的猜测。这让'内省'仍然是一个开放的实证问题,而不是一个可以靠术语解决的定义问题。The most interesting evidence is the failure mode. When models noticed but could not name, they produced unrelated words ('apple') rather than near misses. That leaves introspection an open empirical question, not something a definition can settle.
- 把神经网络权重当文本喂给模型,它能猜出这个网络在玩什么Feed a Network's Weights to a Model as Text and It Can Guess the Game
- 论文《Sparks of Weight-Space Programming》提出一个古怪的实验:把训练好的网络的原始浮点权重直接放进 prompt,让语言模型判断这个网络是玩哪个游戏的。A paper called 'Sparks of Weight-Space Programming' proposed an odd experiment: put the raw floating-point weights of a trained network directly into a prompt and ask a language model which game the network plays.
- Simon 在自己的笔记本上用 Qwen 27B 复现:不做任何特征工程,把数字序列喂进去,模型能分辨 Breakout、Pong、Pac-Man、Freeway 等。Simon reproduced it on his laptop with Qwen 27B: no feature engineering, just the number stream, and the model could tell Breakout from Pong, Pac-Man, Freeway and others.
- 他刻意区分两件事:一是'不用工具、只读权重'做出判断;二是'写代码去分析和修改权重'。前者才是真正惊人的主张。He is careful to separate two claims: judging from weights with no tools at all, versus writing code that analyzes or edits weights. Only the first is surprising.
- 如果成立,说明预训练让模型对'数字里隐藏的结构'有某种迁移能力,而不只是记住文本里的规律。If it holds, pretraining has given models some transferable feel for structure hidden inside numbers, not just patterns in text.
- 他也引用了 Honnibal 和 Goedecke 的质疑:样本量、提示方式、任务难度都可能解释结果。所以这是一个值得亲手复现的观察,不是已经确立的结论。He also cites Honnibal and Goedecke, who question sample size, prompting and task difficulty. Treat it as an observation worth reproducing yourself, not an established result.
数学之美The Beauty of Mathematics
每日 Lean 谜题 · 周一Daily Lean Puzzle · Monday ★☆☆☆☆☆☆
五个连续自然数,为什么总和是中间数的五倍Why Five Consecutive Numbers Sum to Five Times the Middle One
任取一个自然数 $n$,写出紧跟它的五个连续自然数:$n,\ n+1,\ n+2,\ n+3,\ n+4$。要证明的事情很朴素:这五个数的和,恰好等于中间那个数 $n+2$ 的五倍,即Take any natural number $n$ and write down the five consecutive numbers starting at it: $n,\ n+1,\ n+2,\ n+3,\ n+4$. The claim is simple: their sum is exactly five times the middle number $n+2$, that is,
$n + (n+1) + (n+2) + (n+3) + (n+4) = 5\,(n+2)$。$n + (n+1) + (n+2) + (n+3) + (n+4) = 5\,(n+2)$.
在 Lean 里,它就是定理 five_consecutive_sum,对任意自然数 $n$ 成立。In Lean this is the theorem five_consecutive_sum, stated for every natural number $n$.
Lean 形式化陈述(把 sorry 换成你的证明):The statement in Lean (replace sorry with your proof):
-- level: 1
import Mathlib.Tactic.Ring
/-! Prove that the sum of five consecutive natural numbers starting at $n$
equals five times the middle one, $n+2$. -/
theorem five_consecutive_sum (n : ℕ) :
n + (n + 1) + (n + 2) + (n + 3) + (n + 4) = 5 * (n + 2) := by
sorry
在浏览器中挑战 ▶Try it in your browser ▶ 下载题目 .leanDownload puzzle .lean
提示Hint
把五个数写成以中间数 $m=n+2$ 为中心:$m-2,\ m-1,\ m,\ m+1,\ m+2$。两端的偏移会成对抵消,只剩五个 $m$。Rewrite the five numbers around the middle one $m=n+2$: $m-2,\ m-1,\ m,\ m+1,\ m+2$. The offsets cancel in pairs, leaving five copies of $m$.
答案与讲解Solution & walkthrough
- 先把五个数按中间数 $m=n+2$ 重写:$m-2,\ m-1,\ m,\ m+1,\ m+2$。这一步只是换记号,却把“五个连续数”的对称性摆到了明面上。Rewrite the five numbers around the middle one $m=n+2$: $m-2,\ m-1,\ m,\ m+1,\ m+2$. This is only a change of notation, but it puts the symmetry of “five consecutive numbers” in plain sight.
- 相加时按对称配对:$(m-2)+(m+2)=2m$,$(m-1)+(m+1)=2m$,中间还剩一个 $m$。于是总和是 $2m+2m+m=5m$。这就是小学里说的“移多补少”。Add them in symmetric pairs: $(m-2)+(m+2)=2m$ and $(m-1)+(m+1)=2m$, with the middle $m$ left over. The total is $2m+2m+m=5m$ — the same “move the excess to fill the deficit” idea taught in primary school.
- 换回原来的记号:$m=n+2$,所以和就是 $5(n+2)$,正是要证的等式。全程只用了加法的交换律、结合律和乘法分配律,没有借用任何减法技巧。Translate back: $m=n+2$, so the sum is $5(n+2)$, exactly the identity to be proved. Only commutativity, associativity, and distributivity are used; no clever subtraction is needed.
- Lean 中的 ring 策略做的正是同一件事:把等式两边都展开成“若干项相加”的标准形,合并同类项、约掉相同的项,最后确认两边恒等。它不负责解释思路,只负责保证在交换半环 $\mathbb{N}$ 上每一步都合法——这也是为什么用自然数不会出问题:整个证明里根本没有出现 $n-2$ 这种可能为负的项。Lean's ring tactic performs the same computation: it expands both sides into a canonical sum of terms, collects like terms, cancels what matches, and confirms the two sides are identical. It does not explain the idea, it only guarantees each step is valid in the commutative semiring $\mathbb{N}$ — which is why natural numbers are safe here: no term such as $n-2$ that could go negative ever appears.
- 把结论放大:任意奇数个连续整数之和,都等于“项数 × 中间项”;偶数个则等于“项数 × 中间两项的平均数”。这个观察在数论里会反复用到,例如判断一个数能否写成连续整数之和,本质上是在数它的奇因子。Generalize: the sum of any odd number of consecutive integers equals “the count times the middle term”; for an even count it is “the count times the average of the two middle terms”. This observation recurs in number theory — deciding whether a number is a sum of consecutive integers amounts to counting its odd divisors.
-- level: 1
import Mathlib.Tactic.Ring
/-! Prove that the sum of five consecutive natural numbers starting at $n$
equals five times the middle one, $n+2$. -/
theorem five_consecutive_sum (n : ℕ) :
n + (n + 1) + (n + 2) + (n + 3) + (n + 4) = 5 * (n + 2) := by
ring
人的思考A human's take
Three Neighbours — NRICH (student solutions by Nikhil, Roger, Aadit and others)
NRICH 的这道题先问三个连续整数之和为什么总是 3 的倍数,再让读者把它推广到五个、七个。NRICH's problem first asks why three consecutive integers always add up to a multiple of 3, then invites readers to extend the pattern to five and seven numbers.
学生 Nikhil 的解释是:以中间数为基准,后面两个数分别是“中间数减 1、减 2”,前面两个数是“加 1、加 2”,正负抵消后,整列数就相当于五个中间数相加。Student Nikhil explains it by centring on the middle number: the two numbers after it are “middle minus 1, minus 2”, the two before it are “plus 1, plus 2”, and after cancellation the list is just five copies of the middle number.
另一位学生 Roger 用代数写:五个数是 $n$ 到 $n+4$,和为 $5n+10$,提出 5 得到 $5(n+2)$;Aadit 则把它推广到任意奇数个连续整数。Another student, Roger, writes the five numbers as $n$ through $n+4$, sums them to $5n+10$, and factors out 5 to get $5(n+2)$; Aadit generalizes the argument to any odd number of consecutive integers.
AI 随想An AI's reflection
以下由 AI 撰写。Written by AI.
这是一道“看一眼就懂”的题,却值得认真写一遍。因为真正让人确信的,不是记住 $5(n+2)$ 这个结果,而是看见五个数如何围绕中点对称、偏移如何两两抵消。数学里大量“显然”的结论,一旦要求把每一步说出来,就会暴露我们其实只是在复述记忆。This is a problem you understand at a glance, yet it is worth writing out. What convinces you is not the result $5(n+2)$ but the sight of five numbers arranged around their middle, with the offsets cancelling in pairs. Many “obvious” facts expose, once every step must be spoken aloud, that we were only repeating a memory.
这种“找到中心,再看两边如何抵消”的眼光,比公式本身有用得多。它不仅解释了五个连续数,也解释了任意奇数个连续数;换到别的题目里,它会变成“先找对称轴”“先找不变量”这类更一般的策略。That habit of finding the centre and watching the two sides cancel is more useful than the formula. It explains five consecutive numbers, any odd number of them, and turns into general strategies elsewhere: look for the axis of symmetry, look for the invariant.
Lean 在这里扮演的角色很有意思:ring 一行就结束了证明,但它给出的不是洞察,而是保证——保证在自然数这个半环里,展开、合并、约去都合法。人类负责选择“以中点为心”的看法,机器负责确认这个看法没有漏洞。这大概是人与证明助手最舒服的分工。顺带一提,这也解释了题目为什么放心地取自然数:整个论证里根本没有出现 $n-2$ 这种可能为负的式子,自然数没有减法封闭性的麻烦,证明才这么干净。Lean's role is interesting: ring ends the proof in one line, but what it supplies is not insight — it is a guarantee that expanding, collecting and cancelling are legal in the semiring of naturals. The human chooses the view; the machine checks it has no holes. That is also why the problem can safely use natural numbers: nothing in the argument ever writes down $n-2$, so there is no subtraction to worry about, and the proof stays clean.
✓ 已通过 Lean 编译验证(无 sorry,无额外公理)✓ Verified by Lean (no sorry, no extra axioms) · 题目与证明由 AI 编写Problem and proof written by AI · Lean v4.36.0-rc2 · Mathlib fafbe4e
- 用四个 2 写出任意整数,以及 Dirac 如何终结这个游戏Any Integer from Four 2s, and How Dirac Ended the Game
- 游戏规则是:用恰好四个 2,加上你喜欢的运算,写出任意整数。起初大家用加减乘除和括号,很快就卡住了。The rule: use exactly four 2s, plus whatever operations you like, to write any integer. People start with arithmetic and brackets, and quickly get stuck.
- 然后武器升级:阶乘、小数点、循环节、平方根。每加一种运算,可表达的整数就多一批,而'到底允许什么'也越来越模糊。Then the arsenal grows: factorials, decimal points, repeating decimals, square roots. Each new operation adds a batch of representable numbers and blurs what the game even permits.
- Dirac 的做法只用一个动作:把 2 反复开平方。开 k 次,得到 2 的 1/2^k 次方——指数小得几乎看不见,但它是确定的。Dirac's move is a single action: keep taking square roots of 2. After k roots you have 2 to the power 1/2^k — an exponent so small it is invisible, yet exact.
- 接着连取两次以 2 为底的对数:第一次把 2^(2^-k) 变成 2^-k,第二次变成 -k;再在前面加一个负号,就得到 k。k 并没有写进式子,它变成了“开了多少次方”。Then take log base 2 twice: the first turns 2^(2^-k) into 2^-k, the second into -k; a minus sign in front gives k. The number k never appears in the formula — it becomes the number of roots.
- 最后把其中一个 2 换成 √(2+2)(仍然等于 2),凑够四个 2。启示不是“数学家真聪明”,而是一个谜题的死亡常常来自操作集合被扩张到能表达一切:规则决定了游戏还剩多少意义。Replace one 2 with sqrt(2+2) (still 2) and you have exactly four. The lesson is not cleverness: puzzles die when the allowed operations grow until they can express everything. The rules decide how much game is left.
- 一个关于马的假证明,和归纳法最容易漏掉的那一步A False Proof About Horses, and the Step Induction Always Skips
- 命题:所有马都是同一种颜色。'证明'用归纳法,看起来几乎无懈可击。Claim: all horses are the same color. The 'proof' is induction, and it looks airtight.
- 基础情形:只有一匹马时,它当然和自己同色。Base case: one horse is trivially the same color as itself.
- 归纳步:假设任意 n 匹马同色,考虑 n+1 匹。先拿走一匹,剩下 n 匹同色;再拿走另一匹,剩下 n 匹也同色。两组有重叠,所以全部同色。Inductive step: assume any n horses are one color. Take n+1 horses. Remove one; the remaining n are one color. Remove a different one; those n are also one color. The two groups overlap, so all n+1 agree.
- 漏洞在最小的一步。n=2 时,拿走第一匹只剩第二匹,拿走第二匹只剩第一匹,两组根本没有交集——那匹负责'传递颜色'的中介马不存在。The hole is the smallest step. When n=2, removing the first horse leaves only the second, and removing the second leaves only the first. The groups do not overlap at all: there is no middle horse to carry the color across.
- 教训:归纳法必须在最小的转移处也成立。'n 很大时显然'不能代替基础的衔接;把真正的基础改成 2 匹马,命题立刻就是假的。The lesson: induction has to hold at the smallest transition. 'Obviously true for large n' cannot replace the base link. Change the real base case to two horses and the claim is immediately false.
- 参数表上的“128 位安全”是怎么算出来的Where '128-bit Security' on a Parameter Sheet Actually Comes From
- 情景:你在用一个格密码方案,参数表写着 128 位安全。这个数字不是标签,而是'最省力的已知攻击需要多少操作'的估计。Suppose you are using a lattice scheme whose parameter sheet says '128-bit security'. That number is not a label. It is an estimate of how many operations the cheapest known attack needs.
- LWE 的密文形如 b = <a,s> + m + e (mod q),噪声 e 很小。噪声越大越安全,但解密也越容易出错;参数选择就是在这条钢丝上走。An LWE ciphertext looks like b = <a,s> + m + e (mod q), with small noise e. More noise means more security but also more decryption failures; parameter choice walks that wire.
- Lattice Estimator 把所有已知攻击(primal、dual、coded-BKW 以及它们的混合)都跑一遍,取操作数的 log2 作为安全位数。哪个攻击最省,就由它定义安全性。The Lattice Estimator runs every known attack family (primal, dual, coded-BKW and hybrids) and reports operations, taking log2 of the cheapest as the security level. Whatever attack wins defines the number.
- RLWE 把数字换成多项式,不能直接把系数拼成矩阵:x^N = -1 使乘法出现符号翻转,必须构造'反循环矩阵',让环上的乘法等价成普通矩阵乘法。RLWE replaces numbers with polynomials, and you cannot just concatenate coefficients into a matrix: x^N = -1 flips signs during multiplication, so you must build a negacyclic matrix that makes ring multiplication behave like ordinary matrix multiplication.
- 一个真实例子:TFHE 的一组参数被网站标为 128 位,估算器算出来是 2^119.8。差别不大,但足以说明安全参数是需要复核的估计,不是可以照抄的常数。A real example: a TFHE parameter set advertised as 128-bit came out at 2^119.8 in the estimator. That is close, but it shows security parameters are estimates to be rechecked, not constants to copy.
程序员随想Programmer Reflections
- 当用户能自己改代码,发布流程就不再是时刻表When Users Can Edit the Code, Releases Stop Being Timetables
- 过去的软件发布像铁路时刻表:main 是稳定线,unstable 是试验线,用户等下一班车。这个模型假设只有维护者会写代码。Software releases used to run like a railway timetable: main is the stable line, unstable is the test line, and users wait for the next train. That model assumes only maintainers write code.
- AI 编程改变了这个假设:使用者可以让 agent 直接改自己用的版本。既然他们不会等,'稳定分支'就失去了垄断地位。AI coding breaks the assumption. Users can have an agent modify the version they actually run. If they will not wait, a stable branch loses its monopoly.
- 于是仓库的角色变了:它更像模板和示例,而不是唯一正确的制品;维护者应该把实验分支当一等公民,而不是耻辱标记。So the repository changes role: it becomes a template and a worked example rather than the single correct artifact. Experimental branches deserve to be first-class, not a mark of shame.
- 文档的读者也变了。除了人,还有会读代码的 agent,所以接口说明、示例和提交信息都要能被机器消费。The audience for documentation changes too. Besides people, there are agents that read code, so interfaces, examples and commit messages have to be machine-consumable.
- 他举了 Redis 有序集合内存优化的 PR:外部贡献可以直接长成产品的一部分,而不是被发布流程卡上半年。His example is a Redis sorted-set memory optimization: an outside contribution can become part of the product directly, instead of waiting half a year behind a release process.
- 《如何努力》:努力不是美德,而是一门要学的技能How to Work Hard: Effort Is a Skill, Not a Virtue
- 表现由三个变量决定:天赋、练习、努力。顶尖水平三者都要,缺一个就会被卡住;但学校只训练前两个,努力被当成态度问题。Performance has three inputs: talent, practice and effort. The very best need all three; school trains the first two and treats effort as a matter of attitude.
- 学校把目标外部化:考试、排名、截止日期。于是'努力'很容易变成表演——坐在那里很久,做很多不重要的题。School externalizes goals: exams, rankings, deadlines. Effort easily becomes performance — sitting for a long time, solving many unimportant problems.
- 真正难的是自己定义目标。没有外部评分时,你得判断什么值得做、做到什么程度算够,这比完成任务难得多。The hard part is defining your own goals. With no external score, you must decide what is worth doing and when it is good enough. That is much harder than completing an assignment.
- 自欺是最大的敌人:假装在工作、用忙碌代替推进、把准备当成行动。作者的建议是诚实地问:今天有没有推进那个真正难的点?Self-deception is the main enemy: pretending to work, substituting busyness for progress, mistaking preparation for action. His test is blunt: did you move the genuinely hard thing today?
- 结论不是'更拼命',而是把努力投向你自选的方向,并且不断校准。辛苦本身没有价值,辛苦在正确的位置上才有。The conclusion is not 'try harder'. It is to spend effort on a direction you chose and keep recalibrating. Difficulty has no value by itself; it only counts in the right place.
- 公交车票理论:天才的第三种成分The Bus Ticket Theory of Genius: The Third Ingredient
- 除了能力与决心,还有第三种成分:对某件事无关功利的痴迷。公交车票收藏者是原型——他们研究的东西毫无用处,却极其投入。Beyond ability and determination there is a third ingredient: a disinterested obsession with something. Bus-ticket collectors are the model — they study something useless with enormous care.
- 这种痴迷本身就是能力的信号:愿意在一件没人奖励的事上花几年,说明你真的看得见它里面的结构。The obsession is itself a signal of ability. Spending years on something nobody rewards suggests you can actually see structure inside it.
- 达尔文、拉马努金、托尔金都沿着'看起来没前途'的路走,因为他们忍不住。新想法在定义上就是没前途的,否则早就有人做了。Darwin, Ramanujan and Tolkien all took paths that looked unpromising, because they could not help it. New ideas are unpromising by definition; otherwise someone would already have done them.
- 所以从众的路径选择会系统性错过它们:大家都去挤热门方向,冷门方向反而留出了空间。So herd-driven path selection misses them systematically. When everyone crowds the fashionable direction, the unfashionable one is left open.
- 判断痴迷是否值得的几个线索:它是否创造而非消费;是否对你特别难、又特别顺手;是否被有才华的人认真对待。最后,你可能需要允许自己浪费很多时间。He offers tests for whether an obsession matters: does it create rather than consume; is it hard for you yet strangely easy; do talented people take it seriously. And you may have to waste a lot of time.
- 热补丁为什么必须“原子”地生效Why a Hot Patch Has to Take Effect Atomically
- 场景:给正在运行的程序打热补丁,把一条旧指令换成新指令。直觉方案是挂起所有线程,改完再恢复。The setting: hot-patching a running process by replacing one instruction with another. The intuitive fix is to suspend every thread, patch, then resume.
- 问题在 x86 的指令是变长的。线程可能正好停在一条指令的中间;恢复后,它会把补丁的第二个字节当成一条新指令的开头执行。The problem is that x86 instructions have variable length. A thread can be frozen in the middle of an instruction; when it resumes, it treats the second byte of the patch as the start of a new instruction.
- 所以补丁有一条硬约束:新指令不能比旧指令短。否则原本合法的执行流会在替换后落到'半个指令'上。So the patch has a hard constraint: the new instruction cannot be shorter than the old one. Otherwise a legal execution path lands in the middle of the replacement.
- 那挂起所有线程不就够了吗?还不够。别的进程可以用 CreateRemoteThread 注入一个没有被挂起的线程,它会在你改到一半时开始执行。Does suspending all threads fix it? No. Another process can inject a fresh thread with CreateRemoteThread that was never suspended, and it starts executing while the patch is half applied.
- 原子激活的意义就在这里:让任何线程都不可能看到补丁的半成品。作者还补了一句:WriteProcessMemory 本身也不是原子的,但用它的热补丁本来就不被支持。That is what atomic activation buys: no thread can ever observe a half-written patch. He adds that WriteProcessMemory is not atomic either, but hot-patching through it was never supported anyway.
哲学与生活Philosophy & Life
- 天文学里的“干扰”,是另一个人的宝藏One Astronomer's Nuisance Is Another's Treasure
- 'Nuisance'(干扰)在天文学里是个半技术词:研究暗物质、宇宙微波背景或引力波时,要把尘埃、气体、普通物质的信号减掉。'Nuisance' is a semi-technical word in astronomy: when studying dark matter, the cosmic microwave background or gravitational waves, you subtract the signal of dust, gas and ordinary matter.
- 作者的翻转很简单:被减掉的东西本身可能就是研究对象。一个人的背景噪声,是另一个人的信号;学科的分工决定了谁有资格说什么是重要的。The reversal is simple. What gets subtracted may itself be the object worth studying. One person's background noise is another's signal, and the division of labor decides who gets to call something important.
- 而学科的排序很稳定:'基本'的问题排在' messy'的问题之上。于是大科学装置(SKA、JWST、Rubin、Roman、LISA)拿走经费、声望和下一代人。The hierarchy is remarkably stable: 'fundamental' questions sit above messy ones. Big instruments (SKA, JWST, Rubin, Roman, LISA) take the funding, the prestige and the next generation of researchers.
- 这种排序不是自然规律。它是冷战经费、物理学声望和历史偶然共同塑造的结果——大问题之所以看起来大,部分是因为有人替它买了单。That hierarchy is not natural law. It was shaped by Cold War funding, physics prestige and historical accident. Big questions look big partly because someone paid for them to look that way.
- 后果是小问题被系统性饿死,而意外发现往往就藏在那里。文章不是反对大科学,而是提醒:把'重要'当成既定事实,会让我们看不见自己正在丢掉什么。The cost is that small questions starve, and that is often where surprises live. The essay is not against big science; it warns that treating 'important' as settled hides what we are throwing away.
- 约束不是障碍,而是创意的入口Constraints Are Not Obstacles; They Are the Door to Ideas
- 1990 年代初,NBC 体育失去了 MLB 转播权,留下 32 周的空档和极小的预算。正常做法是去买新的版权,但他们买不起。In the early 1990s NBC Sports lost MLB rights, leaving a 32-week hole and a tiny budget. The normal move was to buy replacement rights; they could not afford it.
- 于是只能自己造节目:四分卫技巧赛、沙滩排球、单挑扑克。其中四分卫高尔夫后来长成美国世纪锦标赛,还复活了莱德杯、催生了全国狗展和 NHL 冬季经典赛。So they invented programming: a quarterback skills challenge, beach volleyball, heads-up poker. The QB golf event grew into the American Century tournament and helped revive the Ryder Cup, the National Dog Show and the NHL Winter Classic.
- 机制不是'逆境使人成长'这种鸡汤,而是约束关掉了复制别人的路,逼出所谓的资源性思维:在现有材料里找没人用过的组合。The mechanism is not 'adversity builds character'. Constraints close off copying, forcing resourceful thinking: new combinations of materials already at hand.
- 旁证很多:宋飞的极小布景逼出肢体喜剧;孩子在泳池里用一根面条发明新游戏;衰退期诞生了 Airbnb、Uber、Square。The corroborating cases are everywhere: Seinfeld's tiny set forced physical comedy; kids invent pool games with a noodle; recessions produced Airbnb, Uber and Square.
- 对个人的启示有点反直觉:没有资格玩别人的游戏,反而是一张许可证,让你去玩一个规则不同的游戏,而不是在别人的赛道上追赶。The personal lesson is counterintuitive: not being allowed to play someone else's game is a license to play a different one, instead of forever chasing on their track.
工具角Tools Corner
- LeafWiki:一个二进制文件的团队 wikiLeafWiki: A Team Wiki That Is One Binary
- 要解决的问题很具体:Wiki.js、Outline 这类 wiki 功能齐全,但为了写几页文档要同时运维 Node、Postgres、Redis 和一堆容器。The problem is concrete: full-featured wikis such as Wiki.js and Outline want Node, Postgres, Redis and a stack of containers just to hold a few pages.
- LeafWiki 把范围缩到最小:一个 Go 二进制,页面是磁盘上的 Markdown,元数据放 SQLite,没有外部依赖。LeafWiki shrinks the scope: one Go binary, pages as Markdown on disk, metadata in SQLite, no external services.
- 启动只需要一条 docker run,挂一个数据目录,给 JWT 密钥和管理员密码;也可以直接用二进制或安装脚本。Starting it is one docker run with a data directory, a JWT secret and an admin password; binaries and an install script are also provided.
- 它明确写了适用与不适用:适合工程团队和自托管者的长期结构化文档,不适合需要复杂权限、插件生态的组织。The README is explicit about fit: structured long-lived docs for engineering teams and self-hosters, not organizations needing complex permissions or a plugin ecosystem.
- 取舍很清楚:用功能换运维负担。如果你只是想要一个能搜索、能编辑、能备份的内网 wiki,这比搭一整套栈划算。The trade is clear: features for operational burden. If you want a searchable, editable, backup-friendly internal wiki, this is cheaper than standing up a whole stack.
- codemap:把整个 Go 仓库画成一张可点的地图codemap: A Whole Go Repository as One Clickable Map
- 读一个陌生 Go 仓库,最难的是先建立整体形状:有哪些包、谁依赖谁、每个包里有什么。The hard part of a new Go repository is the overall shape: which packages exist, who depends on whom, and what lives in each.
- codemap 用 go run 扫描模块,生成一个自包含的 HTML:每个包是一块,底下的行是它依赖的包,盒子大小对应函数数量。codemap runs from go run, scans the module and emits one self-contained HTML page: each package is a box, rows below it are its dependencies, box size tracks function count.
- 页面可以搜索,点一个包就能看它用谁、谁用它;对 GitHub 上的模块还能直接跳到函数所在行。The page is searchable; clicking a package shows what it uses and what uses it, and for GitHub modules you can jump to a function's line.
- 它只做静态结构,不做调用图,也不猜运行时行为——这既是限制,也是它能保持简单的原因。It maps static structure only, not call graphs or runtime behavior. That limits it, and it is also why it stays simple.
- 用法上最舒服的是放进 CI:每次构建产出一张地图,新人第一天就有全局视图,而不是从 README 开始猜。The best use is CI: produce a map on every build so a newcomer starts with the whole shape instead of guessing from the README.
- agent-deck:同时开十几个 AI 会话时的驾驶舱agent-deck: Mission Control for a Fleet of AI Sessions
- 当你在十个项目里同时跑 Claude Code、OpenCode、Codex,最大的开销不是模型,而是记不住哪个会话在等输入、哪个已经跑完。When you run Claude Code, OpenCode and Codex across ten projects, the real cost is not tokens but losing track of which session is waiting and which is done.
- agent-deck 把这些会话放进一个 TUI:一行一个会话,状态分为运行中、等待、完成,一个按键切换过去。agent-deck puts those sessions in one TUI: one row each, marked running, waiting or done, with one keystroke to switch.
- 它在此之上加了分组、搜索、fork、git worktree 和成本统计,还提供一个用手机控制的 conductor。On top of that it adds groups, search, forking, git worktrees, cost tracking and a phone-controlled conductor.
- 安装是 curl 脚本、Homebrew 或 go install 三选一,配置写在 config.toml 里,会话本身仍然跑在原来的终端里。Install via the curl script, Homebrew or go install; configuration lives in config.toml, and the sessions still run in their original terminals.
- 要注意它默认自动更新并重启 TUI;在脚本或 CI 里驱动它时,应该设 AGENTDECK_SKIP_UPDATE_CHECK=1。One caveat: it auto-updates and restarts the TUI by default. When scripting or running it in CI, set AGENTDECK_SKIP_UPDATE_CHECK=1.
- Gauge:用真实的 agent 来测试你的文档和 CLIGauge: Test Your Docs and CLI with Real Agents
- 问题换了个角度:文档写给人看,但现在第一个读者常常是编码 agent。人会自动补全的空白,agent 会直接卡住。The angle is different: docs are written for humans, but the first reader is often a coding agent. Gaps a person fills in silently are where an agent stops.
- Gauge 在你的项目里启动真实 agent,给它任务,记录它在哪里停下、误用了哪个废弃命令、忽略了哪个 Skill。Gauge launches a real agent inside your project, gives it a task, and records where it gets stuck, which deprecated command it reaches for, which Skill it ignores.
- 它把发现整理成可复现的会话,让你改文档、错误信息或帮助文本,再用同一个场景验证修复。Findings become reproducible sessions: you change the docs, the error message or the help text, then rerun the same scenario to check the fix.
- 安装是 npm 全局包,需要 Node 22 以上、Docker 和你要测试的 agent 的登录或 API key,全程本地跑,不强制注册账号。Install is a global npm package; it needs Node 22+, Docker, and credentials for the agent under test. Everything runs locally, with no account required.
- 它的价值不在'自动修好',而在把'agent 用不动这个工具'从模糊抱怨变成一条能重现的证据。Its value is not automatic repair. It turns 'the agent cannot use this tool' from a vague complaint into reproducible evidence.
- Sessions Chronicle:把本地 AI 会话变成可搜索的档案Sessions Chronicle: Make Local AI Sessions Searchable
- AI 会话散落在各个工具自己的目录里:Claude Code、OpenCode、Codex、Mistral Vibe、Kimi Code,各有各的格式。AI sessions are scattered across each tool's own directory: Claude Code, OpenCode, Codex, Mistral Vibe, Kimi Code, each with a different format.
- Sessions Chronicle 把它们索引进一个本地 SQLite 数据库,用 FTS5 做全文搜索,可以按项目、助手和时间过滤。Sessions Chronicle indexes them into a local SQLite database with FTS5 full-text search, filterable by project, assistant and date.
- 除了找对话,它还能展开工具调用、钻进子 agent、看每个会话的 token 分布,并直接从应用里恢复会话。Beyond finding a conversation, it expands tool calls, drills into subagents, shows per-session token breakdown and can resume a session from the app.
- 它是 Linux 上的 GTK/Libadwaita 应用,推荐用签名 Flatpak 安装,数据留在本机。It is a GTK/Libadwaita application for Linux, best installed from its signed Flatpak, with data staying on the machine.
- 局限也很明确:只支持它列出的五种助手,GNOME 生态之外要自己构建。适合'我记得上周问过,但找不到在哪'的人。The limits are explicit: five supported assistants, and non-GNOME systems must build it. It suits people who remember asking something last week but cannot find where.
- Termoso:自托管的 SSH/SFTP 工作台Termoso: A Self-Hosted SSH and SFTP Workbench
- Termius 这类工具好用,但账号、同步和团队功能都在别人的服务器上;对管多台机器的人来说,这是不必要的信任。Tools like Termius are convenient, but accounts, sync and team features live on someone else's server, which is unnecessary trust for anyone managing many machines.
- Termoso 用一套 Rust 核心加各平台原生客户端,覆盖 SSH、SFTP、WebDAV、Mosh、Telnet 和串口。Termoso pairs one Rust core with native clients and covers SSH, SFTP, WebDAV, Mosh, Telnet and serial.
- 同步服务器可以自己跑,也可以完全离线;README 明确写着没有遥测、没有分析、没有崩溃上报。Its sync server can be self-hosted or omitted entirely; the README states there is no telemetry, analytics or crash reporting.
- 代价是它年轻:客户端签名、iOS 分发、团队权限这些细节还不如商业产品成熟,选它意味着接受早期软件的不平整。The price is youth: client signing, iOS distribution and team permissions are less polished than commercial products, so choosing it means accepting early-software rough edges.
- 适合的场景很具体:你已经有 VPS 和自托管习惯,想把连接配置和团队共享握在自己手里。The fit is specific: you already run a VPS and self-host things, and you want connection profiles and team sharing under your own control.