Chuyển đến nội dung
Skillpedia
Lập trình chung8.0k · #12741

writing-lean-proofs

Skill này làm gì

Skill này hướng dẫn cách viết chứng minh hình thức bằng ngôn ngữ Lean 4 và tổ chức code Lean thành một thư viện. Skill dành cho nhà toán học và kỹ sư chính thức hóa định lý hoặc đặc tả.

Khi nào nên dùng

  • ✓Khi bạn đang chứng minh một định lý bằng Lean 4 và muốn có cấu trúc rõ ràng cho chứng minh.
  • ✓Khi một chứng minh tactic dài khó đọc và cần tách thành các bổ đề nhỏ hơn.
  • ✓Khi bạn đang review code Lean để cải thiện khả năng đọc hoặc chuẩn bị đưa vào Mathlib.

Liên kết skill

https://github.com/trailofbits/skills/blob/main/plugins/writing-lean-proofs/skills/writing-lean-proofs/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/trailofbits/skills/blob/main/plugins/writing-lean-proofs/skills/writing-lean-proofs/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Hãy giúp tôi chứng minh định lý này bằng Lean 4 và tách chứng minh dài thành các bổ đề nhỏ hơn.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Skill theo cách tiếp cận từ trên xuống. Bạn thiết kế các định nghĩa và phát biểu trước, rồi điền chứng minh từng bước, dùng chỗ giữ chỗ cho tới khi mỗi chứng minh hoàn tất.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Writing Lean Proofs

Contents

Structured Lean 4 proof writing and library design, distilled from Mathlib's style and review conventions and from the methodology of large formalization projects (Liquid Tensor Experiment, PFR, Fermat's Last Theorem).

Core principle: design top-down, prove bottom-up. Lean propositions are proof-irrelevant — only a theorem's statement can affect later declarations. Statements are the stable interface; proofs are disposable and freely replaceable. Put design effort into definitions and statements, then fill in proofs against skeletons that already compile (modulo sorry).

When to Use

  • Proving theorems in Lean 4, from single lemmas to multi-file developments
  • Formalizing mathematics, protocols, or software specifications in Lean
  • Defining new types, structures, or functions in a Lean library
  • Reviewing Lean code for readability, maintainability, or Mathlib readiness
  • Refactoring a long or fragile tactic proof into lemmas
  • Setting up a formalization project that several people or agents will contribute to in parallel
  • Setting up CI, linters, or verification gates for a Lean project — do this at project start, before patterns propagate
  • Diagnosing slow proofs, maxHeartbeats timeouts, or expensive reduction
  • Writing custom tactics, macros, or project-specific linters

When NOT to Use

  • Lean 4 as a general-purpose programming language (no proofs involved) — most of this skill targets proof and API structure
  • Coq, Isabelle, Agda, or Lean 3 — conventions and tactic names differ; Lean 3 idioms (ge_or_gt linting, discrete_field) are obsolete
  • Verified-software Lean projects with their own house style (e.g. spec-traceability-first codebases): Mathlib conventions are the community default, but check the project's CONTRIBUTING first and defer to it

The workflow

1. Design definitions and their API first

Definitions carry the design weight. Before proving anything about a new concept:

  • Prefer total functions with junk values over subtypes or Option in signatures (Mathlib: (0 : ℝ)⁻¹ = 0). Side conditions then appear only on the lemmas that need them, not at every use site.
  • Bundle: new morphism kinds are structures with a FunLike instance; new subobject kinds use SetLike; carry property proofs as structure fields, not separate IsHom-style predicates.
  • Pick the canonical spelling (simp-normal form) for every concept with multiple equivalent forms, and state all API lemmas for that form only.
  • Write the API in the same file, immediately: ext, @[simp], coercion, and injectivity lemmas — before the definition is used anywhere. Downstream proofs use the API, never unfold/show ... from rfl.

See library-design.md for the full set of design rules with rationale.

2. Build a sorry skeleton

State everything before proving anything, at every scale:

  • Project scale: state the target theorem and the lemmas it needs, all with := sorry, and make the file compile. Each sorry is now an independent work unit — a contributor (human or LLM) can discharge one without understanding the rest. This is how LTE, PFR, and FLT scale to dozens of parallel contributors.
  • Proof scale: inside a proof, lay out the have/suffices/calc skeleton with sorry justifications, get Lean to accept the structure, then fill each step. Keeping the structure intact is what produces useful error messages while you work.
example (a b c d : ℝ) (h : c = d * a + b) (h' : b = a * d) : c = 2 * a * d := by
  calc
    c = d * a + b     := sorry
    _ = d * a + a * d := sorry
    _ = 2 * a * d     := sorry

3. Fill goals, one focused goal at a time

  • Every new subgoal gets a focusing dot · with an indented block — never leave several goals active in unfocused sequence (Mathlib's multiGoal linter enforces this). This is what kills fragile goal-ordering dependence.
  • Open each block with a redundant show stating its goal. The proof works without it; reviewers and future editors need it. If show would change the goal, use change instead — keep stated goals honest.
  • Ch
Câu hỏi thường gặp

Ý tưởng cốt lõi là gì?

Thiết kế phát biểu trước, vì đó là phần ổn định. Chứng minh có thể thay sau mà không làm hỏng code khác.

Nó có bao gồm việc thiết lập dự án không?

Có. Skill nhắc đến CI, linter và thiết lập kiểm chứng cho các dự án có nhiều người hoặc agent cùng làm.

Nó có theo phong cách cụ thể nào không?

Nó theo phong cách và quy ước review của Mathlib, và tham khảo từ các dự án chính thức hóa lớn.

Chi tiết

Mô tả gốc của tác giả

Writes and reviews structured Lean 4 proofs and designs Lean libraries following Mathlib conventions. Use when proving theorems in Lean, formalizing mathematics or specifications in Lean 4, defining new types or definitions in a Lean library, reviewing Lean proofs for readability and maintainability, refactoring long tactic proofs into lemmas, filling in sorry placeholders in a Lean development, setting up CI or linters for a Lean project, diagnosing slow proofs or maxHeartbeats timeouts, or writing custom tactics, macros, or linters.

repo: trailofbits/skills

Độ phổ biến

Sao GitHub
8.0k
Vị trí xếp hạng
#12741
Giấy phép
CC-BY-SA-4.0
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự