人物发言

Lauren Tan

我对形式化方法挺看好,但觉得该降温预期、自己去研究(声明:我不是这方面专家)。它没法保证程式没 Bug,只能保证在某些假设下符合规格;而规格来自人想要什么,不是数学。只要我们为人做软体,没有东西能证明你的规格是对的,只能你自己判断。

我在 pstack 做/statechart 技能,主要是让程式里隐含的状态机更清楚可读,缩小审查面,从更高层问:这真的符合意图吗?做游戏时大量使用,下图是剧情模式状态图,靠它找出很多 Bug。

模型检查(如 TLA+/TLC)适合端到端理解与检查系统性质;规格不是真码,有漂移风险,所以她会再叠实证验证。定理证明与有界模型检查各有取舍。近中期仍要分层:约束与护栏、实证验证、真正需要的形式化验证。

背景:附图状态机标出 11 处真实问题(载入冻结、自动选牌、暂停盖住对白等);技能清单截图含外部网域,网站未采用该图。

原文

while i'm quite bullish on formal methods, i think it's worth tempering expectations and doing your own research on it (disclaimer: i am not an expert in it). it cannot guarantee your code is bug free, only that it matches the spec under certain assumptions, and the specs come from what people want, not math. as long as we build software for humans, nothing can prove that your spec is right, only you can judge.

i created the /statechart skill in pstack primarily because it helps make the state machines implicit in your code more obvious and legible to you, so you can shrink the review surface and review the work at a higher level: does it actually match your intent and goal? i used this skill a ton while building my game, below you can see the statechart for story mode where i was able to find many bugs with it.

in that sense, i think model checking (eg TLA+ with TLC) is quite useful for understanding and checking properties of your system e2e, and you don't have to write tons of new verification code for it. the spec isn't your actual code so there's always a risk of drift, but so far i've had good experiences finding actual bugs with it. i tend to pair it with empirical verification (running the code) also to confirm it's real

other types of formal verification like proving theorems (eg Lean, Dafny), bounded model checking (eg CBMC, Kani) etc have their own tradeoffs. proofs cover every possible input, but only for the properties specified, and it takes a lot more code/work. bounded model checking can run on your actual code, which avoids drift, but it only checks up to a certain number of steps, so it's better at finding bugs than proving there aren't any

so i think in the near-medium term you'll still need to layer your codebase: constraints and guardrails (types, lint rules, api design, refactoring), empirical verification (tests, evals, real usage), and formal verification for the parts that really need it. none of these catch everything on their own, but layered together, they catch a lot more and shrink what's left for you to review

but also maybe in the limit, the bitter lesson will prevail and flawless code will just be printed out perfectly every time with no bugs. even in that scenario, /statechart still seems very helpful in confirming that the agent understood your intent correctly. give it a try if you haven't already!

深色状态图「AT THE CASE END」:多条角色分支,红点标出 11 处 Bug 说明。
Lauren 原帖附图:剧情模式状态机与 11 项真实 Bug。Lauren Tan 原帖附圖(已清理網域浮水)

重点总结

她看好形式化方法,但提醒只能保证在假设下符合规格;用 statechart 技能在游戏剧情模式标出 11 处真实 Bug。