prove
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese/prove - Machine-Verified Proofs (5-Phase Workflow)
/prove - 机器可验证证明(5阶段工作流)
For mathematicians who want verified proofs without learning Lean syntax.
面向无需学习Lean语法即可获取可验证证明的数学家。
Prerequisites
前置条件
Before using this skill, check Lean4 is installed:
bash
undefined使用本技能前,请检查Lean4是否已安装:
bash
undefinedCheck if lake is available
检查lake是否可用
command -v lake &>/dev/null && echo "Lean4 installed" || echo "Lean4 NOT installed"
**If not installed:**
```bashcommand -v lake &>/dev/null && echo "Lean4 installed" || echo "Lean4 NOT installed"
**若未安装:**
```bashInstall elan (Lean version manager)
安装elan(Lean版本管理器)
Restart shell, then verify
重启Shell后验证
lake --version
First run of `/prove` will download Mathlib (~2GB) via `lake build`.lake --version
首次运行`/prove`时,将通过`lake build`下载Mathlib(约2GB)。Usage
使用方法
/prove every group homomorphism preserves identity
/prove Monsky's theorem
/prove continuous functions on compact sets are uniformly continuous/prove every group homomorphism preserves identity
/prove Monsky's theorem
/prove continuous functions on compact sets are uniformly continuousThe 5-Phase Workflow
5阶段工作流
┌─────────────────────────────────────────────────────────────┐
│ 📚 RESEARCH → 🏗️ DESIGN → 🧪 TEST → ⚙️ IMPLEMENT → ✅ VERIFY │
└─────────────────────────────────────────────────────────────┘┌─────────────────────────────────────────────────────────────┐
│ 📚 研究 → 🏗️ 设计 → 🧪 测试 → ⚙️ 实现 → ✅ 验证 │
└─────────────────────────────────────────────────────────────┘Phase 1: RESEARCH (before any Lean)
阶段1:研究(在使用Lean之前)
Goal: Understand if/how this can be formalized.
-
Search Mathlib with Loogle (PRIMARY - type-aware search)bash
# Use loogle for type signature search - finds lemmas by shape loogle-search "pattern_here" # Examples: loogle-search "Nontrivial _ ↔ _" # Find Nontrivial lemmas loogle-search "(?a → ?b) → List ?a → List ?b" # Map-like functions loogle-search "IsCyclic, center" # Multiple conceptsQuery syntax:- = any single type
_ - ,
?a= type variables (same var = same type)?b - = must mention both
Foo, Bar
-
Search External - What's the known proof strategy?
- Use Nia MCP if available:
mcp__nia__search - Use Perplexity MCP if available:
mcp__perplexity__search - Fall back to WebSearch for papers/references
- Check: Is there an existing formalization elsewhere (Coq, Isabelle)?
- Use Nia MCP if available:
-
Identify Obstacles
- What lemmas are NOT in Mathlib?
- Does proof require axioms beyond ZFC? (Choice, LEM, etc.)
- Is the statement even true? (search for counterexamples)
-
Output: Brief summary of proof strategy and obstacles
CHECKPOINT: If obstacles found, use AskUserQuestion:
- "This requires [X]. Options: (a) restricted version, (b) accept axiom, (c) abort"
目标: 理解该定理是否可形式化、如何形式化。
-
使用Loogle搜索Mathlib(首选 - 类型感知搜索)bash
# 使用loogle进行类型签名搜索 - 根据形式查找引理 loogle-search "pattern_here" # 示例: loogle-search "Nontrivial _ ↔ _" # 查找Nontrivial相关引理 loogle-search "(?a → ?b) → List ?a → List ?b" # 类Map函数 loogle-search "IsCyclic, center" # 多概念组合搜索查询语法:- = 任意单一类型
_ - ,
?a= 类型变量(同一变量表示同一类型)?b - = 必须同时包含两个概念
Foo, Bar
-
外部搜索 - 已知的证明策略是什么?
- 若Nia MCP可用:使用
mcp__nia__search - 若Perplexity MCP可用:使用
mcp__perplexity__search - 退而求其次使用WebSearch查找论文/参考文献
- 检查:是否已有其他工具(Coq、Isabelle)的形式化实现?
- 若Nia MCP可用:使用
-
识别障碍
- Mathlib中缺少哪些引理?
- 证明是否需要ZFC之外的公理?(选择公理、排中律等)
- 该命题是否成立?(搜索反例)
-
输出: 证明策略和障碍的简要总结
检查点: 若发现障碍,将向用户提问:
- "此证明需要[X]。选项:(a) 限制命题范围,(b) 接受公理,(c) 终止任务"
Phase 2: DESIGN (skeleton with sorries)
阶段2:设计(带sorry的框架)
Goal: Build proof structure before filling details.
-
Create Lean file with:
- Imports
- Definitions needed
- Main theorem statement
- Helper lemmas as
sorry
-
Annotate each sorry:lean
-- SORRY: needs proof (straightforward) -- SORRY: needs proof (complex - ~50 lines) -- AXIOM CANDIDATE: v₂ constraint - will test in Phase 3 -
Verify skeleton compiles (with sorries)
Output: with annotated structure
proofs/<theorem_name>.lean目标: 在填充细节之前搭建证明框架。
-
创建Lean文件,包含:
- 导入语句
- 所需的定义
- 主定理命题
- 以暂代的辅助引理
sorry
-
为每个添加注释:
sorrylean-- SORRY: 需要证明(简单直接) -- SORRY: 需要证明(复杂 - 约50行) -- AXIOM CANDIDATE: v₂约束 - 将在阶段3测试 -
验证框架可编译(包含sorry)
输出: ,带有注释的框架文件
proofs/<theorem_name>.leanPhase 3: TEST (counterexample search)
阶段3:测试(反例搜索)
Goal: Catch false lemmas BEFORE trying to prove them.
For each AXIOM CANDIDATE sorry:
-
Generate test caseslean
-- Create #eval or example statements #eval testLemma (randomInput1) -- should return true #eval testLemma (randomInput2) -- should return true -
Run testsbash
lake env lean test_lemmas.lean -
If counterexample found:
- Report the counterexample
- Use AskUserQuestion: "Lemma is FALSE. Options: (a) restrict domain, (b) reformulate, (c) abort"
CHECKPOINT: Only proceed if all axiom candidates pass testing.
目标: 在尝试证明之前找出错误的引理。
针对每个标记为AXIOM CANDIDATE的sorry:
-
生成测试用例lean
-- 创建#eval或example语句 #eval testLemma (randomInput1) -- 应返回true #eval testLemma (randomInput2) -- 应返回true -
运行测试bash
lake env lean test_lemmas.lean -
若找到反例:
- 报告反例
- 向用户提问:"引理不成立。选项:(a) 限制定义域,(b) 重新表述命题,(c) 终止任务"
检查点: 仅当所有候选公理通过测试后才继续。
Phase 4: IMPLEMENT (fill sorries)
阶段4:实现(填充sorry)
Goal: Complete the proofs.
Standard iteration loop:
- Pick a sorry
- Write proof attempt
- Compiler-in-the-loop checks (hook fires automatically)
- If error, Godel-Prover suggests fixes
- Iterate until sorry is filled
- Repeat for all sorries
Tools active:
- compiler-in-the-loop hook (on every Write)
- Godel-Prover suggestions (on errors)
目标: 完成证明。
标准迭代循环:
- 选择一个sorry
- 编写证明尝试
- 编译器实时检查(自动触发钩子)
- 若出现错误,Godel-Prover会提供修复建议
- 迭代直到sorry被填充
- 重复上述步骤直到所有sorry被填充
激活的工具:
- 编译器实时钩子(每次写入时触发)
- Godel-Prover错误建议(出现错误时)
Phase 5: VERIFY (audit)
阶段5:验证(审计)
Goal: Confirm proof quality.
-
Axiom Auditbash
lake build && grep "depends on axioms" output- Standard: propext, Classical.choice, Quot.sound ✓
- Custom axioms: LIST EACH ONE
-
Sorry Countbash
grep -c "sorry" proofs/<file>.lean- Must be 0 for "complete" proof
-
Generate Summary
✓ MACHINE VERIFIED (or ⚠️ PARTIAL - N axioms) Theorem: <statement> Proof Strategy: <brief description> Proved: - <lemma 1> - <lemma 2> Axiomatized (if any): - <axiom>: <why it's needed> File: proofs/<name>.lean
目标: 确认证明质量。
-
公理审计bash
lake build && grep "depends on axioms" output- 标准公理:propext, Classical.choice, Quot.sound ✓
- 自定义公理:逐一列出
-
Sorry计数bash
grep -c "sorry" proofs/<file>.lean- 若要标记为“完整”证明,计数必须为0
-
生成总结
✓ MACHINE VERIFIED(或⚠️ PARTIAL - N个公理) 定理:<命题> 证明策略:<简要描述> 已证明: - <引理1> - <引理2> 公理化内容(若有): - <公理>:<使用原因> 文件:proofs/<name>.lean
Research Tool Priority
研究工具优先级
Use whatever's available, in order:
| Tool | Best For | Command |
|---|---|---|
| Loogle | Type signature search (PRIMARY) | |
| Nia MCP | Library documentation | |
| Perplexity MCP | Proof strategies, papers | |
| WebSearch | General references | WebSearch tool |
| WebFetch | Specific paper/page content | WebFetch tool |
Loogle setup: Requires with Mathlib index. Run for fast queries.
~/tools/loogleloogle-server &If no search tools available, proceed with caution and note "research phase skipped".
按以下优先级使用可用工具:
| 工具 | 适用场景 | 命令 |
|---|---|---|
| Loogle | 类型签名搜索(首选) | |
| Nia MCP | 库文档查询 | |
| Perplexity MCP | 证明策略、论文查找 | |
| WebSearch | 通用参考文献 | WebSearch工具 |
| WebFetch | 特定论文/页面内容 | WebFetch工具 |
Loogle设置: 需要在目录下有Mathlib索引。运行以实现快速查询。
~/tools/loogleloogle-server &若没有可用的搜索工具,请谨慎操作并标注“研究阶段已跳过”。
Checkpoints (automatic)
检查点(自动触发)
The workflow pauses for user input when:
- ⚠️ Research finds obstacles
- ❌ Testing finds counterexamples
- 🔄 Implementation hits unfillable sorry after N attempts
当出现以下情况时,工作流将暂停并等待用户输入:
- ⚠️ 研究阶段发现障碍
- ❌ 测试阶段找到反例
- 🔄 实现阶段经过N次尝试仍无法填充sorry
Output Format
输出格式
┌─────────────────────────────────────────────────────┐
│ ✓ MACHINE VERIFIED │
│ │
│ Theorem: ∀ φ : G →* H, φ(1_G) = 1_H │
│ │
│ Proof Strategy: Direct application of │
│ MonoidHom.map_one from Mathlib. │
│ │
│ Phases: │
│ 📚 Research: Found in Mathlib.Algebra.Group.Hom │
│ 🏗️ Design: Single lemma, no sorries needed │
│ 🧪 Test: N/A (trivial) │
│ ⚙️ Implement: 3 lines │
│ ✅ Verify: 0 custom axioms, 0 sorries │
│ │
│ File: proofs/group_hom_identity.lean │
└─────────────────────────────────────────────────────┘┌─────────────────────────────────────────────────────┐
│ ✓ MACHINE VERIFIED │
│ │
│ 定理:∀ φ : G →* H, φ(1_G) = 1_H │
│ │
│ 证明策略:直接应用Mathlib中的MonoidHom.map_one。 │
│ │
│ 阶段: │
│ 📚 研究:在Mathlib.Algebra.Group.Hom中找到相关内容 │
│ 🏗️ 设计:单引理,无需使用sorry │
│ 🧪 测试:不适用( trivial) │
│ ⚙️ 实现:3行代码 │
│ ✅ 验证:0个自定义公理,0个sorry │
│ │
│ 文件:proofs/group_hom_identity.lean │
└─────────────────────────────────────────────────────┘What I Can Prove
可证明的领域
| Domain | Examples |
|---|---|
| Category Theory | Functors, natural transformations, Yoneda |
| Abstract Algebra | Groups, rings, homomorphisms |
| Topology | Continuity, compactness, connectedness |
| Analysis | Limits, derivatives, integrals |
| Logic | Propositional, first-order |
| 领域 | 示例 |
|---|---|
| 范畴论 | 函子、自然变换、Yoneda引理 |
| 抽象代数 | 群、环、同态 |
| 拓扑学 | 连续性、紧性、连通性 |
| 分析学 | 极限、导数、积分 |
| 逻辑学 | 命题逻辑、一阶逻辑 |
Limitations
局限性
- Complex proofs may take multiple iterations
- Novel research-level proofs may exceed capabilities
- Some statements are unprovable over ℚ (need ℝ extension)
- 复杂证明可能需要多次迭代
- 前沿研究级别的证明可能超出能力范围
- 部分命题在ℚ上无法证明(需要扩展到ℝ)
Behind The Scenes
幕后技术
- Lean 4.26.0 - Theorem prover
- Mathlib - 100K+ formalized theorems
- Godel-Prover - AI tactic suggestions (via LMStudio)
- Compiler-in-the-loop - Automatic verification on every write
- Research tools - Nia, Perplexity, WebSearch (graceful degradation)
- Lean 4.26.0 - 定理证明器
- Mathlib - 包含10万+形式化定理的库
- Godel-Prover - AI策略建议工具(基于LMStudio)
- 编译器实时检查 - 每次写入时自动验证
- 研究工具 - Nia、Perplexity、WebSearch(支持优雅降级)
See Also
相关功能
- - Search Mathlib by type signature (used in Phase 1 RESEARCH)
/loogle-search - - For computation (integrals, equations)
/math-router - - Direct Lean syntax access
/lean4
- - 按类型签名搜索Mathlib(用于阶段1研究)
/loogle-search - - 用于计算(积分、方程求解)
/math-router - - 直接使用Lean语法
/lean4