返回资讯中心
外部精选
软件工程
#开发者实时流

Elenxis 工具可将自然语言需求与 Lean 合约关联并审计证明

来源标题:Elenxis: The proof checks. Does the spec?

Elenxis 能把自然语言需求与 Lean 合约、反例和证明对应起来,用来发现缺失或弱于预期的规则,并审计证明实际确立了哪些内容。审计结论由 Lean 计算,配置的模型只提出需要阅读原文才能判断的缺口,再由人来裁定。其演示显示,一份把年龄限制写成 16 而非 18 的规格仍能通过证明编译。

Hacker News 最新kbr-2026/11/27 · 今天30 分钟阅读

以下正文由 AI 翻译自 Hacker News 最新(原文版权归原站所有),可能存在偏差,重要内容请以原文为准。

审查你的 Lean 规格逐条承诺了什么。Elenxis 把自然语言需求与 Lean 契约、反例和证明关联起来。用它找出缺失或弱于预期的规则,并审计这些证明究竟确立了什么。Lean 负责计算审计结论。一个已配置的模型会提出需要阅读原文才能判断的缺口,由人来裁决这些提案。

一个已证明的定理可能只覆盖了需求的一部分、依赖不可能成立的假设,或强制执行用户从未要求的规则。整条需求也可能在规格中完全缺失。即便证明能通过编译,这些缺口依然重要。

一分钟演示(合成示例) examples/age-limit 是一个合成演示,专为这份 README 设计。 需求 loans.md:

  1. 未满 18 岁的申请人应被拒绝贷款。 规格 Wrong.lean 把这个年龄界限形式化为 16,证明了它的定理,并给出了一个见证,说明其假设可以成立: def decide (age : Nat) : Decision := if age < 16 then .refused else .approved theorem refuses_minors (age : Nat) (h : age < 16) : decide age = .refused := by simp [decide, h] theorem minor_exists : ∃ age : Nat, ∃ _h : age < 16, True := ⟨15, by decide, trivial⟩ Lean 接受了它。lake env lean examples/age-limit/Wrong.lean 运行审计,不需要模型: proved: minors: A loan is refused to an applicant under 18. AgeLimit.refuses_minors : ∀ (age : Nat), age < 16 → AgeLimit.decide age = AgeLimit.Decision.refused axioms: [propext] checked inhabitation evidence: AgeLimit.minor_exists for AgeLimit.refuses_minors ∃ age _h, True axioms: [] 1 rows: 1 proved, 0 conditional, 0 unknown nonvacuity, 0 inconsistent premises, 0 not stated (1 judged) gaps 发现了不一致之处。配置好模型后, SPEC_TOOLS_BACKEND=$PWD/examples/backend.json lake env lean examples/age-limit/Wrong.lean 会额外输出: Requirements check: process adapter claude-code; model claude-opus-5-5; effort medium; destination note: Anthropic, through the Claude Code login too weak: minors: The statement only covers ages below 16 (age < 16). The clause requires refusal for every applicant under 18, so ages 16 and 17 are not covered. 1 gaps, 0 proposals refused 由人来决定。这个发现只是提案,不是结论:此处需求是对的,形式化是错的,因此 Fixed.lean 在判定逻辑及其定理中把界限设为 18。对它运行同样的命令会输出 0 gaps, 0 proposals refused。

纯 Lean 运行还会在两个版本中检查 16 岁的判定,并在修正后的版本中检查 18 岁的批准。

Lean 演示的命令 以上输出各自来自一次运行,模型为 Opus(claude-opus-5-5),中等推理强度,通过 Claude Code 调用(examples/backend.json)。模型的措辞每次运行都会变化,其发现也可能变化;审计输出的行则不会。

用提示词 Sorting spec in Lean 4 时,spec-tools ask 在其 lean 字段中生成了这条 Lean 后置条件。Lean 接受了该定义。 import Std /-- The output is nondecreasing and contains exactly the input elements, with multiplicity. -/ def SortPostcondition (input output : List Nat) : Prop := output.Pairwise (fun a b => a ≤ b) ∧ output.Perm input ask 的完整输出 usage: 1 calls; tokens input 17083, cache write 0, cache read 0, output 79; 5391 ms; codex gpt-6.2-sol {"lean":"import Std\n\n/-- The output is nondecreasing and contains exactly the input elements, with multiplicity. -/\ndef SortPostcondition (input output : List Nat) : Prop :=\n output.Pairwise (fun a b => a ≤ b) ∧ output.Perm input\n"}

对 draft-review 而言,需求是:排序必须把任意自然数列表排成非递减顺序,并保留每个元素的重数。下面两份草稿都被拒绝,退出状态为 1。

过弱。这份草稿只检查 output.Pairwise (· ≤ ·),忽略了输入。 uncovered: sorting: The draft supplies no external acceptance cases. For example, input [2, 1, 2] should accept [1, 2, 2] and reject [2, 1, 2], [1, 2], and [1, 2, 2, 3]. too weak: sorting: Statement 0 requires nondecreasing output but ignores the input. It accepts [] for input [2, 1, 2]. Require the output to be a permutation of the input so every element's multiplicity is preserved. 2 gaps, 0 proposals refused usage: 1 calls; tokens input 17280, cache write 0, cache read 0, output 177; 7811 ms; codex gpt-6.2-sol uncovered 这一行是另一条独立建议,即补充验收用例。

过强。这份草稿检查了顺序和置换,还额外加了 output.length ≤ 10。 extra: sorting: Statement 0 requires output.length ≤ 10. Since permutation preserves length, inputs with more than 10 elements admit no valid output, even though the requirement applies to every list of natural numbers. 1 gaps, 0 proposals refused usage: 1 calls; tokens input 16354, cache write 0, cache read 0, output 82; 5489 ms; codex gpt-6.2-sol

构建 Elenxis 后要重放这些调用,请在仓库根目录使用 sorting 的输入。诊断措辞可能因运行而异。 cli=.lake/build/bin/spec-tools example=examples/sorting "$cli" ask codex gpt-6.2-sol "$example/proposal.schema.json" "$example/prompt.txt" "$cli" draft-review codex gpt-6.2-sol "$example/prompt.txt" "$example/inventory.json" "$example/too-weak.json" "$cli" draft-review codex gpt-6.2-sol "$example/prompt.txt" "$example/inventory.json" "$example/too-strong.json"

运行 lake env lean examples/sorting/Countermodels.lean 可在不用模型的情况下检查这两处区分。第一个证明表明,仅要求有序的谓词会接受输入 [2, 1, 2] 对应空输出。第二个证明表明,长度上限会拒绝一个含十一个元素的有序置换。该命令会对照示例评分键中的预期方向验证这两个具名定理。同一条命令还会在由二元输入和长度至多为 1 的输出构成的较小范围内搜索。报告会说明搜索在何处未找到区分,并将该范围之外的结果标记为 unknown。

(原文较长,此处译出前 6000 字,完整内容请点「打开原文」。)

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →