axiom-verify
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAxiom Lean 4 Proof Verification
Axiom Lean 4 证明验证
Axiom provides cloud-based Lean 4 proof verification through the Axle API. It compiles and checks Lean code against a full Mathlib environment without requiring a local Lean installation -- verification results come back in seconds rather than the minutes it takes to build locally.
Axiom通过Axle API提供基于云的Lean 4证明验证服务。它可以在完整的Mathlib环境下编译并检查Lean代码,无需本地安装Lean——验证结果只需几秒即可返回,而本地构建通常需要数分钟。
Reference Files
参考文档
Read these as needed based on the task:
- references/axiom-configuration.md -- Setup, authentication, environment selection. Read this first if the user hasn't configured Axiom yet.
- references/axiom-api-reference.md -- All 14 API endpoints with parameters and response formats. Read when you need exact parameter names or response fields.
- references/axiom-cli-reference.md -- CLI commands and options. Read for exact flags and usage details when working with local files.
- references/axiom-best-practices.md -- Workflow guidance, scope limitations, and tips. Read when planning a multi-step workflow or hitting unexpected behavior.
可根据任务需求阅读以下文档:
- references/axiom-configuration.md —— 配置、身份验证、环境选择。如果用户尚未配置Axiom,请先阅读此文档。
- references/axiom-api-reference.md —— 包含14个API端点的所有参数和响应格式。当需要确切的参数名称或响应字段时阅读此文档。
- references/axiom-cli-reference.md —— CLI命令及选项。处理本地文件时,如需确切的标志和使用细节请阅读此文档。
- references/axiom-best-practices.md —— 工作流指导、范围限制及技巧。规划多步骤工作流或遇到异常行为时阅读此文档。
Workflow
工作流
Step 1: Select the Right Tool
步骤1:选择合适的工具
Match the user's intent to the appropriate endpoint:
| User wants to... | Endpoint | Notes |
|---|---|---|
| Verify a proof is correct | | Checks candidate proof against a formal statement |
| Check if code compiles | | Quick syntax and type checking |
| Understand proof structure | | Splits file into self-contained theorem units |
| Rename declarations | | Automatic reference updates throughout |
| Convert theorem/lemma | | Switch between |
| Stub out proofs | | Replace proofs with |
| Combine files | | Intelligent deduplication across files |
| Remove no-op tactics/haves | | Tactics that don't change proof state, unused haves |
| Remove post-completion tactics | | Tactics after proof is done, replace sorry, fix unsafe tactics |
| Extract have statements | | Promote inline |
| Stub have bodies | | Replace |
| Extract sorry placeholders | | Turn |
| Test if statement is false | | Attempts counterexample via Plausible |
| Standardize formatting | | Clean up sections, namespaces, comments |
When unsure which tool to use:
- Start with to see if the code compiles at all
check - Use to understand what's in the file
extract_theorems - Use first if the file uses
normalize/sectionblocks (these can cause issues with other tools)namespace
根据用户的需求匹配对应的端点:
| 用户想要... | 端点 | 说明 |
|---|---|---|
| 验证证明是否正确 | | 检查候选证明是否符合形式化陈述 |
| 检查代码是否可编译 | | 快速语法和类型检查 |
| 理解证明结构 | | 将文件拆分为独立的定理单元 |
| 重命名声明 | | 自动更新所有相关引用 |
| 转换定理/引理 | | 在 |
| 生成证明占位符 | | 用 |
| 合并文件 | | 智能去重跨文件内容 |
| 移除无操作策略/have语句 | | 移除不改变证明状态的策略、未使用的have语句 |
| 移除完成证明后的多余策略 | | 移除证明完成后的策略、替换sorry、修复不安全策略 |
| 提取have语句为引理 | | 将内联 |
| 生成have语句占位符 | | 用 |
| 将sorry占位符转换为引理 | | 将 |
| 测试陈述是否为假 | | 通过Plausible尝试寻找反例 |
| 标准化格式 | | 清理section、namespace、注释 |
当不确定使用哪个工具时:
- 先使用查看代码是否能编译
check - 使用了解文件内容结构
extract_theorems - 如果文件使用/
section块,先使用namespace(这些块可能会导致其他工具出现问题)normalize
Step 2: Execute
步骤2:执行操作
When working with local files, prefer the CLI -- it reads files directly from disk, has simpler syntax, and can write output to files with . The CLI reads from the environment automatically. Note: CLI commands use hyphens (e.g., ), while the HTTP API uses underscores (). All code is sent to for compilation against a full Mathlib environment -- the CLI is not local verification.
axle-oAXLE_API_KEYverify-proofverify_proofaxle.axiommath.aiWhen constructing Lean code dynamically (generating content in scripts, CI/CD pipelines, or building code strings programmatically), use the HTTP API via curl or the Python client (). The API accepts content as JSON strings, which is better suited for generated or in-memory code.
pip install axiom-axleCheck code compiles:
bash
axle check file.lean --environment lean-4.28.0 --ignore-importsVerify a proof:
bash
axle verify-proof formal_statement.lean proof.lean \
--environment lean-4.28.0 --ignore-importsRepair broken proofs:
bash
axle repair-proofs file.lean --environment lean-4.28.0 --ignore-imports \
--repairs remove_extraneous_tactics,apply_terminal_tacticsDisprove a conjecture:
bash
axle disprove file.lean --environment lean-4.28.0 --ignore-importsNormalize a file (flatten sections/namespaces):
bash
axle normalize file.lean -o normalized.lean --environment lean-4.28.0 --ignore-importsExtract theorems:
bash
axle extract-theorems file.lean --environment lean-4.28.0 --ignore-importsSimplify theorems:
bash
axle simplify-theorems file.lean --environment lean-4.28.0 --ignore-importsRename declarations:
bash
axle rename file.lean --declarations '{"old_name": "new_name"}' \
--environment lean-4.28.0 --ignore-importsStub proofs with sorry:
bash
axle theorem2sorry file.lean --environment lean-4.28.0 --ignore-importsWrite transformation output to a file (works with normalize, repair-proofs, simplify-theorems, rename, etc.):
bash
axle normalize file.lean -o output.lean -f --environment lean-4.28.0 --ignore-importsAPI example (for dynamically constructed code):
bash
curl -s -X POST https://axle.axiommath.ai/api/v1/check \
-H "Authorization: Bearer $AXLE_API_KEY" \
-H "Content-Type: application/json" \
-d "$(jq -n \
--arg content "$LEAN_CODE" \
'{content: $content, environment: "lean-4.28.0", ignore_imports: true}')" \
| jq '{okay, failed_declarations, lean_errors: .lean_messages.errors, tool_errors: .tool_messages.errors}'For the full CLI command reference, see references/axiom-cli-reference.md. For the full API parameter reference for all 14 endpoints, see references/axiom-api-reference.md.
处理本地文件时,优先使用 CLI——它可以直接从磁盘读取文件,语法更简单,还能通过将输出写入文件。CLI会自动从环境变量中读取。注意:CLI命令使用连字符(如),而HTTP API使用下划线()。所有代码都会发送到,在完整的Mathlib环境下编译——CLI并非本地验证工具。
axle-oAXLE_API_KEYverify-proofverify_proofaxle.axiommath.ai动态构建Lean代码时(如在脚本、CI/CD流水线中生成内容,或以编程方式构建代码字符串),请通过curl或Python客户端()使用HTTP API。API接受JSON格式的字符串内容,更适合生成的或内存中的代码。
pip install axiom-axle检查代码是否可编译:
bash
axle check file.lean --environment lean-4.28.0 --ignore-imports验证证明:
bash
axle verify-proof formal_statement.lean proof.lean \
--environment lean-4.28.0 --ignore-imports修复损坏的证明:
bash
axle repair-proofs file.lean --environment lean-4.28.0 --ignore-imports \
--repairs remove_extraneous_tactics,apply_terminal_tactics反证猜想:
bash
axle disprove file.lean --environment lean-4.28.0 --ignore-imports标准化文件格式(展开sections/namespaces):
bash
axle normalize file.lean -o normalized.lean --environment lean-4.28.0 --ignore-imports提取定理:
bash
axle extract-theorems file.lean --environment lean-4.28.0 --ignore-imports简化定理:
bash
axle simplify-theorems file.lean --environment lean-4.28.0 --ignore-imports重命名声明:
bash
axle rename file.lean --declarations '{"old_name": "new_name"}' \
--environment lean-4.28.0 --ignore-imports用sorry生成证明占位符:
bash
axle theorem2sorry file.lean --environment lean-4.28.0 --ignore-imports将转换结果写入文件(适用于normalize、repair-proofs、simplify-theorems、rename等工具):
bash
axle normalize file.lean -o output.lean -f --environment lean-4.28.0 --ignore-importsAPI示例(适用于动态构建的代码):
bash
curl -s -X POST https://axle.axiommath.ai/api/v1/check \
-H "Authorization: Bearer $AXLE_API_KEY" \
-H "Content-Type: application/json" \
-d "$(jq -n \
--arg content "$LEAN_CODE" \
'{content: $content, environment: "lean-4.28.0", ignore_imports: true}')" \
| jq '{okay, failed_declarations, lean_errors: .lean_messages.errors, tool_errors: .tool_messages.errors}'完整的CLI命令参考请查看references/axiom-cli-reference.md。所有14个端点的完整API参数参考请查看references/axiom-api-reference.md。
Step 3: Interpret Results
步骤3:解读结果
Every response includes two types of messages -- understanding both is key to helping the user:
- : Direct Lean compiler output. Errors here mean the Lean code itself has problems (type mismatches, tactic failures, unknown identifiers).
lean_messages - : Axle-specific diagnostics. Errors here mean the tool couldn't process the request (import mismatches, unsupported constructs, timeouts). The
tool_messagesfield often contains unsolved goals when a proof fails -- always check this for debugging context.tool_messages.infos
Severity levels:
- Errors: Result may be unusable
- Warnings: Suspicious but non-fatal
- Infos: Timing/debug output, unsolved goals
For : Returns (boolean) and (list). The flag reflects compilation success only -- if the code compiles without errors (warnings like don't affect it). is empty when is . The endpoint does not detect sorry usage or other verification-level issues -- it only checks that code compiles. Use to validate that proofs are complete.
checkokayfailed_declarationsokaytruesorryfailed_declarationsokaytruecheckverify_proofFor : Returns (boolean) and (list). The flag reflects proof validity -- only if the code compiles and passes all verification checks (no sorry, signatures match, no disallowed axioms). Note the distinction:
verify_proofokayfailed_declarationsokaytrue- Compilation errors (tactic failures, syntax errors, name collisions): is
okay,falseis empty. The errors appear infailed_declarations.lean_messages.errors - Verification failures (sorry usage, signature mismatch, disallowed axioms): is
okay, and the offending names appear infalsewith details infailed_declarations.tool_messages.errors - Fully valid proof: is
okayandtrueis empty. This is the only state that means the proof is both compilable and complete.failed_declarations
For transformation tools (, , , etc.): These do not return or . Check that is empty and inspect the field for the transformed result.
repair_proofssimplify_theoremsnormalizeokayfailed_declarationslean_messages.errorscontentFor : Check (list of refuted names) and (dict mapping each theorem name to a human-readable outcome string). If a counterexample is found, the name appears in and the entry contains the counterexample. If disprove fails (the theorem may be true), is empty and the entry describes why the negation could not be proven.
disprovedisproved_theoremsresultsdisproved_theoremsresultsdisproved_theoremsresultsImport handling: Always use (CLI) or (API) unless you have a specific reason not to (e.g., testing that exact imports are correct). Without this flag, import mismatches return a string instead of the standard response format, which breaks JSON parsing and hides the actual verification result. Code snippets, code from different Lean/Mathlib versions, and proof-logic checks all require this flag.
--ignore-imports"ignore_imports": trueuser_erroruser_error{"user_error": "...", "info": {...}}ignore_importsrenameuser_errorlean_messagestool_messages每个响应都包含两种类型的消息——理解这两种消息是帮助用户的关键:
- :Lean编译器的直接输出。此处的错误意味着Lean代码本身存在问题(类型不匹配、策略失败、未知标识符)。
lean_messages - :Axle特有的诊断信息。此处的错误意味着工具无法处理请求(导入不匹配、不支持的构造、超时)。当证明失败时,
tool_messages字段通常包含未解决的目标——调试时务必查看此字段。tool_messages.infos
严重级别:
- 错误:结果可能无法使用
- 警告:存在可疑但非致命的问题
- 信息:计时/调试输出、未解决的目标
对于: 返回(布尔值)和(列表)。标志仅反映编译是否成功——如果代码编译无错误则为(像这样的警告不影响该值)。当为时,为空。端点不会检测的使用或其他验证级别的问题——它仅检查代码是否可编译。请使用验证证明是否完整。
checkokayfailed_declarationsokaytruesorryokaytruefailed_declarationschecksorryverify_proof对于: 返回(布尔值)和(列表)。标志反映证明的有效性——只有当代码可编译并且通过所有验证检查(无sorry、签名匹配、无禁用公理)时才为。请注意以下区别:
verify_proofokayfailed_declarationsokaytrue- 编译错误(策略失败、语法错误、名称冲突):为
okay,false为空。错误信息出现在failed_declarations中。lean_messages.errors - 验证失败(使用sorry、签名不匹配、使用禁用公理):为
okay,有问题的名称会出现在false中,详细信息在failed_declarations中。tool_messages.errors - 完全有效的证明:为
okay且true为空。只有这种状态才表示证明既可以编译又完整。failed_declarations
对于转换工具(、、等):这些工具不会返回或。请检查是否为空,并查看字段获取转换后的结果。
repair_proofssimplify_theoremsnormalizeokayfailed_declarationslean_messages.errorscontent对于: 查看(已被反驳的名称列表)和(将每个定理名称映射为人类可读结果字符串的字典)。如果找到反例,该名称会出现在中,中的对应条目包含反例信息。如果反证失败(定理可能为真),为空,中的条目会说明为何无法证明该陈述的否定。
disprovedisproved_theoremsresultsdisproved_theoremsresultsdisproved_theoremsresults导入处理: 除非有特定原因(例如测试导入是否完全正确),否则请始终使用(CLI)或(API)。如果不使用此标志,导入不匹配会返回字符串而非标准响应格式,这会破坏JSON解析并隐藏实际的验证结果。代码片段、来自不同Lean/Mathlib版本的代码、证明逻辑检查都需要使用此标志。
--ignore-imports"ignore_imports": trueuser_erroruser_error{"user_error": "...", "info": {...}}ignore_importsrenamelean_messagestool_messagesuser_errorCommon Multi-Step Workflows
常见多步骤工作流
Verify and fix a proof:
- -- see if it compiles
check - If errors: -- attempt automatic fix
repair_proofs - again -- verify the repair worked
check - -- confirm it proves the intended statement
verify_proof
Analyze and clean a file:
- -- standardize formatting first (flatten sections/namespaces)
normalize - -- understand the structure
extract_theorems - with
repair_proofs-- remove tactics after proof is already completeremove_extraneous_tactics - -- remove unused haves and no-op tactics
simplify_theorems - -- verify nothing broke
check
Scaffold a proof development:
- Write formal statements
- -- stub out proofs with
theorem2sorry(usesorryparameter to target specific theorems)names - Fill in proofs incrementally
- after each proof to verify progress
check - -- track remaining obligations (generates
sorry2lemmalemma stubs inserted before each sorry'd theorem){name}.sorried - for final verification
verify_proof
Test a conjecture:
- -- look for counterexamples first
disprove - If no counterexample found, attempt the proof
- incrementally as you build the proof
check - when complete
verify_proof
验证并修复证明:
- —— 查看是否可编译
check - 如果有错误:—— 尝试自动修复
repair_proofs - 再次—— 验证修复是否有效
check - —— 确认证明符合预期陈述
verify_proof
分析并清理文件:
- —— 先标准化格式(展开sections/namespaces)
normalize - —— 理解文件结构
extract_theorems - 使用并设置
repair_proofs—— 移除证明完成后的多余策略remove_extraneous_tactics - —— 移除未使用的have语句和无操作策略
simplify_theorems - —— 验证未出现问题
check
搭建证明开发框架:
- 编写形式化陈述
- —— 用
theorem2sorry生成证明占位符(使用sorry参数指定目标定理)names - 逐步填充证明内容
- 每次填充后使用验证进度
check - —— 跟踪剩余任务(在每个带sorry的定理前生成
sorry2lemma引理占位符){name}.sorried - 最终使用验证
verify_proof
测试猜想:
- —— 先尝试寻找反例
disprove - 如果未找到反例,尝试编写证明
- 编写证明时逐步使用验证
check - 完成后使用验证
verify_proof
Common Pitfalls
常见陷阱
- Custom project attributes and constructs. Files from Lean projects often define custom attributes (e.g., ) and helper constructs (e.g.,
@[category research open, AMS 11]) via project-specific imports. Whenanswer(sorry)replaces those imports with standard Mathlib, these custom constructs become unresolvable and produce compilation errors. Before submitting, strip custom attributes and project-specific constructs using sed or similar:ignore_imports: trueremovessed 's/@\[category [^]]*\]//' file.leanblocks; replace@[category ...]withanswer(sorry)or remove it entirely. Note:Truetriggers a misleading "Candidate uses banned 'open private' command" tool error because the parser misinterprets the word@[category ... open ...]inside the attribute as theopencommand -- this is a false positive that disappears once the attribute is stripped.open private - is off in Mathlib environments. Always declare type variables explicitly (e.g.,
autoImplicitorvariable {α : Type*}). Implicit variables like(α : Type*)without declaringList αwill fail.α - Mathlib name shadowing. If your theorem names match existing Mathlib declarations (e.g., ,
add_zero,add_comm), you'll get "already declared" errors and all transformation tools will silently return unchanged content with zero stats. The error appears only inmul_comm, notlean_messages.errors-- you must inspecttool_messagesto notice the problem. Uselean_messagesto give theorems unique names, or prefix with a namespace.rename - cannot see through opaque definitions. The
omegatactic works on linear arithmetic overomegaandNat, but it treats user-defined functions as opaque. If you defineIntand try to provedef my_double (n : Nat) := n + nwithmy_double n = 2 * n, it will fail becauseomegadoesn't know whatomegacomputes. Usemy_double(orunfold my_double) beforesimp [my_double]to expose the definition.omega - vs
simplify_theoremsfor cleanup. These serve different purposes:repair_proofs- with
simplify_theorems: removes tactics that are no-ops (don't change the proof state at all)remove_unused_tactics - with
repair_proofs: removes tactics that appear after the proof is already completeremove_extraneous_tactics - For cleaning up redundant tactics, you usually want first, then
repair_proofs.simplify_theorems
- Sections and namespaces. ,
extract_theorems, and other transformation tools may produce non-compilable output when sections/namespaces are present because extracted names won't be fully qualified. Always runtheorem2sorryfirst to flatten these constructs. Note thatnormalizepreserves the original indentation from inside flattened blocks -- the output may look oddly indented but still compiles correctly. Caveat:normalizemay not update all references inside theorem bodies when flattening namespaces (e.g.,normalizemay not becomep k). AlwaysNamespace.p kthe normalized output and fix any unresolved references manually.check - requires fully-qualified names. The
renameparameter must use fully-qualified names including namespace prefixes. For example, ifdeclarationsis insidemy_thm, usenamespace Foo, not{"Foo.my_thm": "Foo.new_name"}. Using an unqualified name returns a{"my_thm": "new_name"}("Source name not found").user_error - Non-theorem commands in . The
extract_theoremstool warns about any non-theorem command it encounters withextract_theorems. This includes"Unsupported command kind ...",variable,open,notation, and other non-declaration commands. These warnings are informational -- the tool still correctly extracts all theorem declarations and includes dependencies (includingset_optionbindings,variablestatements, etc.) in each theorem's standaloneopenblock.content - Always check both message types. Transformation tools can "succeed" (return content with zero errors) while the underlying code has compilation errors visible only in
tool_messages. Always inspectlean_messages.errorseven whenlean_messages.errorsis clean. This silent failure mode applies broadly: any compilation error (custom attributes, missing imports, syntax issues, name shadowing) causes transformation tools to return unchanged content with zero stats. The only signal is non-emptytool_messages.lean_messages.errors - The environments endpoint uses (no
/v1/environmentsprefix), while all tool endpoints use/api/./api/v1/{tool_name}
- 自定义项目属性和构造。来自Lean项目的文件通常会通过项目特定的导入定义自定义属性(例如)和辅助构造(例如
@[category research open, AMS 11])。当answer(sorry)将这些导入替换为标准Mathlib时,这些自定义构造会无法解析并导致编译错误。提交前,请使用sed或类似工具移除自定义属性和项目特定构造:ignore_imports: true会移除sed 's/@\[category [^]]*\]//' file.lean块;将@[category ...]替换为answer(sorry)或直接移除。注意:True会触发误导性的“Candidate uses banned 'open private' command”工具错误,因为解析器会错误地将属性中的@[category ... open ...]视为open命令——移除该属性后此错误会消失。open private - Mathlib环境中处于关闭状态。请始终显式声明类型变量(例如
autoImplicit或variable {α : Type*})。像(α : Type*)这样未声明List α的隐式变量会导致失败。α - Mathlib名称冲突。如果你的定理名称与现有Mathlib声明冲突(例如、
add_zero、add_comm),会出现“already declared”错误,所有转换工具会静默返回未修改的内容且无统计信息。该错误仅出现在mul_comm中,不会出现在lean_messages.errors中——你必须查看tool_messages才能发现问题。请使用lean_messages为定理指定唯一名称,或添加命名空间前缀。rename - 无法穿透不透明定义。
omega策略适用于omega和Nat上的线性算术,但它会将用户定义的函数视为不透明的。如果你定义Int并尝试用def my_double (n : Nat) := n + n证明omega,会失败,因为my_double n = 2 * n不知道omega的计算逻辑。在使用my_double之前,请使用omega(或unfold my_double)来暴露该定义。simp [my_double] - 与
simplify_theorems的清理区别。它们的用途不同:repair_proofs- 搭配
simplify_theorems:移除无操作(完全不改变证明状态)的策略remove_unused_tactics - 搭配
repair_proofs:移除证明完成后的多余策略remove_extraneous_tactics - 清理冗余策略时,通常先使用,再使用
repair_proofssimplify_theorems
- Sections和Namespaces。、
extract_theorems等转换工具在处理sections/namespaces时可能会生成无法编译的输出,因为提取的名称不会被完全限定。请始终先运行theorem2sorry来展开这些构造。注意:normalize会保留展开块中的原始缩进——输出的缩进可能看起来奇怪,但仍然可以正确编译。注意事项:normalize在展开命名空间时可能不会更新定理体中的所有引用(例如normalize可能不会变为p k)。请始终Namespace.p k标准化后的输出,并手动修复任何无法解析的引用。check - 需要完全限定名称。
rename参数必须使用包含命名空间前缀的完全限定名称。例如,如果declarations在my_thm中,请使用namespace Foo,而非{"Foo.my_thm": "Foo.new_name"}。使用非限定名称会返回{"my_thm": "new_name"}(“Source name not found”)。user_error - 中的非定理命令。
extract_theorems工具会对遇到的任何非定理命令发出extract_theorems警告。这包括"Unsupported command kind ..."、variable、open、notation以及其他非声明命令。这些警告仅为信息性——工具仍会正确提取所有定理声明,并在每个定理的独立set_option块中包含依赖项(包括content绑定、variable语句等)。open - 始终检查两种类型的消息。转换工具可能会“成功”返回内容且无错误,但底层代码可能存在仅在
tool_messages中可见的编译错误。即使lean_messages.errors无错误,也请始终检查tool_messages。这种静默失败模式广泛存在:任何编译错误(自定义属性、缺少导入、语法问题、名称冲突)都会导致转换工具返回未修改的内容且无统计信息。唯一的信号是lean_messages.errors非空。lean_messages.errors - 环境端点使用(无
/v1/environments前缀),而所有工具端点使用/api/。/api/v1/{tool_name}