English | 简体中文
先确认 Lean 里的定理就是公告的定理,再把时间花在读证明上。
一个面向数学评审者的命令行审计器:读取 Lean 声明与构建产物,比较规范化的陈述类型和局部定义闭包,把无法机器判定的部分明确标成残余。
一个 Lean 文件能通过 CI,只说明某个声明在允许的公理集内通过了类型检查;它不说明这个声明就是公告里那条定理。换一个同名但更弱的 def,#check 和 #print axioms 都会放行,构建也照样是绿的。Proofclaim 补的正是这一步:把「是不是同一条定理」拆成可复现的检查,让评审者先确认有值得读的数学。
当一条著名猜想带着 Lean 仓库一起发布时,评审者通常只有两种读法:读散文,或者读 Lean。两种读法都看不见「外层类型相同、定义被悄悄换弱」这种失败——它不会让构建变红,也不会引入新的公理。
Proofclaim 把审计单位定义成陈述规范形 + 它的局部定义闭包:
- 陈述:两边各自的
Expr用同一套序列化规则输出——de Bruijn 索引、显式 universe、丢弃 binder 名、把项目内常量重命名为LOCAL:<basename>,再逐字节比较。 - 定义闭包:从定理类型可达的本地常量,每个
def/opaque把规范类型和定义体一起做 sha256;证明项不参与哈希。 - 公理与 sorry:只在 target 侧收集公理(参考仓库可能合法地依赖
sorry),再对 target 声明的源码区间做一次词法\bsorry\b扫描。 - 散文残余:
claims.yaml是评审者自己写的清单,只做精确名字匹配;不读论文、不推断蕴含,映射不上的行如实计数。
这不是语义等价判定:规范形是语法层的,没有 whnf、zeta 或 delta 归约;拼写不同但定义相等的陈述会被报成 differs。报告里的 limits 每次都会写明这一点。它也不生成、修复或搜索证明,不修改被审计仓库(--build 是唯一会写 .lake/ 的模式)。
如果你熟悉 agent 工具链,可以把它看作其中专门做「声明一致性审计」的一类 Agent:同一谱系里的 HKUDS 项目做的是让模型行动,Proofclaim 做的是让评审者先核对声明——输入是散文清单、Lean 声明和构建产物,输出是一个可复核的判定。
单进程,无服务端、无模型、运行时无网络:
cli.py ─► config.py (proofclaim.yaml, config@1)
─► lean_project.py (发现 lean-toolchain/lakefile,检查 olean,运行 lake env lean)
─► probe.py (渲染 Lean 探针,读取 PRFCLAIM|<len>|<payload> 帧)
─► statement.py (陈述规范形比较,预算内闭包,sha256)
─► claims.py (清单行对闭包分类)
─► report.py (终端表格、Markdown、report@1 JSON)
探针写到被审计仓库的 _proofclaim/Probe.lean,让 import 能解析;运行完即删除,除非 --keep-probe。探针与 Python 之间只有一种通道:PRFCLAIM|BEGIN|1、逐条长度前缀帧、PRFCLAIM|END|1。载荷始终是本项目自己的规范序列化结果,而不是 Lean 的 pretty-printer 文本,所以定义体里的 | 或换行不会破坏通道。
源码入口:cli.py · config.py · lean_project.py · probe.py · statement.py · claims.py · report.py · 探针模板 · report@1 schema
需要 Python 3.12+、elan 安装的 Lean 4 与 lake,以及 macOS 或 Linux。v0.1 不支持 Windows。
git clone https://github.com/SuperMarioYL/proofclaim.git
cd proofclaim
uv venv
source .venv/bin/activate
uv pip install -e .
proofclaim --version本节之后的所有 proofclaim 命令都假定这个虚拟环境已激活;换到新的 shell 时,回到仓库根目录重新执行 source .venv/bin/activate 即可。
也可以不建虚拟环境,直接跑一次:
uvx --from . proofclaim --version审计开始前先确认工具链可见:
proofclaim doctor它会打印 lean --version 和 lake --version;任一缺失就以退出码 3 拒绝运行。
仓库自带一对合成 fixture,用来把「外层类型相同、定义不同」这个核心场景完整跑通。输入已经包含在仓库里,不需要准备额外文件:
# 1. 构建 target 与 reference(一次即可)
cd tests/fixtures/target
lake build
cd ../reference
lake build
# 2. 发现项目并写入 proofclaim.yaml
cd ../target
proofclaim init
# 3. 审计公告的定理
proofclaim audit \
--theorem Mini.claimed \
--reference-repo ../reference \
--reference-decl Ref.reference预期输出(exit 1;前两行里的绝对路径取决于你的 checkout 位置):
target: /path/to/proofclaim/tests/fixtures/target (module Mini, toolchain leanprover/lean4:v4.10.0)
reference: /path/to/proofclaim/tests/fixtures/reference (decl Ref.reference, module Ref, toolchain leanprover/lean4:v4.10.0)
theorem: Mini.claimed
statement: identical
target (const "LOCAL:RiemannHypothesis" [])
reference (const "LOCAL:RiemannHypothesis" [])
definitions: mismatch (0/1 match)
LOCAL:RiemannHypothesis mismatch
target sha256:341a6f8c255790bb6499126fc6a3f0f948ccaadf3aed9bcbbc76012c9965f003 Mini.RiemannHypothesis
reference sha256:3d122f057d3b452486ebb90baba33a7ec0b6f9176aeab9db32aa7a5735ceaf9c Ref.RiemannHypothesis
axioms: allowlisted (none)
sorry: absent
build: not-run
claims: 2/4 covered (partial 0, missing 1, unmapped 1)
verdict: definitions-differ (exit 1)
limits: 7 item(s); see --out or --json
target 的 RiemannHypothesis 是 ∀ n : Nat, n + 0 = n,reference 的是 ∀ n m : Nat, n + m = m + n。外层类型一模一样,所以 statement: identical;定义体不同,所以闭包哈希不匹配。换成 Mini.control 与 Ref.control 这对完全相同的声明,verdict 是 declaration-verified,exit 0。
审计你自己的仓库:
cd /path/to/announced-repo
proofclaim doctor
proofclaim init --scan # 列出候选定理及文件行号
# 在 proofclaim.yaml 里填 reference.repo / reference.decl,或用下面的命令行参数
lake exe cache get # 仅当依赖 mathlib
lake build # 一次真实构建,让探针读到本次源码的 olean
proofclaim audit --reference-repo ../formal-conjectures --reference-decl Some.decl一次只审计一条定理;批量审计请在 CI 里循环。
| 命令 | 作用 |
|---|---|
proofclaim doctor |
打印 lean/lake 版本;缺失时退出 3。 |
proofclaim init [--theorem NAME] [--scan] [--force] |
发现 Lean 项目,写入 proofclaim.yaml(proofclaim/config@1)。--scan 列出候选定理。 |
proofclaim inspect --theorem NAME [--keep-probe] |
只跑 target 侧:打印规范类型、定义闭包、公理与 sorry 状态。 |
proofclaim audit [--theorem NAME] [--reference-repo DIR] [--reference-decl NAME] [--json] [--out FILE] [--build] |
与独立参考声明比较;终端表格、JSON 或 Markdown。 |
proofclaim --version |
打印已安装版本。 |
命令行参数覆盖 proofclaim.yaml 里的同名配置。audit 在没有配置文件时也能用:它按 init 的默认值补全,并在 limits 里说明这次回退。
退出码:
| 码 | 含义 |
|---|---|
0 |
declaration-verified 或 fully-verified。 |
1 |
statement-differs 或 definitions-differ。 |
2 |
用法错误:没有项目、没有定理、没有参考、配置不可读。 |
3 |
unauditable:某项检查不可验证或前置条件失败,reason 指明是哪一项。 |
audit --json 输出一份 proofclaim/report@1 文档;--out report.md 写一份带表格与并排定义体的复核笔记。JSON 的每个字段、每个 verdict 与 reason 取值见 docs/report-schema.md。
下面的 GIF 由 assets/demo.tape 用 vhs 录制,命令与输出是 2026-11-22 在 macOS + Lean 4.10.0 上的一次真实运行,完整记录(含 report@1 JSON)见 docs/demo-results.json。
复现:
git clone https://github.com/SuperMarioYL/proofclaim.git
cd proofclaim
uv venv
source .venv/bin/activate
uv pip install -e .
cd tests/fixtures/target && lake build
cd ../reference && lake build
cd ../target && proofclaim init
proofclaim audit --theorem Mini.claimed --reference-repo ../reference --reference-decl Ref.reference| 检查 | 能看见 | 看不见 |
|---|---|---|
statement |
规范化的外层陈述类型是否逐字节相同 | 定义相等但写法不同的陈述(语法层比较);不同工具链之间的比较直接报 unverifiable。 |
definitions |
从陈述类型可达的每个 LOCAL: 常量的类型/定义体哈希 |
超出 max_local_constants(默认 200)的常量只记入 limits;证明项不参与哈希。 |
axioms |
target 声明的公理依赖,以及白名单外的名字;sorryAx 永不放行 |
参考侧的公理(参考可能合法地依赖 sorry)。 |
sorry |
target 声明源码区间内的词法 \bsorry\b |
整个模块或传递依赖里的 sorry(导入的 sorry 由公理检查以 sorryAx 捕捉)。 |
build |
--build 时真实 lake build 的退出码和日志尾部 |
没有 --build 时完全不运行构建。 |
claims |
评审者清单中的标识符是否精确出现在定理名或闭包里 | 散文是否真的被形式化覆盖;missing/unmapped 是有标注的残余,不是推断。 |
因此,declaration-verified 的含义是:声明层面与参考一致,且公理、sorry 检查都完成并通过;它不表示数学命题为真,也不表示证明正确。想要更强的 fully-verified,还需要一次绿色构建,并且清单里没有 missing/unmapped 行。
proofclaim init 写出的 proofclaim.yaml(proofclaim/config@1)就是全部可编辑状态:
schema: "proofclaim/config@1"
toolchain: "leanprover/lean4:v4.10.0" # 从 lean-toolchain 复制
module: "Mini"
theorem: null # --theorem 覆盖;为 null 且不传参数是用法错误
local_prefixes: ["Mini"] # 参与 LOCAL: 重命名的前缀
max_local_constants: 200 # 闭包预算
axiom_allowlist: ["propext", "Classical.choice", "Quot.sound"]
claims: "claims.yaml" # 相对本文件
reference:
repo: null # --reference-repo 覆盖
decl: null # --reference-decl 覆盖claims.yaml(proofclaim/claims@1)由评审者维护,Proofclaim 不生成也不改写它:
schema: proofclaim/claims@1
rows:
- id: announced-theorem
claim: "仓库声明的定理是 Mini.claimed。"
identifiers: [Mini.claimed]
- id: hypothesis-definition
claim: "假设使用仓库自己的 RiemannHypothesis 定义。"
identifiers: [Mini.RiemannHypothesis]
- id: analytic-continuation
claim: "形式化覆盖解析延拓。"
identifiers: [RiemannZeta]
- id: informal-remark
claim: "公告称论证遵循 1859 年的原始论文。"
identifiers: []最后一行没有标识符,会记为 unmapped;第三行的 RiemannZeta 不在闭包里,会记为 missing。它们都留在残余里,不参与覆盖率猜测。
audit --json 的标准输出是一份可直接进 CI 的文档:
{
"schema": "proofclaim/report@1",
"verdict": "definitions-differ",
"reason": null,
"checks": {
"statement": {"state": "identical", "target": "(const \"LOCAL:RiemannHypothesis\" [])", "reference": "(const \"LOCAL:RiemannHypothesis\" [])"},
"definitions": {"state": "mismatch", "entries": [
{"name": "LOCAL:RiemannHypothesis", "state": "mismatch", "target_sha256": "341a6f8c…", "reference_sha256": "3d122f05…"}
]},
"axioms": {"scope": "target", "state": "checked", "list": [], "allowlisted": true, "violations": []},
"sorry": {"scope": "target", "state": "absent", "hits": []},
"build": {"state": "not-run", "exit_code": null, "log_tail": null},
"claims": {"checked": true, "covered": 2, "partial": 0, "missing": 1, "unmapped": 1, "total": 4, "coverage": "2/4"}
},
"limits": ["..."]
}axioms.state、sorry.state 与 claims.checked 都是三态设计:没有跑探针时是 not-checked/false,计数为 null,绝不会把「没检查」读成「干净」。完整字段、全部 verdict/reason 取值和 JSON Schema 的约束见 docs/report-schema.md。
v0.1 已实现上面描述的全部命令与检查:doctor、init、inspect、audit、config@1、claims@1、report@1、JSON Schema 校验、终端/Markdown/JSON 三种输出,以及覆盖退出码映射的测试。
尚未实现、也不在 v0.1 承诺内:
- 重命名与 notation 的和解——不同名字的参考常量目前只是一个人工复核的差异。
- 一次调用审计多条定理——请在 CI 里循环。
- 跨 Lean 工具链或跨 mathlib revision 的比较——目前统一报
unverifiable。 - Windows 支持、预编译二进制、Docker 镜像。
- 任何 LLM 读取论文、判断蕴含或总结散文的路径——
claims.yaml始终是评审者写的清单。
Proofclaim 以 MIT 许可证发布,永久免费、开源,CLI 之外没有托管服务、账号或计费。
MIT © 2026 SuperMarioYL
